Iqra University Computer Organization and Assembly Language Assignment 1.
Write an Assembly language-based program for MIPS Architecture based MARS simulator to take input from user 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 and subtract both numbers.
# take 4 numbers input
# then perform multiplication
# and addition
# between each other
.data
msgEnterN: .asciiz "Enter N"
msgAnswer1: .asciiz "\nMultiply: "
msgAnswer2: .asciiz "\nAdd: "
msgAnswer3: .asciiz "\nAverage: "
.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, 5 # read int n1 to $v0
syscall # make the syscall read integer
move $t1, $v0
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, 5 # read int n2 to $v0
syscall # make the syscall read integer
move $t2, $v0
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, 5 # read int n3 to $v0
syscall # make the syscall read integer
move $t3, $v0
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, 5 # read int n4 to $v0
syscall # make the syscall read integer
move $t4, $v0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'5' # 5
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n5
li $v0, 5 # read int n5 to $v0
syscall # make the syscall read integer
move $t5, $v0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'6' # 6
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n6
li $v0, 5 # read int n6 to $v0
syscall # make the syscall read integer
move $t6, $v0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'7' # 7
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n7
li $v0, 5 # read int n7 to $v0
syscall # make the syscall read integer
move $t7, $v0
li $v0,4 # print string
la $a0,msgEnterN # "Enter N"
syscall # make the syscall print string
li $v0,11 # print char
li $a0,'8' # 8
syscall
li $v0,11 # print char
li $a0,' ' # space
syscall
#reads and store the n8
li $v0, 5 # read int n8 to $v0
syscall # make the syscall read integer
move $s0, $v0
# ------
mul $t0, $t1, $t2
mul $t0, $t0, $t3
mul $t0, $t0, $t4
mul $t0, $t0, $t5
mul $t0, $t0, $t6
mul $t0, $t0, $t7
mul $t0, $t0, $s0 # n1*n2*n3*n4*n5*n6*n7*n8
li $v0,4 # print string
la $a0,msgAnswer1 # "Multiply: "
syscall # make the syscall print string
add $a0, $0, $t0 # $a0 = n1*n2*n3*n4*n5*n6*n7*n8
li $v0, 1 # Print Integer
syscall # make the syscall print int
add $t0, $t1, $t2
add $t0, $t0, $t3
add $t0, $t0, $t4
add $t0, $t0, $t5
add $t0, $t0, $t6
add $t0, $t0, $t7
add $t0, $t0, $s0 # n1+n2+n3+n4+n5+n6+n7+n8
li $v0,4 # print string
la $a0,msgAnswer2 # "Add: "
syscall # make the syscall print string
add $a0, $0, $t0 # $a0 = n1+n2+n3+n4+n5+n6+n7+n8
li $v0, 1 # Print Integer
syscall # make the syscall print int
# for avergae
li $v0,4 # print string
la $a0,msgAnswer3
syscall
div $s1,$t0,8
li $v0,1
add $a0,$zero,$s1
syscall
# li $v0, 10 # finished .. stop .. return
# syscall
li $v0,10
syscall
No comments:
Post a Comment