Answer to Question #282225 in Assembler for Garcia

Question #282225

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.

  • The standard ticket price is $10.00.
  • Minors (those under the age of 18) will pay $1.00 less than the standard ticket price.
  • Seniors (those over the age of 65) will receive a 15% discount.

has to be done in .asm // mips assembly code


1
Expert's answer
2021-12-23T11:10:12-0500
# 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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS