As anyone who has ever tried programming in assembly will tell you, it can be difficult. This thread is for people to post and discuss problems they may be having with their programs written in assembly.
I'll be posting assembly questions based around the MIPS architecture, but feel free to post questions about other architectures as well.
So, on to my first question:
Mainly, I'm having problems understanding when I need to and don't need to put on and take off my return address from the stack. My instructor made it seem like any time I used a jal I would need to push it on beforehand and load it back into $ra before I would jr $ra
Now, I've tried that in my assignment, and while it seems the program does exit, it exits and MARS (a MIPS IDE) displays an error saying "invalid program counter value: 0" An example of what I am doing is below:
So, am I understanding it wrong, or am I implementing it wrong? A tutor in the lab told me I didn't need to save it off at all, to just load opcode 10 and perform a syscall to exit, but I think I'll get docked points for doing that.
I'll be posting assembly questions based around the MIPS architecture, but feel free to post questions about other architectures as well.
So, on to my first question:
Mainly, I'm having problems understanding when I need to and don't need to put on and take off my return address from the stack. My instructor made it seem like any time I used a jal I would need to push it on beforehand and load it back into $ra before I would jr $ra
Now, I've tried that in my assignment, and while it seems the program does exit, it exits and MARS (a MIPS IDE) displays an error saying "invalid program counter value: 0" An example of what I am doing is below:
Code:
.data
letter: .asciiz "a"
.text
.globl main
main:
addi $sp, $sp, -4
sw $ra, 0($sp)
jal display_letter
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
display_letter:
li $v0, 4
la $a0, letter
syscall
jr $ra