syntax fix + assembly calculate a^b

This commit is contained in:
Sam Hadow 2024-03-28 12:55:16 +01:00
parent 2440c7af7b
commit ee34fc8d14
4 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,13 @@
LDFLAGS="-L/usr/local/opt/flex/lib"
machine.py: ram
a_pow_b: ram
./ram < a_pow_b.1
echo "### machine.py ###"
cat machine.py
echo "### execution ###"
python machine.py
test: ram
./ram < test.1
echo "### machine.py ###"
cat machine.py

11
src/a_pow_b.1 Normal file
View File

@ -0,0 +1,11 @@
(2,4,5)
ADD(i1,0,r0)
ADD(i1,0,r1)
ADD(i1,0,r2)
ADD(1,0,r3)
JE(i2,r3,4)
MULT(r2,r0,r2)
ADD(1,r3,r3)
JUMP(-3)
ADD(0,1,o0)
ADD(r2,0,o1)

View File

@ -11,7 +11,7 @@
%%
[rio][0-9]* { yylval = strdup(yytext); return REGISTER;}
[rio]@[rio][0-9]* { yylval = strdup(yytext); return REGISTER_REF;}
[0-9]* { yylval = strdup(yytext); return VALUE;}
[\-0-9]* { yylval = strdup(yytext); return VALUE;}
ADD|SUB|MULT|DIV { yylval = strdup(yytext); return OP;}
JUMP|JE|JL { yylval = strdup(yytext); return OP_CTRL;}
[ ]*,[ ]* {return COMMA;}

View File

@ -84,9 +84,9 @@ args:
;
args_ctrl:
VALUE COMMA arg COMMA arg {
arg COMMA arg COMMA VALUE {
char* tmp = "";
asprintf(&tmp, "%c, %s, %s", $1, $3, $5);
asprintf(&tmp, "%s, %s, %s", $5, $1, $3);
$$ = tmp;
}
| VALUE {