برنامج بلغة الاسمبلي يطلب من المستخدم ادخال عددين صحيحين ومن ثم يقارن بينهم ...
.data
hello_msg: .asciiz " \n Program compares two integers !\n";
masseg1 : .asciiz "\nPlease enter number A : " ;
masseg2 : .asciiz "\n Please enter number B : " ;
masseg3 : .asciiz "\n value A is smaller than value B : " ;
masseg4 : .asciiz "\n value B is smaller than value A " ;
masseg5: .asciiz "!\n \nDo you want to compares two values agin ? NO press (0) YES press any number except (0) !\n\n";
.text
main :
loop:
la $a0, hello_msg
li $v0, 4
syscall
#-------------------------------------------------------------
add $t0,$t0,$zero # $t0=0
add $t1,$t1,$zero # $t1=0
#-------------------------------------------------------------
#-------------------------------------------------------------
la $a0, masseg1
li $v0, 4
syscall
#-------------------------------------------------------------
li $v0, 5 # read integer A
syscall
move $t0,$v0
#-------------------------------------------------------------
la $a0, masseg2
li $v0, 4
syscall
#-------------------------------------------------------------
li $v0, 5 # read integer B
syscall
move $t1,$v0
#-------------------------------------------------------------
slt $t2,$t1,$t0 # if $t0>=$t1 then $t2 = 1 else $t2 = 0
beq $t2,$zero,small # if $t2 = 0 then go to small( print masseg3 ) else print (masseg3)
la $a0, masseg4
li $v0, 4
syscall
j end
#-------------------------------------------------------------
small:
la $a0, masseg3
li $v0, 4
syscall
#-------------------------------------------------------------
end:
la $a0, masseg5 # Ask the user wants to compare two other numbers
li $v0, 4
syscall
#------------------------------------------------------------------------------
li $v0, 5 # Read integer from User
syscall # $v0 = value read
#-------------------------------------------------------------------------------
move $t5, $v0 #
beq $t5,$zero,exit # if $t5 =0 compare two other numbers else Exit program
j loop
#-------------------------------------------------------------------------------
exit:
li $v0,10 #Exit program
syscall