Vous êtes sur la page 1sur 1

.

data
Prompt: .asciiz "\n Please input a value for N = "
Result: .asciiz " The sum of the integers from 1 to N is "
Bye: .asciiz "\n **** Adios Amigo - Have a good day ****"

.globl main

.text
main:
li $v0, 4
la $a0, Prompt
syscall

li $v0, 5
syscall

blez $v0, End


li $t0, 0
Loop:
add $t0, $t0, $v0 # sum of integers in register $t0
addi $v0, $v0, -1 # summing integers in reverse order
bnez $v0, Loop # branch to loop if $v0 is != zero
li $v0, 4 # system call code for Print String
la $a0, Result # load address of message into $a0
syscall # print the string
li $v0, 1 # system call code for Print Integer
move $a0, $t0 # move value to be printed to $a0
syscall # print sum of integers
b main # branch to main

End: li $v0, 4 # system call code for Print String


la $a0, Bye # load address of msg. into $a0
syscall # print the string
li $v0, 10 # terminate program run and
syscall # return control to system

Vous aimerez peut-être aussi