cs104 Lab 2
cs104 Lab 2
cs104 Lab 2
.data
num1:.asciiz "Enter the first number:"
num2: .asciiz "Enter the second number:"
result: .asciiz "The result is :"
.text
li $v0, 4 #command to print a string
la $a0, num1 #loading a string to print into the argument
syscall #execute the command
li $v0, 5 #command for reading an integer
syscall
move $t0,$v0
li $v0, 4 #command to print a string
la $a0, num2 #loading a string to print into the argument
syscall #execute the command
li $v0, 5 #command for reading an integer
syscall move $t1,$v0
add $t2,$t0,$t1 # t2=t0+t1
li $v0,4
la $a0,result
syscall
li $v0,1
la $a0, ($t2) syscall
IF ELSE STATEMENT
.data
msg1:.asciiz "The numbers are equal"
msg2:.asciiz "The numbers are not equal"
.text
li $t0,8
li $t1,8
beq $t0,$t1,numbersequal
bne $t0,$t1,numbersnotequal
numbersequal: li $v0,4
la $a0,msg1
syscall
numbersnotequal:
li $v0,4 la $a0,msg2 syscall
.data
.text
li $t0,1 #t0=1, similar to i=1
li $t1,0 #t1=0, similar to sum=0
while:
beq $t0,11, exit #if i=11 then exit
add $t1,$t1,$t0 # t1=t1+t0, or similar to sum=sum+i
addi $t0,$t0,1 #t0=t0+1, or similar to i=i+1
j while
exit:
li $v0,1
move $a0, $t1
syscall