1whatleytay / saturn

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

Issue: data directives not honoured unless initialized #22

Open cartoon-raccoon opened 3 months ago

cartoon-raccoon commented 3 months ago

While writing in MIPS, I used several .word directives, but didn't initialize them with a value, as they get initialized later on in the program. However, the assembler doesn't honour this and set aside space for them in the final executable.

LBL_1_ADDR:
    .word LABEL_1               # storing LABEL_1's address
LBL_2_ADDR:
    .word LABEL_2
LABEL_1:
    .word                               # say this address is 0x10010068
LABEL_2
    .word

main:
    lw $t0, LBL_1_ADDR      # this reads 0x10010068
    lw $t1, LBL_2_ADDR      # this also reads 0x10010068

The fix would be to use .word 0, then the assembler does set aside space for them.

I'm not sure if this behaviour is intended, as I haven't seen this behaviour among other assemblers, but I thought it was worth bringing to your attention.

milomg commented 3 months ago

Mars (which I believe saturn is trying to be compatible with) has the same behaviour on a program like this

.data
LBL_1:
    .word
LBL_2:
    .word

.text
main:
    la $t0, LBL_1
    la $t1, LBL_2
1whatleytay commented 2 months ago

Yeah, the .word directive gets a sequence of numbers. So .word 0 1 2 3 is also valid and will create 4 words. .word with no arguments will take zero words.