Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Joe is running a take-out pizza shop that sells 8\" pizzas and is wondering how

ID: 3599662 • Letter: J

Question

Joe is running a take-out pizza shop that sells 8" pizzas and is wondering how many square feet of pizza he sells every day. Write a MIPS assembly language program to help him to do the calculation. The program:

1. prompts Joe for the number of pizza sold in a day.

2. calculates the total pizza sold in square feet, assuming that every pizza is a circle and the radius of the circle is 8 inches.

3. prints out a message and the total number of square feet of pizza sold.

Note: single precision floating point operations must be used.

Do not use li.s as it does not work in Mars MIPS assembly.

Explanation / Answer

Given below is the MIPS code for the question. In case of any issues, post a comment. I will help. If the answer helped, please do rate it. Thank you.


.data
pi: .float 3.14159
radius: .float 8.0 #8 inches radius
sqft: .float 144.0 # 1 sqft = 144 sq inches
prompt: .asciiz "How many pizzas ? "
msg: .asciiz "Total square feet of pizza sold is "
n: .word 0 #The number of pizzas
.text
#prompt the user
li $v0, 4
la $a0, prompt
syscall
#get int input and store in n
li $v0 , 5
syscall
sw $v0, n
#calcualte the area of 1 pizza
l.s $f1, pi # f1 = pi
l.s $f2, radius #f2 = radius
#calculate area as pi * radius * radius and store in $f3
mul.s $f3, $f1, $f2 # f3 = pi * radius
mul.s $f3, $f3, $f2 # f3 = f3 * radius
#now f3 has area of 1 pizza of radius 8"
#get the value of n into f4 and mulitply n * area of 1 pizza to get area for all pizzas
lwc1 $f4, n #n is an word and being loaded into float register, so we have to convert the word to float
cvt.s.w $f4, $f4 #convert the word stored in f4 to single preceision floating point number and store back in f4
mul.s $f3, $f3, $f4 #now area of n pizzas is in f3
#get the value of 1 sqft i..e 144 sq inches inot f4
l.s $f4, sqft
div.s $f3, $f3, $f4 #divide total area by 144 to get area in sq ft
#display the result
li $v0, 4
la $a0, msg
syscall
#show the area
li $v0, 2
mov.s $f12, $f3
syscall
#exit
li $v0, 10
syscall

output

How many pizzas ? 5
Total square feet of pizza sold is 6.9813113

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote