Question: Exercise 1 Write a program in MIPS assembly code that: Inputs a 1x8 vector of single-digit integers Stores them into an 8-entry 32-bit Integer array,

Exercise 1

Write a program in MIPS assembly code that:

  1. Inputs a 1x8 vector of single-digit integers

  2. Stores them into an 8-entry 32-bit Integer array, V.

It is not completely trivial to do this given the Syscalls available and the desired input format.

Hint: Use Read String and not Read Integer, then convert from ASCII to integer before storing into the integer array, V. Use the ASCII table in the book to determine how to convert from ASCII to integer (there are two ways, both very easy, select the met hod as per the introduction).

After storing the integers in the array:

  1. Read the same values using Read Integer and store them in a 32-bit integer array, VPrime.

  2. Subtract the two arrays integer by integer and put the results into a third 32-bit integer array, VCheck.

  3. Sum all the values in VCheck and using Write Integer, display the result.

When you run the program, the input should look something like this with a space between numbers:

Input V: 1 4 0 2 7 3 8 4 

(this is just an example vector; it can be any string of single digit integers)

Input VPrime: 

1 4 0 2 7 3 8 4

(Where the integers: 0 1 2 3 4 ... 8 9 or whatever vector values the user wants to input are input by the user on the console.)

And the output will look like:

Check Result: 0 

----------------------------------------------------------------------------------------------

What I have is this but the check sum doesn't work and my prof says that I'm not using la correctly which I don't understand which one:

.data v: .word 0,0,0,0,0,0,0,0 vPrime: .word 0,0,0,0,0,0,0,0 vcheck: .word 0,0,0,0,0,0,0,0 answer: .space 32

prompt: .asciiz "Input V:" prompt2: .asciiz "Input VPrime:" newline: .asciiz " " output2: .asciiz "CheckResult: "

.text

main: #Promt the user to enter V li $v0,4 #load service number for string print in $v0 la $a0, prompt # load address of string to be printed into $a0 syscall

#get input li $v0,8 #system code for read string la $a0,answer #put address of answer string in $a0 la $a1,64 #put length of string in $a1 move $t0,$a0 syscall

#Store into integer array la $t1,v li $t2,0

loop: bge $t1, 8, main2 lb $t3,0($t0) # grab each element and put into t3 addi $v0, $zero, 11 # converts ASCII number to the correspodning number sw $t5,0($t1)

addi $t0, $t0, 1 # increments t0 by 1 addi $t1, $t1, 1# increments t1 by 1 syscall

j loop main2: li $v0,4 #system code for read string la $a0, prompt2 # load address of string to be printed into $a0 la $t1, vPrime syscall li $v0,11 la $a0, 10 syscall li $t3,0 loop2: bge $t3, 8, subtract li $v0,5 # read an integer lb $t2,0($t1)#put address of answer int into t2 addi $t1, $t1, 1 syscall addi $t3, $t3, 1 j loop2 subtract: la $t0,v la $t1,vPrime la $t2,vcheck li $t3,0

loopsubtract: beq $t3,8,sum lw $t4,0($t0) lw $t5,0($t1) sub $t7,$t4,$t5 sw $t7,0($t2) addi $t0,$t0,4 addi $t1,$t1,4 addi $t2,$t2,4 addi $t3,$t3,1 j loopsubtract sum: la $t6,vcheck li $t1,0 li $t2,0

#Calculate sum loopSum: beq $t2,8,result lw $t3,0($t6) # grabs a number from vcheck and saves it into t3 addu $t1,$t1,$t3 # adds the sums in vcheck addi $t0,$t0,4 addi $t2,$t2,1 j loopSum result: li $v0,4 la $a0,output2 syscall move $a0,$t1 li $v0,1 syscall

exit:

li $v0, 10 syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!