Assembly Language Programming Spring 2016 Program #1 In this assignment, you wil
ID: 3684980 • Letter: A
Question
Assembly Language Programming Spring 2016 Program
#1 In this assignment, you will program a simple calculator for the Raspbian OS using ARM assembly. Your program, at a minimum, will consist of the following procedure calls:
SUM: Adds registers R1 and R2, returning result in register R0.
DIFFERENCE: Subtracts register R2 from R1, returning result in register R0.
PRODUCT: Multiplies registers R1 and R2, returning the result in register R0.
MAX: Compares registers R1 and R2, returning the maximum of the two values in R0.
Your main function will contain a loop that continuously checks for keyboard input in the following pattern:
<OPERAND_1><ENTER> <OPERATION_CODE><ENTER> <OPERAND_2><ENTER> Where
<OPERATION_CODE> can be any of the four characters {+,-,*,M}. Once the 3 lines of input are acquired, the operands should be loaded into the proper registers and the procedure corresponding to <OPERATION_CODE> should be called. The procedure should return the result in register R0, and the main function should print the value to the console and skip to a new line. You may ignore overflows, underflows, and improperly formatted input. All in test cases will consist of positive numbers only.
Below are some example use cases:
5
+
15
20 <- result
100.
M
200
200
5
*
20
100
50
-
20
30
1. Main function correctly retrieves 3 input parameters, prints result in a continuous loop (20 points)
2. SUM, DIFFERENCE, PRODUCT, MAX procedures implemented (10 points each)
3. SUM, DIFFERENCE, PRODUCT, MAX procedures return correct values on all test cases (10 points each).
Submit your solution as a single “.s” file to Blackboard. Name the file “p1_XXXYYYY.s”, where XXXYYYY is your UTA NetID.
*** Be sure to check http://github.com/cmcmurrough/teaching/assembly for useful code snippets ***
Explanation / Answer
//Procedures like Sum and Subtraction and Division , Multiplication of Register Values
.text
.globl __start
__start: li $v0, 4
la $a0, First
syscall # Ask for the first integer
li $v0, 5
syscall # Read an integer
add $R1, $0, $v0 # and store it in $R1
li $v1, 5
syscall # Read an integer
add $R2, $0, $v1 # and store it in $R2
#loop: beq $R1, $R2, exit # if the numbers are equal then exit
# sub $R1, $R2, $R0
# b loop # then continue
# sum $R1, $R2, $R0
# sub $R1, $R2, $R0
# mul $R1, $R2, $R0
# div $R1, $R2, $R0
# b loop
sum:
add $R0 $R1 $R2
end sum;
sub:
sub $R0 $R1 $R2
end sub;
mul:
mul $R0 $R1 $R2
end mul;
div:
div $R0 $R1 $R2
end div;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.