0
votes

I know this maybe a stupid question, but I just want to be sure about this. I am able to use the load address (la) function without having .data in my program? If not, I am able to have the user enter a string in the .data part so that I can use a load address to retrieve that string the user entered?

Right now I am trying to create an encryption such as the user enters a string and enters an integer. That integer will add up each character in the string by that integer they entered. If I cant do any of those options up there, would someone help point me in the right direction on how to do this.

Thank you for taking the time to read this.

1
Why not just try it and see if it works? - Michael
Because the computer I was using at the time didn't have Mars Mips on it. - Rubert
Also It wouldn't hurt to understand whats happening when I am doing these actions. I could check the program it self, but I might have the wrong idea on whats happening. I just want to make sure my observations are not wrong. - Rubert

1 Answers

0
votes

Some terminology first: la is not a function, it's an instruction. Actually it's a pseudo-instruction, meaning that it doesn't actually exist in the MIPS instruction set, and the assembler will translate it into one or more MIPS instructions for you.

Now, la doesn't really have anything to do with the .data section. Its purpose is simply to load the address of some symbol into a register. So it's perfectly legal to do this:

.text
main:
la $t0,main  # load the address of main into $t0

However, if you intend to write to the address you got with la you typically want that address to be somewhere in a writable section of your program, like .data or .bss.

have the user enter a string in the .data part so that I can use a load address to retrieve that string the user entered?

You only need to re-load the address if the register that contains it gets overwritten. If you read the documentation for the MARS system calls you'll see that it says:

MIPS register contents are not affected by a system call, except for result registers as specified in the table below.

And the read_string syscall has no result, so it's perfectly fine to do:

.data
foo: .space 32
.text
main:
la $a0,foo
li $a1,32
li $v0,8
syscall    # read_string
# $a0 still contains the address of foo here
li $v0,4
syscall    # print_string