Assembly Language Programming Due Description This project w

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.

Solution

Solution:

As explicitly specified that only section 3rd answer is on the interest to know. I shall direct to section 3 and provide the necessary steps to obtain an answer. However, i would also keep you aware about section 2 logic if you are not thoroughly knowing the method to get the operation worked.

Section 2

Using an XOR gate the even and odd condiotion is verified.

Step 1: The input is made XOR with 2

Step 2: And the reslutant is right shifted to 1 bit, which provides the LSB.

Step 3: LSB(Least Significaant Bit) is compared with 0 to satisfy even and odd conditio,

Step 4: If the digit is 0, it proves that it is an even integer else odd integer.

Hope, this information is useful to you get assembly code written for section 2.

Section 3

It almost invoke the section 2 code but to enclosed within a loop. Here i shall provide a information to establish the loop within the section 2 Logic. Below is the generral structure

Structure\"

load n to temporary register 1

load 1 to temporary register 2

start : bge $to, $t1, exit [ if n > 1 continue, else goto exit]

Even /Odd operation as same as section 2

Decrement the N by value of 1

J start {Jump to start label)

exit : J $ra ( Jumps to exit if the loop is failed and retrieves the return address value to ra register)

Assembly Language Programming. Due: Description: This project will be done in parts that will increase in complexity. Each portion is to be submitted online sep
Assembly Language Programming. Due: Description: This project will be done in parts that will increase in complexity. Each portion is to be submitted online sep

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site