A quantity surveyor has requested you to design an application using a flowchart to estimate the amount of paint required to paint a cylindrical water storage tank. The tank will be painted on the interior surface only. Each square meter of the surface will need 1 liter of paint that costs KES 500. The labor cost for painting the tank is 1000 KES. The program should prompt user to enter radius and height of the tank in meters then pass these values to a procedure which calculate and display the surface area of the tank, amount of paint needed and total cost of the painting the tank. In this regard you are required to:
1.Draw a flowchart to represent this system (12 Marks)
2.Write an assembly program to implement the design in a) above. (8 Marks)
# Description:
# Write a MIPS program in MARS
##########################################################################
.data
EnterPromptR: .asciiz "Please enter a floating R = "
EnterPromptH: .asciiz "Please enter a floating H = "
InvalidPrompt: .asciiz "\nInvalid number, re-enter "
surfacArea: .asciiz "\nSurface area "
amountPaint: .asciiz "\nAmount of Paint "
totalCost: .asciiz "\nTotal Cost "
KES: .asciiz " KES"
piFloat: .float 3.1415
zeroFloat: .float 0.0
twoFloat: .float 2.0
liter: .float 500
cost: .float 1000
# code segment
.text
.globl main
main:
lwc1 $f1, piFloat # $f1 = 3.1415
lwc1 $f2, zeroFloat
lwc1 $f3, twoFloat
getR:
li $v0,4 # print string
la $a0,EnterPromptR # Please enter a floating R =
syscall
li $v0,6 # read float ($f0 = readed value)
syscall
mov.s $f4,$f0 # save R from $F0 to $F4
# branch if R < 0, then jump to repGetR
c.lt.s $f0, $f2
bc1t repGetR
j getH
repGetR:
li $v0,4 # print string
la $a0,InvalidPrompt #"\nInvalid number, re-enter"
syscall
j getR
getH:
li $v0,4 # print string
la $a0,EnterPromptH # Please enter a floating H =
syscall
li $v0,6 # read float ($f0 = readed value)
syscall
mov.s $f5,$f0 # save H from $F0 to $F5
# branch if H < 0, then jump to repGetH
c.lt.s $f0, $f2
bc1t repGetH
j calc
repGetH:
li $v0,4 # print string
la $a0,InvalidPrompt #"\nInvalid number, re-enter"
syscall
j getH
# Calculate the total surface area of a cylinder 2*pi*r(h+r)
calc:
add.s $f6, $f4, $f5 # (h+r)
mul.s $f6,$f4,$f6 # $F6 = r(h+r)
mul.s $f6,$f6,$f1 # $F6 = pi*r(h+r)
mul.s $f6,$f6,$f3 # $F6 = 2*pi*r(h+r)
li $v0,4 # print string
la $a0,surfacArea # surface Area
syscall
li $v0,2 # print
mov.s $f12,$f6 # surface Area
syscall
# amount of paint
lwc1 $f2, liter
mul.s $f6,$f6,$f2
li $v0,4 # print string
la $a0,amountPaint # Amount Paint
syscall
li $v0,2 # print
mov.s $f12,$f6 # amountPaint
syscall
li $v0,4
la $a0,KES
syscall
# total cost of the painting the tank
lwc1 $f2, cost
add.s $f6, $f6, $f2
li $v0,4 # print string
la $a0,totalCost # totalCost
syscall
li $v0,2 # print
mov.s $f12,$f6 # totalCost
syscall
li $v0,4
la $a0,KES
syscall
li $v0, 10 # finished .. stop .. return
syscall # make the syscall
Comments
Leave a comment