Easy add to MIPS

I am currently in a MIPS build class and the book we are using is coming out of print, so I rely on the internet for help so I can understand. This program takes three integers. Two are for adding / sub / mult / div and the third is for 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: "

      

I understand that beq will jump to add0 if the value in $ s2 is 0 .. but it doesn't seem to be happening. Exit stops after entering the type of operation. Output example:

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?

+3


source to share


1 answer


Before proceeding, you need to execute syscall:



li $v0,5
syscall
move $s2, $v0

      

+3


source







All Articles