Showing
6 changed files
with
37 additions
and
26 deletions
... | @@ -256,11 +256,11 @@ class CodeGenVisitor (Visitor) : | ... | @@ -256,11 +256,11 @@ class CodeGenVisitor (Visitor) : |
256 | node.body.accept(self) | 256 | node.body.accept(self) |
257 | function_str = self.curr_str | 257 | function_str = self.curr_str |
258 | self.curr_str = old_str | 258 | self.curr_str = old_str |
259 | - frame_size = self.stack.get_max_fp() | 259 | + frame_size = abs(self.stack.get_max_fp()) |
260 | - if frame_size > 0: | 260 | + if frame_size != 0: |
261 | self.o(" set R9 %X" % frame_size, | 261 | self.o(" set R9 %X" % frame_size, |
262 | "Allocate %s words for local+temp vars" % frame_size) | 262 | "Allocate %s words for local+temp vars" % frame_size) |
263 | - self.o(" sub R9 SP SP", "... shift SP") | 263 | + self.o(" sub SP R9 SP", "... shift SP") |
264 | self.stack.save_callee_saves() | 264 | self.stack.save_callee_saves() |
265 | self.curr_str.write(function_str.getvalue()) | 265 | self.curr_str.write(function_str.getvalue()) |
266 | self._loc(node, "(exit function)") | 266 | self._loc(node, "(exit function)") |
... | @@ -538,11 +538,13 @@ class CodeGenVisitor (Visitor) : | ... | @@ -538,11 +538,13 @@ class CodeGenVisitor (Visitor) : |
538 | elif node.op == "<" : | 538 | elif node.op == "<" : |
539 | self.o(" gt %s %s %s" % (right_reg, left_reg, reg), "Perform '<'") | 539 | self.o(" gt %s %s %s" % (right_reg, left_reg, reg), "Perform '<'") |
540 | elif node.op == ">=" : | 540 | elif node.op == ">=" : |
541 | - self.o(" gt %s %s %s" % (right_reg, left_reg, reg), "Perform '>='") | 541 | + self.o(" inc %s" % left_reg, "Perform 'a >= b'") |
542 | - self.o(" not %s %s" % (reg, reg), "... throught 'not <'") | 542 | + self.o(" gt %s %s %s" % (left_reg, right_reg, reg), |
543 | + "... that is 'a+1 > b'") | ||
543 | elif node.op == "<=" : | 544 | elif node.op == "<=" : |
544 | - self.o(" gt %s %s %s" % (left_reg, right_reg, reg), "Perform '<='") | 545 | + self.o(" inc %s" % right_reg, "Perform 'a <= b'") |
545 | - self.o(" not %s %s" % (reg, reg), "... throught 'not >'") | 546 | + self.o(" gt %s %s %s" % (right_reg, left_reg, reg), |
547 | + "... that is 'b+1 > a'") | ||
546 | else : | 548 | else : |
547 | raise Exception("unsupported comparison %r" % node.op) | 549 | raise Exception("unsupported comparison %r" % node.op) |
548 | 550 | ||
... | @@ -550,10 +552,12 @@ class CodeGenVisitor (Visitor) : | ... | @@ -550,10 +552,12 @@ class CodeGenVisitor (Visitor) : |
550 | self._loc(node) | 552 | self._loc(node) |
551 | if node.op in cparse.Binop.ASSIGN_OPS: | 553 | if node.op in cparse.Binop.ASSIGN_OPS: |
552 | self._binop_assign(node) | 554 | self._binop_assign(node) |
553 | - elif node.op in ['+','-','*']: | 555 | + elif node.op in ['+','-','*','/','%']: |
554 | self._binop_arith(node) | 556 | self._binop_arith(node) |
555 | elif node.op in ['==', '!=', '<', '>', '<=', '>=']: | 557 | elif node.op in ['==', '!=', '<', '>', '<=', '>=']: |
556 | self._binop_compare(node) | 558 | self._binop_compare(node) |
559 | + else : | ||
560 | + raise Exception("unsupported operation %r" % node.op) | ||
557 | 561 | ||
558 | def vNegative(self, node): | 562 | def vNegative(self, node): |
559 | self._loc(node) | 563 | self._loc(node) | ... | ... |
libc/Makefile
0 → 100644
libc/stdio-c.asm
0 → 100644
This diff is collapsed. Click to expand it.
libc/stdio.asm
0 → 100644
This diff is collapsed. Click to expand it.
... | @@ -84,8 +84,6 @@ int putu(int u, char f) { | ... | @@ -84,8 +84,6 @@ int putu(int u, char f) { |
84 | 84 | ||
85 | int puti(int i) { | 85 | int puti(int i) { |
86 | int n; | 86 | int n; |
87 | - int s; | ||
88 | - int r; | ||
89 | n = 0; | 87 | n = 0; |
90 | if (UINT(i) > 32767) { | 88 | if (UINT(i) > 32767) { |
91 | n += putc(MINUS); | 89 | n += putc(MINUS); |
... | @@ -137,16 +135,16 @@ int printf(char *str, ...) { | ... | @@ -137,16 +135,16 @@ int printf(char *str, ...) { |
137 | return n; | 135 | return n; |
138 | } | 136 | } |
139 | 137 | ||
140 | -int main() { | 138 | +/* int main() { */ |
141 | - puts("hello world\n"); | 139 | +/* puts("hello world\n"); */ |
142 | - puti(42); | 140 | +/* putu(42, XCHAR); */ |
143 | - puts(" => 42\n"); | 141 | +/* puts(" => 2A\n"); */ |
144 | - puti(-42); | 142 | +/* putu(42, UCHAR); */ |
145 | - puts(" => -42\n"); | 143 | +/* puts(" => 42\n"); */ |
146 | - putu(42, XCHAR); | 144 | +/* puti(42); */ |
147 | - puts(" => 2A\n"); | 145 | +/* puts(" => 42\n"); */ |
148 | - putu(42, UCHAR); | 146 | +/* puti(-42); */ |
149 | - puts(" => 42\n"); | 147 | +/* puts(" => -42\n"); */ |
150 | - printf("hello %s I'm %u (%x)\n", "stdio", 42, 42); | 148 | +/* printf("hello %s I'm %u (%x)\n", "stdio", 42, 42); */ |
151 | - return 0; | 149 | +/* return 0; */ |
152 | -} | 150 | +/* } */ | ... | ... |
1 | +# | ||
2 | +# extern int putc(char c) | ||
3 | +# | ||
4 | + | ||
1 | putc: | 5 | putc: |
2 | - set R8 3 # Point R8 towards argument c | 6 | + set R8 2 # Point R8 towards argument c |
3 | - add R8 SP R8 # ... located as SP+3 | 7 | + add R8 SP R8 # ... located as SP+2 |
4 | ld R8 R8 # Load argument c | 8 | ld R8 R8 # Load argument c |
5 | set R9 1012 # Put command for screen | 9 | set R9 1012 # Put command for screen |
6 | - bus R9 R8 R8 # Write char to screen | 10 | + bus R9 R0 R8 # Write char to screen |
7 | set R0 1 # Set return value | 11 | set R0 1 # Set return value |
8 | ret | 12 | ret |
13 | + | ... | ... |
-
Please register or login to post a comment