1whatleytay / saturn

A modern MIPS interpreter and assembler.
MIT License
29 stars 6 forks source link

Hex Regions export bug for addi with hex immediates #15

Closed finesden33 closed 3 months ago

finesden33 commented 7 months ago

for example, .text addi $s0, $0, 0x1234 addi $t0, $0, 0x0c00 addi $t0, $t0, 0x0001 addi $t0, $t0, 0x0001 addi $t0, $t0, 0x0001 addi $s0, $t0, 0xffff addi $t1, $0, 0xffff addi $t1, $t1, 0xffff

exports to this (with HEXV3 and 32 bit little-endian configurations):

v3.0 hex words plain 20101234 20080c00 21080001 21080001 21080001 3401ffff 01018020 3401ffff 00014820 3401ffff 01214820

1whatleytay commented 7 months ago

This is expected behavior. The s addi $s0, $t0, 0xffff instruction doesn't exist in native MIPS bitcode. The immediate for addi is signed, so an immediate value of 0xffff would be equivalent to addi $s0, $t0, -1 (e.g. the instruction would subtract one instead of adding 0xffff).

Saturn knows that you probably don't want to subtract here. Instead, it will generate two instructions (a load immediate equivalent and an addi) so your intent is expressed properly- a secret pseudo-instruction! That's why multiple instructions are emitted here. You can see the exact instructions it emitted by hitting File -> Assemble Elf.

Let me know if you have any questions 👍

SallyZhijing commented 7 months ago

image This is the version I was using, and I did File->Export Hex Regions with default settings, it creates an empty folder with nothing in it, and there's nothing shown in the console: image but when I check the CONTINUOUS EXPORT, then it can create the file I want but with no folder.

1whatleytay commented 3 months ago

This should be fixed in v0.1.8 👍

1whatleytay commented 3 months ago

Going to close this with the release of v0.1.8.