#MIPS
.text
.globl main
main:
li $v0,4 # load syscall write string into $v0
la $a0, EnterN1 # "Enter Number 1: "
syscall
li $v0,5 # load syscall read_int into $v0
syscall # read int number to $v0
add $t1, $0, $v0 # save n1 in $t1
li $v0,4
la $a0, EnterN2 # "Enter Number 2: "
syscall
li $v0,5
syscall # read int number to $v0
add $t2, $0, $v0 # save n2 in $t2
li $v0,4
la $a0, Addition # "Addition: "
syscall
add $a0,$zero,$t1 # n1
add $a0,$a0,$t2 # n1 + n2
li $v0, 1 # print integer sum
syscall # make the syscall
li $v0,4
la $a0, Subtruction # "Subtruction: "
syscall
add $a0,$zero,$t1 # n1
sub $a0,$a0,$t2 # n1 - n2
li $v0, 1 # print integer sub
syscall # make the syscall
li $v0,4 # load syscall write string into $v0
la $a0, NewLine
syscall
# is N1 Odd or Even
li $v0, 1
add $a0,$zero,$t1 # n1
syscall
andi $t0, $t1, 1
beq $t0, $0, _oddN1
li $v0,4
la $a0, EvenNumber # "Even"
syscall
j _testN2
_oddN1:
li $v0,4
la $a0, OddNumber # "Odd"
syscall
# is N2 Odd or Even
_testN2:
li $v0,4
la $a0, NewLine
syscall
li $v0, 1
add $a0,$zero,$t2 # n2
syscall
andi $t0, $t2, 1
beq $t0, $0, _oddN2
li $v0,4
la $a0, EvenNumber # "Even"
syscall
j _testCmp
_oddN2:
li $v0,4
la $a0, OddNumber # "Odd"
syscall
_testCmp:
li $v0,4 # load syscall write string into $v0
la $a0, NewLine
syscall
li $v0,4 # load syscall write string into $v0
la $a0, EnterN1 # "Enter Number 1: "
syscall
li $v0,5 # load syscall read_int into $v0
syscall # read int number to $v0
add $t1, $0, $v0
li $v0,4
la $a0, EnterN2 # "Enter Number 2: "
syscall
li $v0,5 # load syscall read_int into $v0
syscall # read int number to $v0
add $t2, $0, $v0
beq $t1, $t2, _equal
blt $t1,$t2, _less
li $v0,4
la $a0, greater
syscall
j final
_equal:
li $v0,4
la $a0, equal
syscall
j final
_less:
li $v0,4
la $a0, less
syscall
final: nop
addi $v0, $zero, 10 # Sets $v0 to "10" to select exit syscall
syscall # make the syscall Exit
.data
NewLine: .asciiz "\n"
EnterN1: .asciiz "Enter Number 1: "
EnterN2: .asciiz "Enter Number 2 : "
Addition: .asciiz "Addition: "
Subtruction: .asciiz "\nSubtruction: "
OddNumber: .asciiz " Odd"
EvenNumber: .asciiz " Even"
greater: .asciiz "Number1 greater Number2"
less: .asciiz "Number1 less Number2"
equal: .asciiz "Number1 equal Number2"
Comments
Leave a comment