Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- N: .word 5
- .text
- .globl main
- ## es 2 13 02 2019
- ric_t:
- slti $t0,$a0,3 #controllo iniziale n<3;
- beq $t0,$0,else #if n<3
- addi $v0,$0,1 # retrun 1
- jr $ra
- else:
- addi $sp,$sp -16 #allocazione stack
- sw $ra,0($sp) #
- sw $s0,4($sp) #$s0--> per salvare n
- sw $s1,8($sp) #$s1 --> per salvare il risultaro della mult
- sw $s2,12($sp) #$s2 --> per salvare la i della sommatoria
- add $s2,$0,$0 # inizializzo i=0;
- add $s0,$a0,$0 # $s0= n
- for:
- beq $s0,$s2,exit #condizione uscita del for (n == i)--> exit \\ for(i=0; i<n;i++){
- addi $a0,$s2,0 #$a0=i;
- jal ric_t # T(i)
- mult $s2,$v0 # i*T(i)
- mflo $s1 #salvo la mult in $s1
- addi $s2,$s2,1 #i++
- j for # go to for
- exit:
- add $v0,$v0,$s1 # somma totale i*T(i)
- lw $ra,0($sp)
- lw $s0,4($sp)
- lw $s1,8($sp)
- lw $s2,12($sp)
- addi $sp,$sp,16
- jr $ra
- main:
- lw $a0,N
- add $v0,$0,$0
- jal ric_t
- add $a0,$v0,$0
- li $v0,1
- syscall
- li $v0,10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement