Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MIPS Question .text .globl __start __start: # execution starts here la $a0, msg1

ID: 668083 • Letter: M

Question

MIPS Question

   .text      
    .globl __start
__start:           # execution starts here
          
   la $a0, msg1       # load address of msg1 into register
   li $v0, 4       # li means load immidiate. This instruction is the same as addi $v0, $zero, 4
   syscall           # make a syscall to print msg1 in console window
               # ($v0=4 tells the system call to print the characters that are at address $a0 to console)


   li   $v0, 5       # system call code for read integer = 5
   syscall           # call operating system to read an integer from the console
               # value read from keyboard returned in register $v0
   add $s0, $zero, $v0   # move $v0 to $s0


               # write your code here

   ###### printing the result to console

   la $a0, msg2       # load address of msg2 into register
   li $v0, 4
   syscall           # make a syscall to print msg1 in console window
          
   li   $v0, 1       # system call code for printing integer = 1
   li   $a0, 0       # move integer to be printed into $a0: $a0 = 0
   syscall           # call operating system to perform print

   li $v0, 10
   syscall           # exit the program via syscall      

# Start of the data segment
   .data

msg1:       .asciiz       "Enter an integer between 0 and 7: "
msg2:      .asciiz       "The computed result is: "
MyArray:   .word 5, -10, 12, 0x12, 0xfabc, 350, 124, -500, 0, 0xa

For this part and, you need to write assembly code for MIPS. QtSpim does not have an editor and is just a simulator. This means you need to edit your code in a basic editor such as Notepad for windows. Make sure you save it after you are done with editing. Then in QtSpim, under File, choose "Reinitialize and Load File" and select your new assembly file. For Part 2: After the user enters an integer between 0 and 7, your task is to use that integer as index i. Then, perform the following operation: MyArray[i+2] = MyArray[i]+MyArray[i+1 ] MyArray is an array words defined in the data segment at the bottom of hw1.asm. It is preloaded with 10 integer values. In addition to performing the above task, you need to print the result of the sum to the console. Slightly modify the bottom of the code of hw1.asm in order to achieve this

Explanation / Answer

.text
.globl __start
__start: # execution starts here
  
la $a0, msg1 # load address of msg1 into register
li $v0, 4 # li means load immidiate. This instruction is the same as addi $v0, $zero, 4
syscall # make a syscall to print msg1 in console window
add $s1, $zero, $v0 # move $v0 to $s0
# ($v0=4 tells the system call to print the characters that are at address $a0 to console)

li $v0, 5 # system call code for read integer = 5
syscall # call operating system to read an integer from the console
# value read from keyboard returned in register $v0
add $s0, $zero, $v0 # move $v0 to $s0

# write your code here
mov ecx,x #move current element to sum
add $a0, ecx #Arrays myarray[i]
add ecx,1 #incrementing
add $a1, ecx # myarray[i+1]
add ecx,1
add $a2, ecx # myarray[i+2]
add $a3, $a0,$a1 #adding MyArray[i] + myarray[i+1]
mov [$a2], $a3 #storing sum to myarray[i+2]


###### printing the result to console
la $a0, msg2 # load address of msg2 into register
li $v0, 4
syscall # make a syscall to print msg1 in console window
  
li $v0, 1 # system call code for printing integer = 1
li $a0, 0 # move integer to be printed into $a0: $a0 = 0
syscall # call operating system to perform print
li $v0, 10
syscall # exit the program via syscall
# Start of the data segment
.data
msg1: .asciiz "Enter an integer between 0 and 7: "
msg2: .asciiz "The computed result is: "
MyArray: .word 5, -10, 12, 0x12, 0xfabc, 350, 124, -500, 0, 0xa

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote