هذا البرنامج من تصميمي يقوم بسؤال المستخدم كم عدداً يريد ان يدخله الى البرنامج ومن ثم يقوم بإستقبال الاعداد ومن ثم طباعة حاصل الجمع والمعدل لكل الاعداد المدخلة ...
# Average and sum
.data
hello_msg1: .asciiz "How many Number do you want to add !\n";
hello_msg4: .asciiz "OK that is cooool Then inter your Numbers !\n";
hello_msg2: .asciiz "The Sum of your Numbers is !\n";
hello_msg3: .asciiz "!\n The Average of your Numbers is !\n";
#-------------------------------------------------------------------------------
.text
main:
la $a0, hello_msg
li $v0, 4
syscall
#-------------------------------------------------------------------------------
la $a0, hello_msg1
li $v0, 4
syscall
#-------------------------------------------------------------------------------
li $v0, 5 # Read integer
syscall # $v0 = value read
#-------------------------------------------------------------------------------
move $t0, $v0 #
#------------------------------------------------------------------------------
add $t3,$t3,$zero
#------------------------------------------------------------------------------
la $a0, hello_msg4
li $v0, 4
syscall
#------------------------------------------------------------------------------
loop:
beq $t3,$t0,L1
#------------------------------------------------------------------------------
li $v0, 5 # Read integer
syscall # $v0 = value read
#------------------------------------------------------------------------------
move $t1,$v0
#------------------------------------------------------------------------------
add $t2,$t2,$t1 # to get Sum of your number
#------------------------------------------------------------------------------
addi $t3,$t3,1
#------------------------------------------------------------------------------
j loop
#------------------------------------------------------------------------------
L1:
#-------------------------------------------------------------------------------
la $a0, hello_msg2
li $v0, 4
syscall
#------------------------------------------------------------------------------
add $v0,$t2,$zero # to get Sum of your number $v0
#------------------------------------------------------------------------------
move $a0, $v0 # $a0 = value to print
#------------------------------------------------------------------------------
li $v0, 1 # Print integer
syscall
#-------------------------------------------------------------------------------
la $a0, hello_msg3
li $v0, 4
syscall
#-------------------------------------------------------------------------------
div $v0,$t2,$t0 # to get avareg of your number
#-------------------------------------------------------------------------------
move $a0, $v0 # $a0 = value to print
#-------------------------------------------------------------------------------
li $v0, 1 # Print integer
syscall
#-------------------------------------------------------------------------------
li $v0, 10 # Exit program
syscall