please solve 18 18. Write a complete MIPS assembly language program that impleme
ID: 3793569 • Letter: P
Question
please solve 18
18. Write a complete MIPS assembly language program that implements the following pseudocode. program h2 define global integer variables w, r, y, z in the data section function main() SysPrintstr("Enter an integer for w? SysReadInt SysPrintstr("Enter an integer 0 for x? z SysReadInt SysPrintstr("Enter an integer 0 for y? y SysReadInt z 16 (w 2) (3 x y mod 7) SysPrintstr( Sys Print Int (z) SysErit() end function. main end progra 2 Miscellaneous program requirements and hints a. Write the code so its output and behavior would match mine shown below, where user input is in bold Enter an integer 0 for w? 9 Enter an integer 0 for x? 17 Enter an integer 0 for y? -5 415 b. Define the four variables w, T, y, and 2 as words in the data section. Initialize each to 0. c. Place the string literals in the .data section using the .asciiz directive. d. Information about the MARS system calls can be found by selecting Help I Help on the main menu (or hit F1). In the Help window, click on the Syscalls tab. Information on MARS-implemented MIPS32 instructions can be found by clicking on the Basic Instructions and Extended (pseudo) Instructions tabs. Information on MARS impl- emented assembler directives can be found by clicking on the Directives tab. For this program you will need to use the following directives: data for the data section: .text for the text section rd for the definitions of the inte- ger variables; and .asciiz to place the strings in the data section. e. For my solution, I used these MIPS32 instructions so familiarize yourself with them: add (addition), addi (addi tion with an immediate), div (division), lw (load word), mul (multiplication sll (shift logical left), s (sub- traction) sw (store word. syscall (perform system cal I also used these pseudoinstructions: la (load address and neg (negate). Note: MARS implements many non-standard pseudoinstructions, documented in the Help sys tem. You are not permitted to use these non-standard pseudoinstructions in your homework assignments or exams. The only instructions you may use are those that we discussed and are documented in the notes. The reaExplanation / Answer
Following is the MIPS program for above question
.data
w: .word 0
x: .word 0
y: .word 0
z: .word 0
msg1: .asciiz "Enter an integer >= 0 for w?"
msg2: .asciiz "Enter an integer >= 0 for x?"
msg3: .asciiz "Enter an integer < 0 for y?"
msg4: .asciiz "z= "
.text
li $v0, 4
la $a0, msg1
syscall
li $v0, 5
syscall
lw w, $v0
li $v0, 4
la $a0, msg2
syscall
li $v0, 5
syscall
lw x, $v0
li $v0, 4
la $a0, msg3
syscall
li $v0, 5
syscall
lw y, $v0
lw $s0, w
lw $s1, x
lw $s2, y
addi $t0, $s0, $s1 #t0 = w+x
mul $t0, $t0 , 16 # t0 = 16(w+x)
nor $s2, $s2, $s2
mul $s2 , $s2, 3
div $s2, 7 # -y div 7
mfhi $t1 # -y mod 7
sub $t2 , $t0 , $t1
li $v0, 4
la $a0, msg3
syscall
li $v0, 1
la $a0, $t2
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.