Problem:
Write an assembly language program which takes two integers, A and B, and computes the following expressions. You must use the same variables for A and B throughout all three expressions (you can hard code once at the beginning). The result of each problem should be printed to the terminal.
1) A * 5
2) (A + B) – (A / B)
3) (A – B) + (A * B)
CS330 – Computer Organization & Assembly Language
Assignment # 6
***Individual Work Only***
Problem:
Write an assembly language program which takes two integers, A and B, and
computes the following expressions. You must use the same variables for A and
B throughout all three expressions (you can hard code once at the beginning).
The result of each problem should be printed to the terminal.
1) A * 5
2) (A + B) – (A / B)
3) (A – B) + (A * B)
TURN IN: Please the following three items inside a .zip file and submit the .zip file
•
•
•
asgn7.s (includes all the code)
Makefile
Independent completion form
RUBRIC:
•
•
•
•
45%: 15% per working problem. (Each missing problem is minus 33%)
15%: 5% per result of problem printed.
10%: Use the same A and B variables for all expressions.
30%: Document all code.
o Comments must be thorough and correct but not redundant.
o Explain both what you’re doing and why you’re doing it.
•
•
•
•
10% bonus: Take user input for A and B. Must meet all the criteria above to be
eligible for this bonus.
10% bonus: Create all three functions as functions. Be sure to handle callersaved and callee-saved register saving appropriately. Must meet all the criteria
above to be eligible for this bonus.
Code that does not compile using the Makefile on Vulcan will result in an
automatic zero.
NOTE: Writing C code and converting it into Assembly and submitting the
compiler generated Assembly is STRICTLY PROHIBITED.
MIPS assembly language code for taking input of A and B and then storing the result
after performing the operations.
Taking input of A:
daddiu $2,$fp,4
move $5,$2
ld $4,%got_disp(_ZSt3cin)($28)
ld $2,%call16(_ZNSirsERi)($28)
move $25,$2
nop
Taking input of B:
daddiu $2,$fp,8
move $5,$2
ld $4,%got_disp(_ZSt3cin)($28)
ld $2,%call16(_ZNSirsERi)($28)
move $25,$2
nop
Performing first operation i.e A*5:
lw $2,4($fp)
move $3,$2
move $2,$3
sll $2,$2,2
addu $2,$2,$3
sw $2,0($fp)
Performing second operation i.e (A+B)-(A/B):
lw $3,12($fp)
lw $2,16($fp)
addu $2,$3,$2
move $3,$2
lw $4,12($fp)
lw $2,16($fp)
div $0,$4,$2
teq $2,$0,7
mfhi $2
mflo $2
subu $2,$3,$2
sw $2,4($fp)
Performing next opeartion i.e(A-B)+(A*B):
lw $3,12($fp)
lw $2,16($fp)
subu $2,$3,$2
move $3,$2
lw $4,12($fp)
lw $2,16($fp)
mult $4,$2
mflo $2
addu $2,$3,$2
sw $2,8($fp)