Ask the name and roll number of user and then take two float values from user and perform all arithmetic opertaions on them and print the answers.
#1. read float n1 n2
#2. add, sub, mult, div
# MIPS assembly
#************************************************
.data
zeroFloat: .float 0.0
name: .space 24
roolNum: .space 12
msgEnterName: .asciiz "Enter Name: "
msgEnterRoolNum: .asciiz "Enter Rool Number: "
msgEnterN: .asciiz "\nEnter N"
msgAnswerSum: .asciiz "\nAdd: "
msgAnswerSub: .asciiz "\nSub: "
msgAnswerMul: .asciiz "\nMul: "
msgAnswerDiv: .asciiz "\nDiv: "
msgEnd: .asciiz "\n...Finish"
# code segment
.text
.globl main
main:
li $v0,4 # print string
la $a0,msgEnterName # "Enter Name: "
syscall # make the syscall print string
li $v0,8 # read string
la $a0,name
li $a1,24
syscall
li $v0,4 # print string
la $a0,msgEnterRoolNum # "Enter Rool Number: "
syscall # make the syscall print string
li $v0,8 # read string
la $a0,roolNum
li $a1,12
syscall
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 # n1 store to $f12
mov.s $f16, $f0 # n1 store to $f16
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 # n1 store to $f14
#add:
li $v0,4 # print string
la $a0,msgAnswerSum # "\nAdd: "
syscall # make the syscall print string
add.s $f12, $f12, $f14 # add
li $v0,2 # Print
syscall # make the syscall print
#sub
li $v0,4 # print string
la $a0,msgAnswerSub # "\nSub: "
syscall # make the syscall print string
mov.s $f12, $f16 # restore n1 from $f16
sub.s $f12, $f12, $f14
li $v0,2 # Print float
syscall # make the syscall print
#multiply
li $v0,4 # print string
la $a0,msgAnswerMul # "\nMul: "
syscall # make the syscall print string
mov.s $f12, $f16 # restore n1 from $f16
mul.s $f12, $f12, $f14
li $v0,2 # Print float
syscall # make the syscall print
#div
lwc1 $f10,zeroFloat
c.eq.s $f10, $f14 # n2 compare with 0.0
bc1t finish # if n2==zero goto finish
li $v0,4 # print string
la $a0,msgAnswerDiv # "\nDiv: "
syscall # make the syscall print string
mov.s $f12, $f16 # restore n1 from $f16
div.s $f12, $f12, $f14
li $v0,2 # Print float
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