The program you will develop needs to accept input from a source, run the input through several comparisons, and then calculate an output. You will use variables, assignments, if-else functions, and arrays.
In this scenario, you need to create a program that will take a user's age and determine a ticket price based on their age.
has to be done in .asm // mips assembly code
# MIPS assembly
#************************************************
.data
msgEnd: .asciiz "\n...Finish"
msgEnterAge: .asciiz "Enter age: "
price: .word 10
float100: .float 100.0
# code segment
.text
.globl main
main:
li $v0,4 # print string
la $a0,msgEnterAge # "Enter age"
syscall # make the syscall print string
#reads and store AGE
li $v0, 5 # read int AGE to $v0
syscall # make the syscall read integer
move $t1, $v0
blt $t1, 18, age18
bgt $t1, 65, age65
la $s0,price
lw $t0, 0($s0)
j ticketPrice
age18:
la $s0,price
lw $t0, 0($s0)
sub $t0, $t0, 1
j ticketPrice
age65:
la $s0,price
lw $t0, 0($s0)
mul $t0, $t0, 85
mtc1 $t0, $f0 # copy $t0 to $f0
cvt.s.w $f2, $f0 # convert int $f0 to float $f2
lwc1 $f0, float100
div.s $f12, $f2, $f0
li $v0,2 # Print float
syscall # make the syscall print
j finish
ticketPrice:
add $a0, $0, $t0 # $a0 = price
li $v0, 1 # Print Integer
syscall # make the syscall print int
finish:
li $v0,4 # print string
la $a0,msgEnd # "Finish"
syscall # make the syscall
li $v0, 10 # finished .. stop .. return
syscall
Comments
Leave a comment