windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
337 stars 36 forks source link

ppci-cc: x86 backend stops when generating a char switch with a negative value #73

Closed tstreiff closed 4 years ago

tstreiff commented 4 years ago

char sym; switch (sym).. case -1: ...

File "/home/tsf/sandbox/local/lib/python3.6/site-packages/ppci/arch/token.py", line 27, in u8 return struct.pack("<B", x) struct.error: ubyte format requires 0 <= number <= 255

This generates an instruction "mov bl,-1" and the assembler does not accept negative value for immediate8. Note: the problem does not occur if "sym" is of type "int" (or "short")

I have got a fix (in arch/token.py°). I'll make a pull request this week.

windelbouwman commented 4 years ago

Thanks for fixing this!