Question
The following program that you will write will read two numbers
A and B, and print out multiples of A from A to A*B
Resolving the question
.data
hello_msg1: .asciiz "please enter first number !\n";
hello_msg2: .asciiz "please enter second number !\n";
hello_msg3: .asciiz " !\n The Multiplier A ";
hello_msg4: .asciiz " !\n your program is finish ";
#-------------------------------------------------------------------------------
.text
main:
#------------------------------------------------------------------------------
add $t0,$zero,$zero
add $t1,$zero,$zero
add $t2,$zero,$zero
#-------------------------------------------------------------------------------
la $a0, hello_msg1
li $v0, 4
syscall
#-------------------------------------------------------------------------------
li $v0, 5 # Read first number A
syscall # $v0 = value read
#-------------------------------------------------------------------------------
move $t0, $v0 #
#------------------------------------------------------------------------------
la $a0, hello_msg2
li $v0, 4
syscall
#--------------------------------------------------------------------
li $v0, 5 # second number B
syscall # $v0 = value read
#-------------------------------------------------------------------------------
move $t1, $v0
#-------------------------------------------------------------------------------
mul $t3,$t0,$t1 # $t3= A * B
#------------------------------------------------------------------------------
loop:
beq $t2,$t3,L1 # if $t2=$t3 then Exit program
la $a0, hello_msg3
li $v0, 4
syscall
#-----------------------------------------------------------------------------
add $t2,$t2,$t0 # multiples of A from A to A*B.
move $v0,$t2
move $a0, $v0
#------------------------------------------------------------------------------
li $v0,1
syscall
#------------------------------------------------------------------------------
j loop
#------------------------------------------------------------------------------
L1:
#-------------------------------------------------------------------------------
la $a0, hello_msg4
li $v0, 4
syscall
#-------------------------------------------------------------------------------
li $v0, 10 # Exit program
syscall