Assembly Language Programming. Due: Description: This project will be done in pa
ID: 3795385 • Letter: A
Question
Assembly Language Programming.
Due: Description:
This project will be done in parts that will increase in complexity. Each portion is to be submitted online separately. In the assembly file for each section you must place a pair of comments identifying yourself and the section that you are working on.
# Name: Jerry Heuring # Project 1: Section 1
Details:
Section 1:
Using the MARS or SPIM simulator develop a program that will evaluate the following expression:
3 * n + n * (n – 1) – 15
where n is stored in a data location and is set to 15. Your program should use the system calls to print the result and to exit the program.
Section 2:
Using the MARS or SPIM simulator develop a program that will implement the following conditional statement.
If ( n is even) { n = n / 2;
} else {
n = 3 * n + 1;
}
In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the program. Hint: There is a remainder pseudoinstruction for the MIPS architecture that you can use to determine if the value is even or odd or you can look at bit 0 to determine if the value is even or odd.
Section 3:
You are to take the conditional from the previous section and build a loop around it to find the Collatz sequence. The structure of this would be:
while (n > 1) {
If (n is even) {
n = n / 2;
} else {
n = 3 * n + 1;
}
cout << n;
}
Section 4:
You are to write a leaf subprogram that will output the following information: Your Name
Your favorite sports team
The main program should call your leaf routine and then exit using the system call.
Section 5:
Write a program with a leaf subprogram that will take two values in $a0 and $a1 and compute their greatest common divisor. The greatest common divisor should be returned in the $v0 register. The main program should input the values for $a0 and $a1 using system calls, call your subprogram, and then output the result using a system call.
Submission:
There are locations for you to submit the assignment available in BlackBoard. You need to upload only the .asm (assembly language) file. There is a different location for EACH section.
Explanation / Answer
.data
string1: .asciiz "Enter the first number: "
string2: .asciiz "Enter the second number: "
string3: .asciiz "GCD is : "
.text
#display string1
li $v0,4
la $a0,string1
syscall
#get first number
li $v0, 5
syscall
add $s0,$v0,$zero #s0 = first number
#display string2
li $v0,4
la $a0,string2
syscall
#get second number
li $v0, 5
syscall
add $s1,$v0,$zero #s1= second number
slt $t0,$s0,$s1
beq $t0,$zero,L # if first number < second number , swap or Jump directll to L
add $t1,$s0,$zero
add $s0,$s1,$zero
add $s1,$t1,$zero
L:
add $a0,$s0,$zero # put first number in $a0 as input argument
add $a1,$s1,$zero # put second number in $a1 as input argument
jal GCD
move $s3,$v0 #move gcd in $v0 to $s3
#display string3
li $v0,4
la $a0,string3
syscall
#display gcd
li $v0,1
add $a0,$s3,$zero
syscall
#end program
li $v0,10
syscall
GCD:
# a0 and a1 are the two integer parameters
# return value is in v0
move $t0, $a0
move $t1, $a1
loop:
beq $t1, $0, done
div $t0, $t1
move $t0, $t1
mfhi $t1
j loop
done:
move $v0, $t0
jr $ra
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.