Wzorce generowania kodu

Każdy komentarz w poniższej tabeli oznacza, że w tym miejscu należy wstawić zawartość odpowiedniego parametru szablonu.

Wstawianie zawartości szablonu wygląda tak: <tt>, gdzie tt jest nazwą parametru.

Nazwa Architektura rejestrowa Architektura stosowa
  • Odejmowanie
/*put the code leaving result of the right argument in the A register*/
PUSH A
/*put the code leaving result of the left argument in the A register*/
POP B
SUB A,B
/*put the code leaving result of the left argument on the stack*/
/*put the code leaving result of the right argument on the stack*/
SUB
  • Read number
MOV A,#<number>
PUSH	#<number>
  • Declare variable
  DD <ID> 
  DD <ID>
  • Read variable
  MOV A,[<ID>]
  PUSH [<ID>]
  • Write variable
  MOV [<ID>],A 
  POP [<ID>]
  • if

The label must be unique for each if in the code!

/*put the code leaving results of the boolean expression in A and flags*/
 JE label_else_xx 
/*put the then code*/
 JMP label_endif_xx label_else_xx: 
/*put the else code*/ 
label_endif_xx:
  
/*put the code leaving results of the boolean expression on the stack*/
 PUSH #label_else_xx
 JE 
/*put the then code*/
 PUSH #label_endif_xx
 JMP label_else_xx: 
/*put the else code*/ 
label_endif_xx: 

to be continued…