Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement an interactive MIPS code to calculate either of sum, max or min of the list depending on keyboard input - 4 different keyboard inputs

Implement an interactive MIPS code to calculate either of sum, max or min of the list depending on keyboard input

- 4 different keyboard inputs in an infinite loop until q. (e.g., your input could be x, s, s, n, s, x, q)

-- \'s -> you should print out the sum with a proper message (like "The sum is 232")

-- \'x -> you should print out the max

-- \'n -> you should print out the min

-- \'q -> you should quit the loop.

digits list is set. inputs are "character: q, s, x, n" .

this is my code.

when loading file, "Target of jump differs in high-order 4 bits from instruction pc 0x40008c" -> i don't know why i got this message.

And, when i run this code, i also got error message : "Exception occurred at PC=0x00010074" and "Bad address in text read: 0x00010074"

i wonder how to read char type user inputs in MIPS and store them like "scanf" in C programing.

.data userInput: .space 20 S: .word 's' #S for sum = s X: .word 'x' #X for max = x N: .word 'n' #N for min = n Q: .word 'q' #Q for quit = q

digit: .word 10, 12, 23, 28, 7, 39, 10, 11, 23, 12, 3, 4, 5, 1, 34, 17, 0, 5, 24 length: .word 19 # the length of the digit list

str: .asciiz " " sum: .asciiz "sum is " max: .asciiz "max is " min: .asciiz "min is "

.text

main:

while: li $v0, 12 la $a0, userInput

syscall

la $s1, digit lw $t0, 0($s1) add $t1, $t0, $zero #max add $t2, $t0, $zero #min add $t3, $t0, $zero #sum la $s2, length lw $t4, 0($s2)

Loop: addi $s1, $s1, 4 lw $t5, 0($s1) slt $t6, $t1, $t5 bne $t6, $zero, Max slt $t7, $t5, $t2 bne $t7, $zero, Min

Sum: add $t3, $t3, $t5 addi $t4, $t4, -1 addi $t8, $zero, 1 slt $t9, $t8, $t4 bne $t9, $zero, Loop j L1

Max: add $t1, $t5, $zero j sum

Min: add $t2, $t5, $zero j sum

L1: la $s3, 'q' #store 'Q' address lw $t5, 0($s3) la $s4, 's' #store 'S' address lw $t6, 0($s4) la $s5, 'x' #store 'X' address lw $t7, 0($s5) la $s6, 'n' #store 'N' address lw $t8, 0($s6) beq $a0, $s3, Exit beq $a0, $s4, PrintSum beq $a0, $s5, PrintMax beq $a0, $s6, PrintMin

PrintSum: li $v0, 4 la $a0, sum syscall

li $v0, 1 add $a0, $t3, $zero syscall

li $v0, 4 la $a0, str syscall j While

PrintMax: li $v0, 4 la $a0, max syscall

li $v0, 1 add $a0, $t1, $zero syscall li $v0, 4 la $a0, str syscall j While

PrintMin: li $v0, 4 la $a0, min syscall

li $v0, 1 add $a0, $t2, $zero syscall

li $v0, 4 la $a0, str syscall

j While Exit: #exit the system li $v0, 10 syscall

.end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+1. Which of the following are money in the U.S. economy?

Answered: 1 week ago