Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- a: .word 0
- operation: .word 0
- b: .word 0
- result: .word 0
- choice: .word 0
- newLine: .asciiz "\n"
- firstItemMessage: .asciiz "Put first item\n"
- operationMessage: .asciiz "Put operation code\n"
- secondItemMessage: .asciiz "Put second item\n"
- wrongOperationCode: .asciiz "Wrong operation code"
- operations: .asciiz "Operations:\n0 - addition\n1 - subtraction\n2 - division\n3 - multiplication\n"
- resultMessage: .asciiz "Result: "
- choiceMessage: .asciiz "Do you want to invoke next operation? (0 - no, 1 - yes)\n"
- .text
- main:
- li $v0, 4
- la $a0, firstItemMessage
- syscall
- jal readInt
- sw $v0, a
- li $v0, 4
- la $a0, operations
- syscall
- li $v0, 4
- la $a0, newLine
- syscall
- li $v0, 4
- la $a0, operationMessage
- syscall
- jal readInt
- sw $v0, operation
- li $v0, 4
- la $a0, secondItemMessage
- syscall
- jal readInt
- sw $v0, b
- lw $t0, operation
- beq $t0, 0, addition
- beq $t0, 1, subtraction
- beq $t0, 2, division
- beq $t0, 3, multiplication
- li $v0, 4
- la $a0, wrongOperationCode
- syscall
- li $v0, 4
- la $a0, newLine
- syscall
- li $v0, 4
- la $a0, newLine
- syscall
- jal main
- endif:
- sw $t3, result
- li $v0, 4
- la $a0, resultMessage
- syscall
- li $v0, 1
- lw $a0, result
- syscall
- li $v0, 4
- la $a0, newLine
- syscall
- li $v0, 4
- la $a0, choiceMessage
- syscall
- jal readInt
- sw $v0, choice
- lw $t0, choice
- li $v0, 4
- la $a0, newLine
- syscall
- beq $t0, 1, main
- end:
- # end of program
- li $v0, 10
- syscall
- readInt:
- li $v0, 5
- syscall
- jr $ra
- addition:
- lw $t4, a
- lw $t5, b
- add $t3, $t4, $t5
- j endif
- subtraction:
- lw $t4, a
- lw $t5, b
- sub $t3, $t4, $t5
- j endif
- division:
- lw $t4, a
- lw $t5, b
- div $t3, $t4, $t5
- j endif
- multiplication:
- lw $t4, a
- lw $t5, b
- mul $t3, $t4, $t5
- j endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement