sy2002 / QNICE-FPGA

QNICE-FPGA is a 16-bit computer system for recreational programming built as a fully-fledged System-on-a-Chip in portable VHDL.
http://qnice-fpga.com
Other
69 stars 15 forks source link

VBCC: Check edge case around abra @R13++,!v #186

Open sy2002 opened 3 years ago

sy2002 commented 3 years ago

This issue steps from this comment: https://github.com/sy2002/QNICE-FPGA/issues/179#issuecomment-719987345

Given a C program like this:

int a;

void f()
{  
   if (a < 2)
   {
      a=2;
   }
}

int main()
{  
   a = 1;
   f();
}  

The generated assembly for the function f() is:

.....
_f:
   move  #_a,R11
   cmp   2,@R11
   abra  @R13++,!v
   move  #_a,R12
   move  2,@R12
l4:
   move  @R13++,R15
.....

What if we force the compiler to use register bank switching instead of the stack?

Would the compiler still generate abra @R13++,!v to return?

For the return itself, on the first glance this seems correct. BUT:

As described in https://github.com/sy2002/QNICE-FPGA/issues/179#issuecomment-719987345, this would be wrong, because in case of register banking, the "return statement" aka abra @R13++,!v would need to do a DECRB first.