This code is part of a much bigger program that worked just fine. Then I realized the assignment would be tested in -bare mode. As soon as I tried running it in -bare mode my print_string syscalls went from working fine to not printing anything and I have no idea why.
Running this gives me no errors it just doesn't print anything
(also are the 2 or $0,$0,$0 necessary at the end?)
.globl main
.data
v: .space 2
w: .space 2
x: .space 2
y: .space 2
z: .space 2
inputPrompt: .asciiz "Input mathmatical expression: "
.text
main: #main block used to read in all the necessary data
lui $a0, 0x1001
#prompt for expression
addi $v0, $0, 4
addi $a0, $a0, 10
syscall
or $0,$0,$0
jr $ra
or $0,$0,$0
This is the problem:
lui $a0, 0x1001
If you look at the addresses in the DATA/STACK viewer in SPIM, you'll see that when you're in bare mode the DATA section starts at 0x10000000 instead of 0x10010000. So you should change that lui
to lui $a0, 0x1000
.
are the 2
or $0,$0,$0
necessary
Bare mode implies that branch delay slots are simulated. So you should fill any branch delay slots with instructions that are safe to execute there. That could be NOPs, or more meaningful instructions if you manage to reorganize your code. For example, if you had:
ori $a0,$0,1
jal foo
you could've changed that into:
jal foo
ori $a0,$0,1 # will be executed in the delay slot
Note that syscall
doesn't have any delay slot. From MIPS32™ Architecture For Programmers
Volume II: The MIPS32™ Instruction Set:
Format:
SYSCALL
Description:
A system call exception occurs, immediately and unconditionally transferring control to the exception handler