

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























Construct code for expressions, assignments, if, and while. ¾ Concatenate statements in stmt-list ¾ Allocate temporaries as needed ¾ Keep track of variables, constants, and temporaries in Symbol Table ¾ Use symbolic instructions and fill in absolute addresses (linking)when complete code has been constructed
LDA X; Load the AC with the contents of memory address X
X; Load the AC indirectly with the contents of address X STA X; Store the contents of the AC at memory address X
X; Store the contents of the AC indirectly at address X ADD X; Add the contents of address X to the contents of the AC SUB X; Subtract the contents of address X from the AC MUL X; Multiply the contents of address X to the contents of the AC JMP X; Jump to the instruction labeled X JMZ X; Jump to the instruction labeled X if the AC contains 0 JMN X; Jump to the instruction labeled X if the contents of the AC isnegative
; Halt execution
8
1
2
1
1
2
2
1
1
2
2
3
1
2
n
LD ZERO ST T1 LD FIVE ST T2 LD T1 SUB T2 ST T3 LD T3 ST n LD n ST T4 LD T4 JMN L1 JMZ L1 LD n ST T5 LD T5 ST i JMP L L3: LD i ST T10 JMN L4 JMZ L4 LD fact ST T11 LD i ST T12 LD T11 MUL T12 ST T13 LD T13 ST fact LD i ST T14 LD ONE ST T15 LD T14 SUB T15 ST T16 LD T16 ST i JMP L L4: HLT L1: LD ZERO ST T6 LD n ST T7 LD T6 SUB T7 ST T8 LD T8 ST i L2: LD ONE ST T9 LD T9 ST fact