Mercurial > hg > index.cgi
comparison lwcc/cc-gencode.c @ 501:f3e9732973f1
Add basic integer operations to lwcc
Add +, -, *, and / to lwcc parser and code generator. Multiplication and
division require helper functions in a yet to be created support library.
These operations are integer only for the moment.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 24 Sep 2019 22:07:56 -0600 |
parents | c3099c5d9d3e |
children | 14a40f8bb4eb |
comparison
equal
deleted
inserted
replaced
500:733fd05ca2a8 | 501:f3e9732973f1 |
---|---|
41 | 41 |
42 case NODE_CONST_INT: | 42 case NODE_CONST_INT: |
43 fprintf(output, "\tldd #%s\n", n->strval); | 43 fprintf(output, "\tldd #%s\n", n->strval); |
44 break; | 44 break; |
45 | 45 |
46 case NODE_OPER_PLUS: | |
47 generate_code(n->children, output); | |
48 fprintf(output, "\tpshs d\n"); | |
49 generate_code(n->children->next_child, output); | |
50 fprintf(output, "\taddd ,s++\n"); | |
51 break; | |
52 | |
53 case NODE_OPER_MINUS: | |
54 generate_code(n->children, output); | |
55 fprintf(output, "\tpshs d,x\n"); | |
56 generate_code(n->children->next_child, output); | |
57 fprintf(output, "\tstd 2,s\n\tpuls d\n\tsubd ,s++\n"); | |
58 break; | |
59 | |
60 case NODE_OPER_TIMES: | |
61 generate_code(n -> children, output); | |
62 fprintf(output, "\tpshs d\n"); | |
63 generate_code(n->children->next_child, output); | |
64 fprintf(output, "\tjsr ___mul16i\n"); | |
65 break; | |
66 | |
67 case NODE_OPER_DIVIDE: | |
68 generate_code(n -> children, output); | |
69 fprintf(output, "\tpshs d\n"); | |
70 generate_code(n->children->next_child, output); | |
71 fprintf(output, "\tjsr ___div16i\n"); | |
72 break; | |
73 | |
46 default: | 74 default: |
47 for (nn = n -> children; nn; nn = nn -> next_child) | 75 for (nn = n -> children; nn; nn = nn -> next_child) |
48 generate_code(nn, output); | 76 generate_code(nn, output); |
49 break; | 77 break; |
50 } | 78 } |