Answer to Question #281376 in Assembler for Mengal

Question #281376

Write an Assembly language-based program for MIPS Architecture-based MARS simulator to take input from users and compare two float numbers. If number one is greater than number two multiply both, and if number one is lesser than number 2; add both numbers.

1
Expert's answer
2021-12-20T14:49:30-0500
#1. read double n1 n2
#2. mult/add
# MIPS assembly
#************************************************
.data
 
msgEnd:     .asciiz "\n...Finish"
msgEnterN:     .asciiz "Enter N"
msgAnswer:    .asciiz "\nResult: "

# code segment
    .text
    .globl  main
main:   

    li $v0,4            # print string
    la $a0,msgEnterN    # "Enter N"
    syscall                # make the syscall print string
    
    li $v0,11            # print char
    li $a0,'1'              # 1
    syscall        
    
    li $v0,11            # print char
    li $a0,' '              # space
    syscall            

#reads and store the n1
    li  $v0, 6            # read  n1 to $f0
    syscall                # make the syscall    read
    mov.s $f12, $f0

    li $v0,4            # print string
    la $a0,msgEnterN    # "Enter N"
    syscall                # make the syscall print string
    
    li $v0,11            # print char
    li $a0,'2'              # 2
    syscall        

    li $v0,11            # print char
    li $a0,' '              # space
    syscall    
    
#reads and store the n2
    li  $v0, 6            # read  n2 to $f0
    syscall                # make the syscall    read
    mov.s $f14, $f0
    

# compare:
    c.le.s $f12, $f14        # n1 compare with n2
    bc1f multiply            # n1>n2
    add.s $f12, $f12, $f14        # else add
    j answer
multiply:
    mul.s $f12, $f12, $f14
    
answer:
    li $v0,4            # print string
    la $a0,msgAnswer    # "Result: "
    syscall                # make the syscall print string
    
    li    $v0,2            # Print  
    syscall                # make the syscall print      

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