Answer to Question #281371 in Assembler for Mengal

Question #281371

Take 4 numbers as an input from the user and perform the multiplication and then addition among the numbers using MIPS.

1
Expert's answer
2021-12-20T10:02:12-0500

#1. read n1 n2 n3 n4

#2. mult

#3. add

# MIPS assembly

#************************************************

.data


msgEnd:   .asciiz "\n...Finish"

msgEnterN:   .asciiz "Enter N"


msgAnswer1:   .asciiz "\nMultiply: "

msgAnswer2:   .asciiz "\nAdd: "


# 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, 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


   mul $t0, $t1, $t2

   mul $t0, $t0, $t3

   mul $t0, $t0, $t4   # n1*n2*n3*n4


   li $v0,4         # print string

   la $a0,msgAnswer1   # "Multiply: "

   syscall            # make the syscall print string


   add $a0, $0, $t0   # $a0 = n1*n2*n3*n4

   li   $v0, 1         # Print Integer

   syscall            # make the syscall print int   


   add $t0, $t1, $t2

   add $t0, $t0, $t3

   add $t0, $t0, $t4   # n1+n2+n3+*n4


   li $v0,4         # print string

   la $a0,msgAnswer2   # "Add: "

   syscall            # make the syscall print string


   add $a0, $0, $t0   # $a0 = n1+n2+n3+n4

   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