I am trying to finish this MIPS calculator, super basic, my first mips program. It should not handle overflow or something like that, just need to work with small positive numbers.
I have not tested my algorithms for multiplication and division, because I'm just trying to add work.
I can’t understand in life why ints will not read, and also I get memory outside the field when I call lb $ a0, op to display the operator for output and don’t understand why.
I am new to this, so everything is possibly helpful. Thanks in advance.
.data
welc: .asciiz "Welcome to SPIM Calculator 1.0!\n"
p_int: .asciiz "\nPlease give an integer: "
p_op: .asciiz "\nPlease give an operator: "
i_err: .asciiz "\nInput Incorrect, bad operator!\n"
again_str: .asciiz "Another calculation? (y/n)"
rmndr: .asciiz " r: "
new_line: .asciiz "\n"
int1: .word 1
int2: .word 1
raw_in: .space 1
op: .space 1
a_char: .space 1
out: .word 1
remain: .word 1
c_plus: .ascii "+"
c_min: .asciiz "-"
c_mult: .asciiz "*"
c_divi: .asciiz "/"
c_eq: .asciiz "="
c_no: .asciiz "n"
.text
.globl main
main: li $v0, 4
la $a0, welc
syscall
calc: la $t6, remain
move $t6, $zero
li $v0, 4
la $a0, p_int
syscall
li $v0, 5
syscall
la $s1, int1
move $s1, $v0
li $v0, 4
la $a0, p_int
syscall
li $v0, 5
syscall
la $s2, int2
move $s2, $v0
li $v0, 4
la $a0, p_op
syscall
li $v0, 8
la $a0, op
syscall
lb $t0, op
li $t1, '+'
li $t2, '-'
li $t3, '*'
li $t4, '/'
la $s0, out
beq $t0, $t1, plus
beq $t0, $t2, minus
beq $t0, $t3, multi
beq $t0, $t4, divi
j error
plus: add $s0, $s1, $s2
j print
minus: sub $s0, $s1, $s2
j print
multi: slt $t1, $t2, $s2
beq $t1, $zero, print
add $s0, $s1, $s1
j multi
divi: la $t0 remain
move $t0, $s1
add $s0, $zero, $zero
loop: slt $t1, $t0, $s2
beq $t1, $zero, print
sub $t0, $t0, $s2
addi $s0, $s0, 1
j loop
print: li $v0, 1
la $a0, int1
syscall
li $v0, 4
lb $a0, op
syscall
li $v0, 1
la $a0, int2
syscall
li $v0, 4
la $a0, c_eq
syscall
li $v0, 1
la $a0, out
syscall
la $t0, remain
beq $t0, $zero, again
li $v0, 4
la $a0, rmndr
syscall
li $v0, 1
la $a0, remain
syscall
again: li $v0, 4
la $a0, new_line
syscall
la $a0, again_str
syscall
li $v0, 8
la $a0, a_char
syscall
lb $t0, a_char
li $t1, 'n'
beq $t0, $t1, exit
j calc
error: li $v0, 4
la $a0, i_err
syscall
j again
exit: li $v0, 10
syscall
screenshot