Advertisement
Guest User

Untitled

a guest
May 16th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     a: .word 0
  3.     operation: .word 0
  4.     b: .word 0
  5.     result: .word 0
  6.     choice: .word 0
  7.    
  8.     newLine: .asciiz "\n"
  9.    
  10.     firstItemMessage: .asciiz "Put first item\n"
  11.     operationMessage: .asciiz "Put operation code\n"
  12.     secondItemMessage: .asciiz "Put second item\n"
  13.    
  14.     wrongOperationCode: .asciiz "Wrong operation code"
  15.    
  16.     operations: .asciiz "Operations:\n0 - addition\n1 - subtraction\n2 - division\n3 - multiplication\n"
  17.     resultMessage: .asciiz "Result: "
  18.    
  19.     choiceMessage: .asciiz "Do you want to invoke next operation? (0 - no, 1 - yes)\n"
  20. .text
  21.  
  22.     main:
  23.    
  24.     li $v0, 4
  25.     la $a0, firstItemMessage
  26.     syscall
  27.    
  28.     jal readInt
  29.     sw $v0, a
  30.    
  31.     li $v0, 4
  32.     la $a0, operations
  33.     syscall
  34.    
  35.     li $v0, 4
  36.     la $a0, newLine
  37.     syscall
  38.    
  39.     li $v0, 4
  40.     la $a0, operationMessage
  41.     syscall
  42.    
  43.     jal readInt
  44.     sw $v0, operation
  45.    
  46.     li $v0, 4
  47.     la $a0, secondItemMessage
  48.     syscall
  49.    
  50.     jal readInt
  51.     sw $v0, b
  52.  
  53.     lw $t0, operation
  54.  
  55.     beq $t0, 0, addition
  56.     beq $t0, 1, subtraction
  57.     beq $t0, 2, division
  58.     beq $t0, 3, multiplication
  59.    
  60.     li $v0, 4
  61.     la $a0, wrongOperationCode
  62.     syscall
  63.    
  64.     li $v0, 4
  65.     la $a0, newLine
  66.     syscall
  67.    
  68.     li $v0, 4
  69.     la $a0, newLine
  70.     syscall
  71.    
  72.     jal main
  73.    
  74.     endif:
  75.    
  76.     sw $t3, result
  77.    
  78.     li $v0, 4
  79.     la $a0, resultMessage
  80.     syscall
  81.    
  82.     li $v0, 1
  83.     lw $a0, result
  84.     syscall
  85.    
  86.     li $v0, 4
  87.     la $a0, newLine
  88.     syscall
  89.    
  90.     li $v0, 4
  91.     la $a0, choiceMessage
  92.     syscall
  93.    
  94.     jal readInt
  95.     sw $v0, choice
  96.    
  97.     lw $t0, choice
  98.    
  99.     li $v0, 4
  100.     la $a0, newLine
  101.     syscall
  102.    
  103.     beq $t0, 1, main
  104.    
  105.     end:
  106.     # end of program
  107.     li $v0, 10
  108.     syscall
  109.  
  110.     readInt:
  111.     li $v0, 5
  112.     syscall
  113.     jr $ra
  114.    
  115.     addition:
  116.     lw $t4, a
  117.     lw $t5, b
  118.    
  119.     add $t3, $t4, $t5
  120.    
  121.     j endif
  122.    
  123.     subtraction:
  124.     lw $t4, a
  125.     lw $t5, b
  126.    
  127.     sub $t3, $t4, $t5
  128.    
  129.     j endif
  130.    
  131.     division:
  132.     lw $t4, a
  133.     lw $t5, b
  134.    
  135.     div $t3, $t4, $t5
  136.    
  137.     j endif
  138.    
  139.     multiplication:
  140.     lw $t4, a
  141.     lw $t5, b
  142.    
  143.     mul $t3, $t4, $t5
  144.    
  145.     j endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement