0% found this document useful (0 votes)
45 views

HomeWorks 6 Assembly

The document describes three MIPS assembly language programs. The first program loads values into registers, computes x^2 + 3y + 10z, and stores the result in $t3. The value in $t3 is 0xc7e in hexadecimal. The second program loads values into registers $t4 and $t7, performs operations to compute a value, and stores the result in multiple registers including $s7, which contains 0x85e in hexadecimal. The third program solves the equation w = 4x^2 + 8y + z, with given values for x, y, and z, stores the result in $s0, and ends the program. The value of

Uploaded by

Hjonk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

HomeWorks 6 Assembly

The document describes three MIPS assembly language programs. The first program loads values into registers, computes x^2 + 3y + 10z, and stores the result in $t3. The value in $t3 is 0xc7e in hexadecimal. The second program loads values into registers $t4 and $t7, performs operations to compute a value, and stores the result in multiple registers including $s7, which contains 0x85e in hexadecimal. The third program solves the equation w = 4x^2 + 8y + z, with given values for x, y, and z, stores the result in $s0, and ends the program. The value of

Uploaded by

Hjonk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

HomeWorks

Assignment 1: Write a program on your computer to do the following:

– Enter 47 into $t0 (“x”)


– Put 253 into $t1 (“y”)
– Load 23 in $t2 (“z”)
– Compute x2 + 3y + 10z
– Store the result in $t3
– Stop the program by using system call 10.
.text mul $t4, $t1, $t4 # $t4 = 3 * y

.globl main add $t3, $t3, $t4 # $t3 = x^2 + 3y

li $t4, 10

main: mul $t4, $t2, $t4 # $t4 = 10 * z

# Assign values add $t3, $t3, $t4 # $t3 = x^2 + 3y + 10z


(final result)
li $t0, 47 # x = 47

li $t1, 253 # y = 253


# Store the result in $t3 (already done)
li $t2, 23 # z = 23

# Exit the program


# Compute x^2 + 3y + 10z
li $v0, 10 # syscall code for exit
mul $t3, $t0, $t0 # $t3 = x * x (x^2)
syscall
li $t4, 3

– What is the number in $t3? Hex: 0xc7e



Assignment 2 Write a program to do the following:

– Load 25 in $t4 and 126 into $t7.


– Add the contents of registers $t4 and $t7, storing in $t3.
– AND this result with $t4, storing in $s2.
– Multiply $s2 by the contents of $t7, storing in $t9.
– Also store the result in $t9 in $s5 and $s7.
– Use syscall 10 to end the program.
.text

.globl main main:


# Load values # Multiply $s2 by $t7, store in $t9

li $t4, 25 # Load 25 into $t4 mul $t9, $s2, $t7

li $t7, 126 # Load 126 into $t7

# Store result in $t9 in $s5 and $s7

# Add $t4 and $t7, store in $t3 move $s5, $t9

add $t3, $t4, $t7 move $s7, $t9

# AND $t3 with $t4, store in $s2 # Exit the program

and $s2, $t3, $t4 li $v0, 10 # syscall code for exit

syscall

– What is the value of the number in $s7 (state in hex)? 85e


– Assignment 3 Write a program to solve the equation: w = 4x2+8y+z. value of w in hex?
0x90bd3
– Variable x is 0x123, y is 0x12b7, and z is 0x34af7.
– Use $t0 for x, $t1 for y, and $t2 for z.
– Remember to start your program with .text and label the first instruction as “main:”.
– Store w in $s0 and end your program with syscall 10.
.text # Compute 8y

.globl main li $t3, 8

main: mul $t3, $t1, $t3 # $t3 = 8 * y

# Assign variables

li $t0, 0x123 # x = 0x123 # Compute w = 4x^2 + 8y + z

li $t1, 0x12b7 # y = 0x12b7 add $s0, $s0, $t3 # $s0 = 4x^2 + 8y

li $t2, 0x34af7 # z = 0x34af7 add $s0, $s0, $t2 # $s0 = 4x^2 + 8y + z


(w)

# Compute 4x^2
# Store w in $s0 (already done)
mul $s0, $t0, $t0 # $s0 = x * x

li $t3, 4
# Exit the program
mul $s0, $s0, $t3 # $s0 = 4 * x^2
li $v0, 10 # syscall code for exit

syscall

You might also like