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
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.