Write a MIPS assembly language program that reads how many T-shirts a customer w
ID: 3742769 • Letter: W
Question
Write a MIPS assembly language program that reads how many T-shirts a customer wants to purchase.
If a customer enters 0 or a negative integer,
then the program should print out "Please enter a positive integer. ", and exit.
Otherwise, if a customer orders less than 10 T-shirts, then since each T-shirt costs 9 dollars, the payment will be 9 x the number of T-shirts.
If a customer orders 10 or more T-shirts, and less then 20, then the customer will get a discount of 9 dollars, thus the payment will be (9 x the number of T-shirts) - 9.
If a customer orders 20 or more T-shirts, then the customer will get a discount of 18 dollars, thus the payment will be (9 x the number of T-shirts) - 18.
In addition, if a customer has a coupon, then there will be an additional discount of 5 dollars.
After computing its payment including its discounts, it should print out the payment amount, along with the number of T-shirts.
Here is a sample output (user input is in bold):
Welcome to our T-shirt shop!
How many T-shirts would you like to purchase?
19
Do you have a coupon? Enter 1 for Yes, 0 for No:
1
Your total payment for this purchase: 157 dollar(s) for 19 T-shirt(s)
-----------------------------------------------
Here is another sample output (user input is in bold):
Welcome to our T-shirt shop!
How many T-shirts would you like to purchase?
8
Do you have a coupon? Enter 1 for Yes, 0 for No:
0
Your total payment for this purchase: 72 dollar(s) for 8 T-shirt(s)
-----------------------------------------------
Here is another sample output (user input is in bold):
Welcome to our T-shirt shop!
How many T-shirts would you like to purchase?
-1
Please enter a positive integer.
-----------------------------------------------
Explanation / Answer
SOLUTION :
$LC0:
.ascii "Enter number of T-shirts: "
$LC1:
.ascii "%d"
$LC2:
.ascii "Please enter a positive integer."
$LC3:
.ascii "Do you have a coupan(y/n):"
$LC4:
.ascii " %c"
$LC5:
.ascii "Amount to be paid for %d t-shirts: %d"
main:
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
move $fp,$sp
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
jal printf
nop
addiu $2,$fp,28
move $5,$2
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
jal scanf
nop
lw $2,28($fp)
nop
beq $2,$0,$L2
nop
lw $2,28($fp)
nop
bgez $2,$L3
nop
$L2:
lui $2,%hi($LC2)
addiu $4,$2,%lo($LC2)
jal puts
nop
move $4,$0
jal exit
nop
$L3:
lw $2,28($fp)
nop
slt $2,$2,10
beq $2,$0,$L4
nop
lw $3,28($fp)
nop
move $2,$3
sll $2,$2,3
addu $2,$2,$3
sw $2,24($fp)
b $L5
nop
$L4:
lw $2,28($fp)
nop
slt $2,$2,20
beq $2,$0,$L6
nop
lw $2,28($fp)
nop
addiu $3,$2,-1
move $2,$3
sll $2,$2,3
addu $2,$2,$3
sw $2,24($fp)
b $L5
nop
$L6:
lw $3,28($fp)
nop
move $2,$3
sll $2,$2,3
addu $2,$2,$3
addiu $2,$2,-18
sw $2,24($fp)
$L5:
lui $2,%hi($LC3)
addiu $4,$2,%lo($LC3)
jal printf
nop
addiu $2,$fp,32
move $5,$2
lui $2,%hi($LC4)
addiu $4,$2,%lo($LC4)
jal scanf
nop
lb $3,32($fp)
li $2,121 # 0x79
bne $3,$2,$L7
nop
lw $2,24($fp)
nop
addiu $2,$2,-5
sw $2,24($fp)
$L7:
lw $2,28($fp)
lw $6,24($fp)
move $5,$2
lui $2,%hi($LC5)
addiu $4,$2,%lo($LC5)
jal printf
nop
move $2,$0
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
j $31
nop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.