Go to the first, previous, next, last section, table of contents.


assembleBeq

Function: assembleBeq { label asm -> }
file: job.t
package: muf
status: alpha

The assembleBeq prim is one of four functions provided in support of basic control structures such as if-then-else and loop{...}.

The assembleBeq deposits a conditional branch to the given label.

At runtime, the deposited branch will pop one value from the data stack: If that value is nil, the next instruction executed with be that located at label, otherwise execution continues normally with the next instruction.

For example, : ab if "a" else "b" fi ; can be compiled so:

stack:
makeAssembler --> *asm*
stack:
*asm* reset
stack:
*asm* assembleLabelGet --> *elseLabel* ( Allocate first label )
stack:
*asm* assembleLabelGet --> *endLabel*  ( Allocate second label )
stack:
*elseLabel* *asm* assembleBeq ( Deposit conditional jump )
stack:
"a" *asm* assembleConstant ( Deposit 'then' clause body )
stack:
*endLabel* *asm* assembleBra ( Deposit unconditional jump to end )
stack:
*elseLabel* *asm* assembleLabel ( Deposit 'else' label )
stack:
"b" *asm* assembleConstant ( Deposit 'else' clause body )
stack:
*endLabel* *asm* assembleLabel ( Deposit 'end' label )
stack:
nil -1 makeFunction *asm* finishAssembly --> #'ab ( Compile fn 'ab' )
stack:
t ab ( Test fn 'ab' on true value )
stack: "a"
pop nil ab ( Test fn 'ab' on false value )
stack: "b"

See section assembleBne. See section assembleLabel. See section assembleLabelGet.


Go to the first, previous, next, last section, table of contents.