I am working on a program in MIPS using MARS simulator to read and write .pgm files. It consists of several files containing different helper functions, but for the purposes of this question, there are 2 files of concern: main.asm, and writeimage.asm.
In the .data segment of writeimage.asm, I want to initialize: a string literal "P5\n" a string literal "P2\n" a buffer size, so that I can play with this parameter without having to hardcode a buffer size.
Here is the 'preamble' (if I may call it that) of writeimage.asm:
.data
myStack: .space 5
writeBuffer: .space 128
.align 2
writeBufferSize: .word 128
.align 2
p5: .ascii "P5\n"
.align 2
p2: .ascii "P2\n"
.text
.globl write_image
write_image: ...
For some reason, when run my program from main, when I try to access writeBufferSize like so:
la $t0, writeBufferSize
lw $s0, ($t0)
the value loaded into $s0 is zero. Also, the strings p2 and p5 do not seem to exist at the addresses MARS says they are in. Later on in the code I try to write these stings to a file, and when I load the address of the string into $a1 and perform the syscall, what gets printed to the file is nothing; and when I look at the address that is loaded into $a1, and use the debugger to see the contents of that memory address, it's blank, as if the string never existed.
I do not have this issue when I assemble writeimage.asm only, only when I assemble from main, and when I assemble all files in the directory.
I am very frustrated by this, and I really don't want to go hard coding buffer lengths throughout my code. Please help!
Thanks