Programming Constructs

Below are common assembly equivalents of constructs.

Conditional Evaluation

; X=4, Y=5
; if (X-Y == 0)
;  X+Y
; stop
 
If,    Load X
       Subt Y
	   Skipcond 400
	   Jump EndIf
Then,  Load X
       Add Y
EndIf, Halt
X,     DEC 4
Y,     DEC 5

If, then, else

; X=4, Y=5
; if (X-Y == 0) {
;  X+Y
; } else {
;  X+X
; }
; stop
 
If,    Load X
       Subt Y
	   Skipcond 400
	   Jump Else
Then,  Load X
       Add Y
	   Jump EndIf
Else,  Load X
       Add X
EndIf, Halt
X,     DEC 4
Y,     DEC 5

Definite iteration

; for (i=0; i<10; i++) {
;  output i
; }
; stop
 
         Clear
		 Store Counter
Loop,    Load Counter
		 Subt Limit
		 Skipcond 000
		 Jump Next
		 Output
		 Load Counter
		 Add One
		 Store Counter
		 Jump Loop
Next,    Halt
Counter, DEC 0
Limit,   DEC 10
One,     DEC 1

Indefinite iteration

; while (x<0) {
;  output x
; }
; stop
 
Test, Load X
      Skipcond 000
	  Jump Next
	  Output
	  Jump Test
Next, Halt

Procedure invocation

; f() {
;  input
; }
;
; f();
; output
; f();
; output
; stop
 
      JnS Proc
	  Output
	  JnS Proc
	  Output
	  Halt
Proc, HEX 0
      Input
	  JumpI Proc