Take 4 values in floating-point double precision and compare which one is smaller and display the output using MIPS.
#1. read double n1 n2 n3 n4
#2. smaller
# MIPS assembly
#************************************************
.data
msgEnd: .asciiz "\n...Finish"
msgEnterN: .asciiz "Enter N"
msgAnswer: .asciiz "\nSmaller: "
# 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, 7 # read n1 to $f0
syscall # make the syscall read
mov.d $f14, $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, 7 # read n2 to $f0
syscall # make the syscall read
mov.d $f16, $f0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'3' # 3
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n3
li $v0, 7 # read n3 to $f0
syscall # make the syscall read
mov.d $f18, $f0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'4' # 4
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n4
li $v0, 7 # read n4 to $f0
syscall # make the syscall read
mov.d $f20, $f0
# Smaller:
mov.d $f12, $f14 # $f12 = begining min
c.le.d $f12, $f16 # min compare with n2
bc1t next1 # min <= n2
mov.d $f12, $f16 # else $f12 = new min
next1:
c.le.d $f12, $f18 # min compare with n3
bc1t next2 # min <= n3
mov.d $f12, $f18 # else $f12 = new min
next2:
c.le.d $f12, $f20 # min compare with n4
bc1t smaller # min <= n4
mov.d $f12, $f20 # else $f12 = new min
smaller:
li $v0,4 # print string
la $a0,msgAnswer # "Smaller: "
syscall # make the syscall print string
li $v0,3 # 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
Comments
Leave a comment