Assembly language (MIPS)
Let register $8 be x and register $9 be y. Write a program to evaluate:
Z = 3x - 5y+5
Leave the result in register $10. Inspect the register after running the program to check that the program works. Run the program several times, initialize x and y to different values for each run.
.data
x: .word 10
y: .word 2
msg: .asciiz "z = "
.text
main:
#load value 3 to $t0
li $2,3
#load value 5 to $t1
li $3,5
#load x value to $t8
lw $8,x
#load y value to $t9
lw $9,y
#multiply $2 and $8,result stores in $10
# 3*x
mul $10,$2,$8
# 5*y
mul $5,$9,$3
#subtract $10 and $5,result stores in $10
# 3x - 5y
sub $10,$10,$5
#add $10 and $3,result stores in $10
# z = 3x - 5y + 5
add $10,$10,$3
#print msg1
li $v0,4 #print string syscall value is 4
la $a0,msg #load address of msg to $a0
syscall
#print z value
li $v0,1 #print integer syscall value is 1
move $a0,$10 #load z value to $a0
syscall
#terminate the program
li $v0, 10
syscall
For x = 4 and y = 5
For x = 10 ,y = 2
For x = 15,y = 6
Assembly language (MIPS) Let register $8 be x and register $9 be y. Write a program...
1- Write a MIPS assembly program to initialize register Ss0 to 8, register Ssl to 12, regis- ter Ss2 to 5, and register Ss3 to 2. Then, store register Ss0 in the first element of an array, register Ssl in the second element of the array, register Ss2 in the third element of the ar- ray, and register Ss3 in the fourth element of the array. Then, sort the elements of the ar- ray using the selection sort algorithm, and...
Write the hexadecimal notation for a MIPS machine language program that adds 42 to the value in register 2 placing the result in register 3 and then returns. Example of running the program: Enter value for register 1: 2 Enter value for register 2: 3 Running MIPS program. MIPS program completed normally. $01 = 0x00000002 $02 = 0x00000003 $03 = 0x0000002D ...
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...
3. Write a program in assembly language that reads a number from the keyboard and displays it on the screen. 4. Write a program in assembly language to ask two digits from the user, store the digits in the EAX and EBX register, respectively, add the values, store the result in a memory location 'res' and finally display the result.
Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program: loop: addi Sto, $to,-1 bne $to, $zero, loop Translate the second instruction into MIPS machine language and write it in hex. 2. (2 pt) Which best describes the reason that we maintain the stack pointer in a register? (circle one) i. The hardware forces use of a stack pointer. ii. We need a local pointer because we are often limited to relative addressing. ili....
Write the program in MIPS
Initialize register $t0 (will hold the sum) to zero. Then add 409610 to $t0 sixteen times. You don't know how to loop yet, so do this by making 16 copies of the same instruction. The hexadecimal value of 409610 is 0x1000 Next, initialize register Stl to 409610. Shift St1 left by the correct number of positions so that registers $t0 and $tl contain the same bit pattern. Finally, initialize register $t2 to 409610. Add $t2...
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 =...
Given: MIPS Programming in MIPS Assembly Language Assume: Load, Store, R-format, and Jump (j) instructions have CPI = 1 Assume: Branch and jr or ja Instructions (e.g., branches) have CPI = 2 Assume: All MIPS system calls (e.g., for printing) have CPI = 3 Assume: Variable x stored in register $s1, y in $s2, z in $s3, i in $t0 Express the following precondition loop in MIPS assembly language x := 0 ; i := 5 ; # Document each MIPS...
Write one equivalent MIPS assembly language for the HLL code: E = F -10 when the compiler associates E with register $s6 and F with register $s7. (Hint: Remember that there is no SUBI instruction in MIPS)
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write it out to the console.