- #1

fiksx

- 77

- 1

- Homework Statement
- trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler.

- Relevant Equations
- addition / subtraction written using the MIPS assembler.

im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler.

im having hard times to debug this.

The input is given to the array of Formula char (base address $ s0) in the form of a formula.

The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored.

For example, if the input is Formula = “100 + 20 + 3”, $ s1 = 123, and if Formula = “− 100 + 20-3”, $ s1 = −83 is output.

The '+' and-in the program are the characters + 'and-, in ASCII respectively, and the ASCII characters are 0..9 are 48 (10), 49 (10) and 57 (10).

However when debugging this code produce 23, but the correct result is -83

where is the wrong part?

im having hard times to debug this.

The input is given to the array of Formula char (base address $ s0) in the form of a formula.

The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored.

For example, if the input is Formula = “100 + 20 + 3”, $ s1 = 123, and if Formula = “− 100 + 20-3”, $ s1 = −83 is output.

The '+' and-in the program are the characters + 'and-, in ASCII respectively, and the ASCII characters are 0..9 are 48 (10), 49 (10) and 57 (10).

Code:

```
.text
.globl main
main:
la $s0,word ##copy base address of array to t1
add $s1, $zero, $zero
add $s2, $zero, $zero
Addi $s3,$zero,1
Addi $t1, $zero,'+'
Addi $t2,$zero,'-'
addi $t3,$zero,10
Loop: lb $t0,0($s0)
Addiu $s0,$s0,1
Beq $t0,$t1,Plus
Beq $t0,$t2,Minus
Beq $t0,$zero,Cal
Addi $t0,$t0,-48
Mul $s2, $s2, $t3
Add $s2,$s2,$t0
J Loop
End:
li $v0,1
move $a0,$s1
syscall
li $v0, 10
syscall
Plus: addi $s4, $zero, 1
j Cal
Minus: addi $s4, $zero, 0
Cal: beq $s3,$zero,Subn
Addn:
add $s1,$s1,$s2
beq $s4,1,Join // this part I am not sure, maybe causing trouble and i don't know how can i save the after the +\- symbol
Subn: sub $s2,$s1,$s2
Join : add $s2,$zero,$zero
Beq $t0,$zero,End
Add $s3,$s4,$zero
J Loop
Exit:
li $v0, 10
syscall
.data
word: .asciiz "-100+20+3"
result: .asciiz "$s1->"
prompt: .asciiz "$s0->"
```

However when debugging this code produce 23, but the correct result is -83

where is the wrong part?

Last edited by a moderator: