From c2b396b85357adfd511798ae71d58b0de92adfaf Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 13 Sep 2020 00:04:38 +0100 Subject: [PATCH] Fix bug in loading values into variables --- src/Assembler.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Assembler.c b/src/Assembler.c index 9ccbeb5..c66940f 100644 --- a/src/Assembler.c +++ b/src/Assembler.c @@ -348,11 +348,11 @@ int AsLdVar(int ID) { switch(Symbols[ID].Type) { case RET_CHAR: // movzbq zeroes, then moves a byte into the quad register - fprintf(OutputFile, "\tmovzbq\t%s(\%%rip), %s\n", Symbols[ID].Name, Registers[Reg]); + fprintf(OutputFile, "\tmovb\t%s(\%%rip), %s\n", Symbols[ID].Name, ByteRegisters[Reg]); break; case RET_INT: - fprintf(OutputFile, "\tmovzbl\t%s(\%%rip), %s\n", Symbols[ID].Name, Registers[Reg]); + fprintf(OutputFile, "\tmovl\t%s(\%%rip), %s\n", Symbols[ID].Name, DoubleRegisters[Reg]); break; case RET_LONG: @@ -367,29 +367,27 @@ int AsLdVar(int ID) { } int AsStrVar(int Register, int ID) { - int Reg = RetrieveRegister(); - printf("\tStoring contents of %s into %s\n", Registers[Register], Symbols[ID].Name); switch(Symbols[ID].Type) { case RET_CHAR: // movzbq zeroes, then moves a byte into the quad register - fprintf(OutputFile, "\tmovb\t%s, %s(\%%rip)\n", ByteRegisters[Reg], Symbols[ID].Name); + fprintf(OutputFile, "\tmovb\t%s, %s(\%%rip)\n", ByteRegisters[Register], Symbols[ID].Name); break; case RET_INT: - fprintf(OutputFile, "\tmovl\t%s, %s(\%%rip)\n", DoubleRegisters[Reg], Symbols[ID].Name); + fprintf(OutputFile, "\tmovl\t%s, %s(\%%rip)\n", DoubleRegisters[Register], Symbols[ID].Name); break; case RET_LONG: - fprintf(OutputFile, "\tmovq\t%s, %s(%%rip)\n", Registers[Reg], Symbols[ID].Name); + fprintf(OutputFile, "\tmovq\t%s, %s(%%rip)\n", Registers[Register], Symbols[ID].Name); break; default: DieMessage("Bad type for saving", Types[Symbols[ID].Type]); } - return Reg; + return Register; } void AsNewSymb(int ID) {