Question

im trying to complete mips program code about a calculator program that can calculate integer addition...

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).


    .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 //here im not sure
           
              beq $s4,1,Join
            
              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->"

it produce 23 but the right answer -83, which one is wrong?

However when debugging this code produce 23, but the correct result is -83 where is the wrong part?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the updated code below::

.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,'+'
move $s7,$t1
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,End
Addi $t0,$t0,-48
Mul $s2, $s2, $t3
Add $s2,$s2,$t0
J Loop
  
  
  
End:
   li $s6,1
Beq $s7,$t1,Addn
Beq $s7,$t2,Subn  
  
  
  
li $v0, 10
syscall
  
Plus:
move $s4,$t1 #store plus sign
    Beq $s7,$t1,Addn
Beq $s7,$t2,Subn
  
j Join
Minus:
move $s4,$t2 #store plus sign
    Beq $s7,$t1,Addn
Beq $s7,$t2,Subn
   j Join

Addn:
add $s1,$s1,$s2 #here im not sure
j Join
Subn: sub $s1,$s1,$s2
  
Join :
beq $s6,1,Exit
move $s7,$s4 #load value
add $s2,$zero,$zero
Beq $t0,$zero,End
Add $s3,$s4,$zero
J Loop
  
  
Exit:
li $v0,1
move $a0,$s1
syscall
  
.data
word: .asciiz "-100+20+3"
result: .asciiz "$s1->"
prompt: .asciiz "$s0->"

output:

Add a comment
Know the answer?
Add Answer to:
im trying to complete mips program code about a calculator program that can calculate integer addition...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​be...

    what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall

  • .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0,...

    .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall /// whats the output of above assembly program

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

  • It's a MIPS question. Can anyone explain what's happened in the loop? Thank you. I need...

    It's a MIPS question. Can anyone explain what's happened in the loop? Thank you. I need a deep explanation. Ma1n SvO, 4 $a0, stri1 # print string upper case 14 syscall $v0, 4 $a0, string 16 # print string "ABCDEFG. 18 syscall v0, 4 $a0, str2 19 # print string lower case 21 syscall 23 1oo 24 25 26 $t1, string($tO) beq $t1, $zero, exit blt $t1, A', continue bgt $t1, 2', conti addi $t1, $t1, 0x20 sb #t0 to...

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

  • MIPS - Takes two inputs from the user, which are the lengths of two sides of...

    MIPS - Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle. See blue highlighted. preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...

  • please trace this is sort program and base address s0, number of element s1 please also complete the program(..) explai...

    please trace this is sort program and base address s0, number of element s1 please also complete the program(..) explain the program too thanks sit $t4, $t1, $to beq $t4, $zero, Skip sll $s1, $s1, 2 add $s2, $s0, $s1 addi $t2, $so, 0 Skip: oopl: addi $t3, $t2, 0 oopJ: addi $t3, $t3, 4 beq $t3, $s2, NextI Iw $to, 0($t2) lw NextI: addi $t2, $t2, 4 End: 配列の昇順ソートベースアドレス$50, 空欄を埋めてプログラムを完成させよ。 要素数$51 sit $t4, $t1, $to beq $t4, $zero, Skip...

  • 1. What would be the output of the following MIPS code? .globl main main addu $s7, $0, $ra add $s3, $0,$0 addi $s4, $0,...

    1. What would be the output of the following MIPS code? .globl main main addu $s7, $0, $ra add $s3, $0,$0 addi $s4, $0, 1 $s5, $0,$0 $s6, save add . data .align 2 .globl save # the next line creates an array of 10 words that can be re ferred to as "save" # the array is initialized to the 10 values after .wo rd # so the first array entry is a 0 and the last entry is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT