Reputation: 526
I'm currently in a MIPS assembly class and the book we use is out of print so I am relying upon the internet for help so that I may understand. This program is taking in three integers. Two of them to add/sub/mult/div and the third is the operator. Here is the code.
.text
.globl __start
__start:
# Prompt for first int and accept first int
la $a0,firstint
li $v0,4
syscall
li $v0,5
move $s0, $v0
syscall
# Prompt for second int and accept second int
la $a0,firstint
li $v0,4
syscall
li $v0,5
move $s1, $v0
syscall
# Prompt for operation
la $a0,operation
li $v0,4
syscall
li $v0,5
move $s2, $v0
syscall
beq $s2,0,__add0
li $v0,10
syscall
__add0:
la $a0,added
li $v0,4
syscall
add $a0, $s0, $s1
li $a0,1
syscall
.data
firstint: .asciiz "Enter the first integer: "
secondint: .asciiz "Enter the second integer: "
operation: .asciiz "Enter operation (add=0, subtract=1, multiply=2, divide=3): "
added: .asciiz "The added number is: "
My understanding is that beq will jump to add0 if the value in $s2 is equal to 0.. but it does not seem to be happening. Output stops after entering the operation type. Example output:
Enter the first integer: 10
Enter the first integer: 5
Enter operation (add=0, subtract=1, multiply=2, divide=3): 0
-- program is finished running --
Any ideas?
Upvotes: 3
Views: 5438
Reputation: 2692
You have to do the syscall before the move:
li $v0,5
syscall
move $s2, $v0
Upvotes: 3