Skip to content

Instantly share code, notes, and snippets.

@pcyu16
Created June 26, 2010 02:14
Show Gist options
  • Select an option

  • Save pcyu16/453696 to your computer and use it in GitHub Desktop.

Select an option

Save pcyu16/453696 to your computer and use it in GitHub Desktop.
* Standard prelude:
0: LD 5,0(0) load maxaddress form dmem[0]
1: ST 0,0(0) clear dmem[0]
* End of standard prelude
2: LDA 3,0,5 reserved places for global variables
3: LDA 0,4(7) eax = return addr of main
4: LDC 2,1(2) pushl: push return addr of main
5: SUB 3,3,2 pushl
6: ST 0,0(3) pushl
7: LDA 7,143(7) jump to main
8: HALT 0,0,0
* function start
9: LDC 2,1(2) backup ebp: push ebp
10: SUB 3,3,2 backup ebp
11: ST 4,0(3) backup ebp
12: LDC 2,0(2) new base: set new ebp
13: ADD 4,3,2 new base
14: LDA 3,-1,3 reserved places for local variables
15: LD 0,2(4) load id value
16: LDA 1,2(4) get address save to edx (local)
17: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
18: SUB 3,3,2 pushl
19: ST 0,0(3) pushl
20: LD 0,3(4) load id value
21: LDA 1,3(4) get address save to edx (local)
22: LD 1,0(3) popl: reg[addr] = mem[esp++]
23: LDC 2,1(2) popl
24: ADD 3,3,2 popl
25: SUB 0,1,0 relop: boolean expression
26: JLT 0,2(7) relop: brunch if true
27: LDC 0,0(0) relop: false case: eax = 0
28: LDA 7,1(7) relop: unconditional jump
29: LDC 0,1(0) relop: true case: eax = 1
30: JEQ 0,33(7) sele_stmt: jump to the end of sele_stmt
31: LD 0,-1(4) load id value
32: LDA 1,-1(4) get address save to edx (local)
33: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
34: SUB 3,3,2 pushl
35: ST 1,0(3) pushl
36: LD 0,2(4) load id value
37: LDA 1,2(4) get address save to edx (local)
38: LD 1,0(3) popl: reg[addr] = mem[esp++]
39: LDC 2,1(2) popl
40: ADD 3,3,2 popl
41: ST 0,0(1) assign value
42: LD 0,2(4) load id value
43: LDA 1,2(4) get address save to edx (local)
44: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
45: SUB 3,3,2 pushl
46: ST 1,0(3) pushl
47: LD 0,3(4) load id value
48: LDA 1,3(4) get address save to edx (local)
49: LD 1,0(3) popl: reg[addr] = mem[esp++]
50: LDC 2,1(2) popl
51: ADD 3,3,2 popl
52: ST 0,0(1) assign value
53: LD 0,3(4) load id value
54: LDA 1,3(4) get address save to edx (local)
55: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
56: SUB 3,3,2 pushl
57: ST 1,0(3) pushl
58: LD 0,-1(4) load id value
59: LDA 1,-1(4) get address save to edx (local)
60: LD 1,0(3) popl: reg[addr] = mem[esp++]
61: LDC 2,1(2) popl
62: ADD 3,3,2 popl
63: ST 0,0(1) assign value
64: LD 0,3(4) load id value
65: LDA 1,3(4) get address save to edx (local)
66: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
67: SUB 3,3,2 pushl
68: ST 0,0(3) pushl
69: LDC 0,0(0) load const
70: LD 1,0(3) popl: reg[addr] = mem[esp++]
71: LDC 2,1(2) popl
72: ADD 3,3,2 popl
73: SUB 0,1,0 relop: boolean expression
74: JEQ 0,2(7) relop: brunch if true
75: LDC 0,0(0) relop: false case: eax = 0
76: LDA 7,1(7) relop: unconditional jump
77: LDC 0,1(0) relop: true case: eax = 1
78: JEQ 0,12(7) sele_stmt: jump to end of sele_stmt
79: LD 0,2(4) load id value
80: LDA 1,2(4) get address save to edx (local)
81: LDA 3,2,3 release places for local variables
82: LDC 2,0(2) erase local: restore esp
83: ADD 3,4,2 erase local
84: LD 4,0(3) restore ebp: pop ebp
85: LDC 2,1(2) restore ebp
86: ADD 3,3,2 restore ebp
87: LDC 2,1(2) ret: backup esp and load return address
88: ADD 3,3,2 ret
89: LD 7,-1(3) ret
90: LDA 7,51(7) sele_stmt: jump to end of sele_stmt
91: LDC 2,-2(2) addc: mem[addr] += cnt
92: ADD 3,3,2 addc
93: LD 0,3(4) load id value
94: LDA 1,3(4) get address save to edx (local)
95: ST 0,0(3) stroe argument
96: LD 0,2(4) load id value
97: LDA 1,2(4) get address save to edx (local)
98: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
99: SUB 3,3,2 pushl
100: ST 0,0(3) pushl
101: LD 0,3(4) load id value
102: LDA 1,3(4) get address save to edx (local)
103: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
104: SUB 3,3,2 pushl
105: ST 0,0(3) pushl
106: LD 0,2(4) load id value
107: LDA 1,2(4) get address save to edx (local)
108: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
109: SUB 3,3,2 pushl
110: ST 0,0(3) pushl
111: LD 0,3(4) load id value
112: LDA 1,3(4) get address save to edx (local)
113: LD 1,0(3) popl: reg[addr] = mem[esp++]
114: LDC 2,1(2) popl
115: ADD 3,3,2 popl
116: DIV 0,1,0 mulop
117: LD 1,0(3) popl: reg[addr] = mem[esp++]
118: LDC 2,1(2) popl
119: ADD 3,3,2 popl
120: MUL 0,1,0 mulop
121: LD 1,0(3) popl: reg[addr] = mem[esp++]
122: LDC 2,1(2) popl
123: ADD 3,3,2 popl
124: SUB 0,1,0 addop
125: ST 0,1(3) store argument
126: LDA 0,4(7) pushl: push return address
127: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
128: SUB 3,3,2 pushl
129: ST 0,0(3) pushl
130: LDA 7,-122(7) jump to function
131: LDC 2,2(2) addc: mem[addr] += cnt
132: ADD 3,3,2 addc
133: LDA 3,2,3 release places for local variables
134: LDC 2,0(2) erase local: restore esp
135: ADD 3,4,2 erase local
136: LD 4,0(3) restore ebp: pop ebp
137: LDC 2,1(2) restore ebp
138: ADD 3,3,2 restore ebp
139: LDC 2,1(2) ret: backup esp and load return address
140: ADD 3,3,2 ret
141: LD 7,-1(3) ret
142: LDA 3,1,3 release places for local variables
143: LDC 2,0(2) erase local: restore esp
144: ADD 3,4,2 erase local
145: LD 4,0(3) restore ebp: pop ebp
146: LDC 2,1(2) restore ebp
147: ADD 3,3,2 restore ebp
148: LDC 2,1(2) ret: backup esp and load return address
149: ADD 3,3,2 ret
150: LD 7,-1(3) ret
* function end
* function start
151: LDC 2,1(2) backup ebp: push ebp
152: SUB 3,3,2 backup ebp
153: ST 4,0(3) backup ebp
154: LDC 2,0(2) new base: set new ebp
155: ADD 4,3,2 new base
156: LDA 3,-2,3 reserved places for local variables
157: LD 0,-1(4) load id value
158: LDA 1,-1(4) get address save to edx (local)
159: IN 0,0,0 read interger value
160: ST 0,0(1) assign value
161: LD 0,-2(4) load id value
162: LDA 1,-2(4) get address save to edx (local)
163: IN 0,0,0 read interger value
164: ST 0,0(1) assign value
165: LDC 2,-2(2) addc: mem[addr] += cnt
166: ADD 3,3,2 addc
167: LD 0,-1(4) load id value
168: LDA 1,-1(4) get address save to edx (local)
169: ST 0,0(3) stroe argument
170: LD 0,-2(4) load id value
171: LDA 1,-2(4) get address save to edx (local)
172: ST 0,1(3) store argument
173: LDA 0,4(7) pushl: push return address
174: LDC 2,1(2) pushl: mem[--esp] = reg[addr]
175: SUB 3,3,2 pushl
176: ST 0,0(3) pushl
177: LDA 7,-169(7) jump to function
178: LDC 2,2(2) addc: mem[addr] += cnt
179: ADD 3,3,2 addc
180: OUT 0,0,0 write value in eax
181: LDA 3,2,3 release places for local variables
182: LDC 2,0(2) erase local: restore esp
183: ADD 3,4,2 erase local
184: LD 4,0(3) restore ebp: pop ebp
185: LDC 2,1(2) restore ebp
186: ADD 3,3,2 restore ebp
187: LDC 2,1(2) ret: backup esp and load return address
188: ADD 3,3,2 ret
189: LD 7,-1(3) ret
* function end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment