Here is my code:
.data
num1: .word # num1 variable
num2: .word # num2 variable
max: .word # max variable
msg: .asciiz "Enter an integer " # msg
msg2: .asciiz "The bigger value is " # msg2
.text
main:
la $a0, msg # prints msg
li $v0, 4
syscall
la $v0, 5 # reads data
syscall
# loads address of num1 to $t0
la $t0, num1
# moves the content of $v0 to $t0
move $t0,$v0
la $a0, msg # print msg
li $v0, 4
syscall
la $v0, 5 # read data
syscall
# loads address of num1 to $t1
la $t1, num2
# moves the content of $v0 to $t1
move $t1,$v0
# loads address of max to t2
la $t2, max
# if $t0 (num1) > $t2 (num2), execute if part/label
bgt $t0,$t1,if # go to if label
# else
else:
# moves the contents of $t1 (num2) to $t2 (max)
move $t2,$t1
la $a0, msg2 # print msg2
li $v0, 4
syscall
move $a0, $t2 # print max
li $v0, 1
syscall
li $v0, 10 # exit
syscall
# if
if:
# moves contents of $t0 (num1) to $t2 (max)
move $t2,$t0
la $a0, msg2 # print msg2
li $v0, 4
syscall
move $a0, $t2 # print max
li $v0, 1
syscall
li $v0, 10 # exit
syscall
Every time I try running this code in QTSpim, I get the error "spim: (parser) syntax error on line 3 of file C:/Users/danie/Desktop/program_1.asm .word # num1 variable"
What am I doing wrong? Thank you
You want
.word 0to emit one 32-bit word with value0..wordwith no operands would reserve 0 bytes of space, for that empty list of word initializers. (This is how some other assemblers actually do handle it, not erroring.) So it's likeuint32_t array[] = {};in C1, like declaring an array of 0 elements.That's not what anyone wants (a normal person would just leave out
.wordentirely if they just wanted to put multiple labels on the same address), so it seems the SPIM assembler stops you from writing something useless and treats it as an error. I guess maybe you can imagine a macro that expands to nothing for some configs, which is maybe why other assemblers choose not to error and treat.wordas taking a list of zero or more word values, instead of one or more.Footnote 1: Except in C two arrays can't have the same address even if empty, or at least GCC avoids that. GCC does actually emit some padding after an empty array: https://godbolt.org/z/5GMT6e