What to do: 1 Initialize x to be zero 2 Prompt the user for the next operation (
ID: 3621009 • Letter: W
Question
What to do:1 Initialize x to be zero
2 Prompt the user for the next operation (Addition or Subtraction)
3 Prompt the user for the next operand (y).
4 Perform the operation (x + y or x – y depends on the operation selected by
the user), and store back the result to x.
5 Output x in decimal.
6 Go back to step 2 until user input “q” as the next operation, then exit.
• Operations:
• Addition: perform x = x + y (when user input “+”)
• Subtraction: perform x = x - y (when user input “-”)
• quit: (when user input “q”).
• Operands:
• One operand (x) is initialized to be zero (defined in .data), and updated as
the result; the other operand is always provided by the user
• Output:
• Decimal value of the current result (x).
• Include integer multiplication (*) and division (/) operations
-perform x = x * y (when user input “*”), and output the product.
- perform x = x / y (when user input “/”), and output both the
quotient and remainder. In this case, x needs to be updated as the
quotient.
Explanation / Answer
Dear, Here is the code.. $t1 for x $t2 for y _start: li $t1,0 # $t1 store x=0 for $t1 la $a0,Y# print prompt on terminal li $v0,4 syscall Loop: lb $t3,operator # and $t3 will hold the char li $v0,5 # syscall 5 reads an integer syscall mov $t1,$vo lb $t3,char # and $t3 will hold the char beq $t3,’+’,Add beq $t3,’-’,Sub Add: add $t1,$t1,$t2 JMP print Sub: sub $t1,$t1,$t2 Jmp print print: la $a0,ans # system call to print li $v0,4 # out a message syscall move $a0,$t1 # system call to print li $v0,1 # out the count worked out syscall la $a0,endl # system call to print li $v0,4 # out a newline syscall la $a0,prompt # print prompt on terminal li $v0,4 syscall mov ah, 1h ; keyboard input subprogram int 21h ; read character into al mov dl, al beq ah,’q’,exit Jmp Loop exit: li $v0,10 syscall .data Y: .asciiz ”Enter Y:” ans: .asciiz "Result:" prompt: .asciiz "To Quit enter ‘q’" endl: .asciiz " " Hope this will help you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.