[20 points] Write and debug a MIPS program that performs the following operation
ID: 3858092 • Letter: #
Question
[20 points] Write and debug a MIPS program that performs the following operations:
• Prompt for and input two integers “a” and “b” using syscalls
• Display one of the following statements depending on if a>b, or a=b or a<b:
- You entered a greater than b
- You entered a equal to b
- You entered a less than b
• Compute
1. 7*a+b
2. a-6*b+1
3. (a-8)*(b+5)
and display the result of each computation. Be careful with operator precedence, especially in the
second part.
• Return to the operating system.
Your run’s output must look exactly in format like the sample below. (If only close, but not exact, will
result in lost points.). Note that only the output result will vary depending on the input numbers. Adjust
your code until your output exactly matches (including horizontal and vertical spacing). You can use "
to put a double quote inside a text string. The values shown in bold here (not in your console window)
are user inputs for this run.
What is integer "a"? 3
What is integer "b"? 4
You entered a less than b
7*a+b is 25
a-6*b+1 is -20
(a-8)*(b+5) is -45
2. [EXTRA CREDIT – 5 points]
Implement a program which divides a user input by 8 using only bit shift. Your program should include
a proper and useful prompt for input, and print the results in a meaningful manner, similar to above.
Submission (15 points):
Submit the following to D2L before the deadline:
a. Assembly Source code. (filename format: firstnameLastname_X.s), where X is the problem number above
a. PDF document containing screen shots of output of your program with three different data inputs pasted in a word
file. (filename format: firstnameLastname_X.pdf), where X is the problem number above
Formatting Information (See the code in practice lab 01 as an example)
Read the following information/instructions before you start.
Comment your code – explain the logic of your code. Initial comments in your code must include:
• # Your name
• # IT 320 Assignment 2
• # I certify that this program is entirely my own creation.
• # I have not shared this code with any other person.
• You will need to use .text and .data directives to define program and data areas in SPIM.
• A colon (:) must follow all labels. Note that labels allow easy reference to a specific address/place in the program or
an argument that is required.
• Each data entry must be uniquely labeled to avoid any potential error.
• The word "main:" must label the first line in a SPIM program and always be made global.
• You may write only one instruction to a line (once past the instruction, you may add a comment, simply preceding with
a # sign).
• Read the resources posted on D2L for a full list of directives and instruction set.
• All characters in a string are represented in ASCII code.
• Use comments (#) to adequately write the logic of the program. Note comments do not wrap. If a comment takes
more than one line, start a new line with # and continue your comment.
• A "syscall 10" to return control to OS. For example,
li $v0, 10
syscall
• For better readability well format your code:
o use distinct columns for labels, opcode, operands and comments (see the format in the example below).
• Always read the assignment specification, where most hints to write the code is provided.
IMPORTANT – Certification required for all programming assignment submissions
Your program must be written exclusively by you. It is acceptable to discuss logic and other strategies such as the
number of variables, number of functions, et cetera, but it is NOT acceptable to show another class member even a single
line of code. Obviously, using code that I provide is acceptable. The program must contain the following comment lines
immediately after the comment(s) containing your name:
# I certify that this program is entirely my own creation (except for portions provided
# to me by the professor).
# I have not shared this code with any other person.
Protect your code. If another student obtains a copy of your program even though you are unaware of the infraction, you
are still guilty of collusion. Do not leave an ACC workstation unattended, even for a little while. Other students monitor
your patterns and, while you are out for even a few seconds, may walk up to your workstation and email a copy of your
program to themselves! You should also be careful where you leave paper copies of your program. A trash receptacle
anywhere near the ACC is likely to be rummaged. You should also protect your work in situations where you are living
with someone else taking the class or a friend of someone who is taking the class.
IT320 Assembly Example Code
# Your Name
# This is an example program to test SPIM
# IT 320 Practice Lab 1
.data
# Note space at end of each string! Spacing on screen is better this way.
p1:
.asciiz "What is the first integer? "
p2:
.asciiz "What is the second integer? "
ans1:
.asciiz " The sum of your numbers is "
ans2:
.asciiz " The diference of your numbers is "
.text
.globl main # must be global
main:
li $v0, 4 # system call code for print_str
la $a0, p1 # address of string to print
syscall # print the first prompt
li $v0, 5 # system call code for read_int
syscall # read the first integer
move $t1, $v0 # and store it 'till later
li $v0, 4 # system call code for print_str
la $a0, p2 # address of string to print
syscall # print the second prompt
li $v0, 5 # system call code for read_int
syscall # read the second integer
move $t2, $v0 # and store it 'till later
add $t0, $t1, $t2 # add the two integers
sub $t3, $t1, $t2 # subtract the two integers
li $v0, 4 # system call code for print_str
la $a0, ans1 # address of string to print
syscall # print the answer identifying string
li $v0, 1 # system call code for print_int
move $a0, $t0 # integer to print (sum)
syscall # print it
li $v0, 4 # system call code for print_str
la $a0, ans2 # address of string to print
syscall # print the answer identifying string
li $v0, 1 # system call code for print_int
move $a0, $t3 # integer to print (difference)
syscall # print it
jr $ra # return to system
Explanation / Answer
lb $t0 a
lb $t1 b
bgt $t0 $t1
la $a0 "A is greater then B"
syscall
blt $t0 $t1
la $a0 "A is less than B"
syscall
la $a0 "A is equal to B"
syscall
li $t6 7
mult $t7 $t6 $t0
add $t7 $t1
la $a0 $t7
syscall
li $t8 -6
mult $t9 $t8 $t1
la $a0 $t9
syscall
li $t3 -8
li $t 4 5
add $t3 $t0
add $t4 $t1
mult $t5 $t3 $t4
la $a0 $t5
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.