Thanks Name your source code file hw02-01.s. Write a complete MIPS assembly lang
ID: 3549725 • Letter: T
Question
Thanks
Name your source code file hw02-01.s. Write a complete MIPS assembly language program that implements this pseudocode: Program hw02-01 Define int variables a, b, c, d, answer PrintString("Enter a? ") a = ReadInt() PrintString("Enter b? ") b = ReadInt() PrintString("Enter c? ") c = ReadInt() PrintString("Enter d? ") d = ReadInt() answer = (a + b) - (c + d) PrintString("The answer is ") PrintInt(answer) End Program That is, the program asks the user to enter four signed integer values a, b, c, and d and then calculates and displays on the console (a + b) - (c + d). Miscellaneous program requirements and hints: Write the code so its behavior would match this sample output where sample user input is in bold: Enter a? 12 Enter b? 4 Enter c? -8 Enter d? -757 The answer is 781 Define a, b, c, d, and answer as global variables in the .data section using the .word directive. Initialize them to 0. Place the strings in the .data section using the .asciiz directive. The information on the MARS system calls can be found by selecting Help | Help on the main menu (or hit Fl). 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-implemented 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 integer variables a, b, c, d, and answer, .asciiz to place the strings in the data section. For my solution, I used these MIPS32 instructions so familiarize your self with them: add (signed addition): la (load address): li (load immediate): lw (load word): sub (signed subtraction): sw (store word): syscall (make a system call).Explanation / Answer
#####Data Segment##########
.data
number_prompt1:
.asciiz " Enter a : "
number_prompt2:
.asciiz " Enter b : "
number_prompt3:
.asciiz " Enter c : "
number_prompt4:
.asciiz " Enter d : "
out_msg1:
.asciiz " The answer (a+b)-(c+d) is : "
tab:
.asciiz " "
#####Code Segment###########
.text
.globl main
main:
la $a0,number_prompt1
li $v0,4
syscall
li $v0,5
syscall
move $t0,$v0
la $a0,number_prompt2
li $v0,4
syscall
li $v0,5
syscall
move $t1,$v0
la $a0,number_prompt3
li $v0,4
syscall
li $v0,5
syscall
move $t2,$v0
la $a0,number_prompt4
li $v0,4
syscall
li $v0,5
syscall
move $t3,$v0
add $t0,$t0,$t1
add $t2,$t2,$t3
sub $t0,$t0,$t2
la $a0,out_msg1
li $v0,4
syscall
move $a0,$t0
li $v0,1
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.