Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: data directives not honoured unless initialized #22

Open
cartoon-raccoon opened this issue Mar 27, 2024 · 2 comments
Open

Issue: data directives not honoured unless initialized #22

cartoon-raccoon opened this issue Mar 27, 2024 · 2 comments

Comments

@cartoon-raccoon
Copy link

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
Copy link
Contributor

milomg commented Mar 27, 2024

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants