86.0k views
1 vote
Write an Assembly program in MIPS that does the following:

- Ask to enter two integers
- Ask to choose which of the 4 operations user wants to perform.

The operations are listed as follows:

Addition
Subtraction
Multiplication
Division

- Perform the operation and display the result to the user
- Ask if the user wants to continue (C) or quit (Q). If the user chooses continue (C), steps should start over. Otherwise (Q) program ends.

Submit a screenshot of execution of your program for each operation. Also include your program source code together with a comment section in the beginning of your program that has your name, as well as a description about how to run your program.

2 Answers

3 votes

Answer: Multiplication

Step-by-step explanation:

User Thromordyn
by
4.6k points
5 votes

Answer:

see explaination

Step-by-step explanation:

#DATA SECTION

.data

#Decalre x

x: .word 0

#declare y

y: .word 0

#Declare variables

choice: .space 1

#Store the repeat choice

op: .asciiz "C"

#Prompt

prompt1: .asciiz "\\Enter 2 integers:\\"

#Declare string for menu

menu: .asciiz "\\Menu \\ 1. Addition\\ 2. Subtraction \\ 3. Multiplication \\ 4. Division \\Enter your choice:"

#Declare string for repeat

repeat: .asciiz "\\Do u want to continue (C) or quit(Q):"

#Declare string for result

result: .asciiz "Result="

#Code section

.text

#main

main:

#label

continue:

#Load code to print string

li $v0, 4

#Load the base address of prompt1

la $a0, prompt1

#Print string

syscall

#Load code to read integer

li $v0, 5

#Read integer

syscall

#Store integer in x

sw $v0, x

#load code to read integer

li $v0, 5

#read integer

syscall

#Store in y

sw $v0, y

#Load code to print string menu

li $v0, 4

#Load address of menu

la $a0, menu

#Print string

syscall

#Load code to read integer

li $v0, 5

#Read integer

syscall

#Store the operation choice in $a1

move $a1, $v0

#Check user wishes to add

beq $a1, 1, addition

#Check user wishes to do subtraction

beq $a1, 2, subtraction

#Check user wishes to do multiplication

beq $a1, 3, multiplication

#Check user wishes to do division

beq $a1, 4, division

#Ask user for repetition

GetChoice:

#Load code to print string "repeat"

li $v0, 4

#Load address of repeat

la $a0, repeat

#Print string

syscall

#Load code to read character

li $v0, 12

#Read character

syscall

#Store character in choice

sb $v0, choice

#Load user choice

lb $t2, choice

#Load repeat option

lb $t3, op

#Check both

#If user wishes to continue, then go to continue

beq $t2, $t3, continue

#Else stop the program

j programEnd

#For addition

addition:

#load x

lw $t4, x

#load y

lw $t5, y

#Add

add $t6, $t4, $t5

#Load code to print result

li $v0, 4

#load result address

la $a0, result

#Print result

syscall

#load code to print integer

li $v0, 1

#load the value

move $a0, $t6

#print the integer

syscall

#Jump to get choice

j GetChoice

#For subtraction

subtraction:

#load x

lw $t4, x

#load y

lw $t5, y

#Add

sub $t6, $t4, $t5

#Load code to print result

li $v0, 4

#load result address

la $a0, result

#Print result

syscall

#load code to print integer

li $v0, 1

#load the value

move $a0, $t6

#print the integer

syscall

#Jump to get choice

j GetChoice

#For multiplication

multiplication:

#load x

lw $t4, x

#load y

lw $t5, y

#Add

mul $t6, $t4, $t5

#Load code to print result

li $v0, 4

#load result address

la $a0, result

#Print result

syscall

#load code to print integer

li $v0, 1

#load the value

move $a0, $t6

#print the integer

syscall

#Jump to get choice

j GetChoice

#Division

division:

#load x

lw $t4, x

#load y

lw $t5, y

#Add

div $t6, $t4, $t5

#Load code to print result

li $v0, 4

#load result address

la $a0, result

#Print result

syscall

#load code to print integer

li $v0, 1

#load the value

move $a0, $t6

#print the integer

syscall

#Jump to get choice

j GetChoice

#end

programEnd:

#loa dcode to stop the program

li $v0, 10

syscall

User Fmassica
by
5.0k points