Kingcom / armips

An assembler for various ARM and MIPS platforms. Builds available at http://buildbot.orphis.net/armips/
MIT License
363 stars 77 forks source link

-definelabel is sign-extended from 32-bit to 64-bit #158

Closed Prof9 closed 5 years ago

Prof9 commented 5 years ago

Given the following test.asm:

.definelabel    testlabel2,0xFFFFFFFF
.gba
.create "test.bin",0
.org 0xFFFFFFFF
testlabel3:
.close

Assembled with:

armips -definelabel testlabel 0xFFFFFFFF -sym test.sym test.asm

Produces a test.sym with:

00000000 0
FFFFFFFFFFFFFFFF testlabel
FFFFFFFF testlabel2
FFFFFFFF testlabel3


As you can see, the 0xFFFFFFFF that was passed in with -definelabel was sign-extended from 32-bit to 64-bit. Whereas the ones defined with .definelabel and : were not.

We can also see this when we change all the label values to 0x1122334455667788, which will result in the following symfile:

00000000 0
FFFFFFFF55667788 testlabel
1122334455667788 testlabel2
1122334455667788 testlabel3


Though this somehow produces 0xFFFFFFFF55667788 and not just 0x55667788. It seems like any value at least 0x80000000 is just sign-extended anyway.

This is kind of annoying, since having such a 64-bit label in your symfile when you didn't intend to will cause No$gba to throw a Symbolic Info File Corrupt error and refuse to run the ROM.

Ideally all three of these methods would behave the same way.

A workaround is to use -equ testlabel 0xFFFFFFFF instead.