Write a complete MIPS assembly language program that impleme
Write a complete MIPS assembly language program that implements the following pseudocode. program h2
18. Write a complete MIPS assembly language program that implements the following pseudocode. program n2 define global integer variables w y, z in the data section function main() SysPrintstr(\"Enter an integer for w? SysReadint C) SysPrintstr(\"Enter an integer for x? z SysReadint C) SysPrintstr(\"Enter an integer 0 for y? y SysReadint C) 16 (w r) (3 x y mod 7) SysPrintstr Sys Print Int (z) SysEzit() end function main end program h2 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 for x? 17 Enter an integer 0 for y? -5 415 b. Define the four variables w, T, y, and z 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 word 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), d (division), lw (load word) mul (multiplication sll (shift logical left), sub (sub- traction sw (store word), syscall (perform system call). 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 rea-Solution
.data //tells the assembler that we are in data segment
 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 = \"
w: .word 0
 x: .word 0
 y: .word 0
 z: .word 415
.text //tells the assembler that we are in text segment
main:
# promt the user to enter w
 li $v0 , 4
 la $a0, msg1
 syscall
#get the user input w
 li v0, 5
 syscall
 move w, v0 // move it to w
# promt the user to enter x
 li $v0 , 4
 la $a0, msg2
 syscall
#get the user input x
 li v0, 5
 syscall
 move x, v0 // move input to x
# promt the user to enter x
 li $v0 , 4
 la $a0, msg3
 syscall
#get the user input x
 li v0, 5
 syscall
 move y, v0 // move the input to y
// to perform the modulo op
 move t1, -y
 move t2, 7
 div t1, t2
 mfhi t3 // t3 = t1%t2
add r1, w, x
 mul r1, r1, 16
mul r2, 3, t3
 sub r1, r1, r2
 move z, r1 // move the final result into z
#print z=
li $v0 , 4
 la $a0, msg4
 syscall
 //print the value of z
 li $v0, 1
 lv $a0, z
 syscall
exitProgram: li $v0, 10 # system call to
 syscall # terminate program


