Hi everyone. I'm fairly new to programming with spim. This is the first time I've tried to multiply numbers and I keep getting errors!
I looked up on 'SPIM quick reference' how to do multiplication but can't get it to work.
Any help would be greatly appreciated :)

PS. I hope my code is readable, apologies if its not to standard coding practices

.data
.text
.globl main
main:
li $v0, 5 #read int (x)
syscall
# first int is stored in $v0 
move $s0, $v0  # first int in $s0


# read in 2nd int
li $v0, 5 # read int (y)
syscall
#2nd int is stored in $v0
move $s1, $v0 #2nd int in $s1

# x^2

mult $s2, $s0, $s0  # x^2 is in $s2

# 4y^2
mult $s3, $s1, $s1  # y^2 is in $s3
mult $s3, $s3, 4  # 4y^2 is in $s3

# 4xy
mult $s4, $s0, $s1  # $s4 is xy
mult $s4, $s4, 4  # $s4 is 4xy

# -6y
mult $s5, $s1, -6  # $s5 is -6y

#  Put it all together
add $s6, $s2, $s3
add $s6, $s6, $s4
add $s6, $s6, $s5
addi $s6, $s6, 9

#print it
move $a0, $s6
li $v0, 1
syscall


li $v0, 10 # exit
syscall

Recommended Answers

All 3 Replies

error message:

spim: (parser) syntax error on line 19 of file
mult $s2, $s0, $s0 # x^2 is in $s2
^

I am not sure if this will help, but the syntax for mult is
mult Rsrc1, Rsrc2
This leaves the low order bits in lo, and the high order bits in hi.
Maybe what you are looking for is mul -
mul Rdest, Rsrc1, Src2
Let us know if this makes a difference-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.