Write a complete MIPS assembly language program that implements the following pseudocode.
program h2
define global integer variables w,
x, y, z -- in the .data section
function main()
SysPrintStr("Enter an integer >= 0 for w? ")
w ← SysReadInt()
SysPrintStr("Enter an integer >= 0 for x? ") x
← SysReadInt()
SysPrintStr("Enter an integer < 0 for y? ")
y ← SysReadInt()
z ← 16(w + x) - (3 × -y mod 7)
SysPrintStr("z = ")
SysPrintInt(z)
SysExit()
end function main
end program h2
Miscellaneous program requirements and hints:
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 z = 415
De ne the four variables w, x, y, and z as words in the .data section. Initialize each to 0.
Place the string literals in the .data section using the .asciiz directive.
Information about the MARS system calls can be found by selecting Help | 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 de nitions of the inte- ger variables; and .asciiz to place the strings in the data section.
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), 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
.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
Write a complete MIPS assembly language program that implements the following pseudocode. program h2 define global...
im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...
CONCEPTS OF PROGRAMMING LANGUAGE Consider the following skeleton program skeleton. List all the variables, along with the program units where they are declared, that are visible in the bodies of Sub1, Sub2, and Sub 3, assuming static scoping is used. Procedure Main is X, Y, Z: Integer; procedure Sub1 is A, Y, Z: Integer; begin -- of Sub1 ... end; -- of Sub1 procedure Sub2 is A, X, W: Integer; procedure Sub3 is A, B, Z: Integer; begin -- of...
WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4 la...
Hello, I'm having trouble completing this program in less than four lines using MIPS programming language, we are required to fill in the missing code as indicated (via comments). IMPORTANT: As indicated in the program's comments: ⇒ Write no more than certain number of lines of code as indicated. (One instruction per line, and there will be penalty if your code consumes more lines.) ⇒ Code MUST use only instructions that are allowed i.e., only bit manipulating instructions: (ANDing, ORing,...
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...
Write an ARM assembly language program to translate the following sequence of statements . Assume x and y are memory locations that store two unsigned integers. Use the following: x is in R1, y is in R2, and z in R3. Make sure that your program works for any value of x and y. if (x > 15) { x = 1; if (y > 15) { y = 2; } else { y =...
NEED HELP WITH THIS . Write a MARIE assembly language program that would simulate calling and executing the following C function, as shown below: z = someFunction(a, b); where z, a and b are main( ) program variables, and the values stored in a and b are input by the user. The value stored in z will be output. Did your program execute correctly? This is the code for the function: int someFunction(int x, int y) { return 3 *...
Problems: 1. Write a program to define the following variables, assign them values, and print their values on screen: Integer x = 20, Float y = 40.45 Double z = 91.51e+5 Char w = A • • For the integer variable x, you need to print it in decimal notations, octal notations and hexadecimal notation. For the double variable y, you need to print it in double notations and scientific notation. 2. Write a program with the following three parts:...
Hi, I need help with this MIPS Problem. Thanks! (2 pts) Modify your program from exercise 1. Now, instead of having the variables x and y in your .data section, you should ask the user for two numbers. Each time you ask for a number, you should print: Enter number: You should add the two numbers typed at the console and print the sum. In this program, you'll need to make use of system calls 1, 4, and 5. I...
Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...