Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- w: .asciiz "8754830094826456674949263746929"
- resultat: .byte 0
- .text
- .globl main
- main:
- addiu $sp, $sp, -4
- sw $ra, 0($sp)
- la $a0, w
- li $a1, 31
- jal moda
- la $s0, resultat
- sw $v0, 0($s0)
- move $a0, $v0
- li $v0, 11
- syscall
- lw $ra, 0($sp)
- addiu $sp, $sp, 4
- jr $ra
- nofares:
- li $t0, 0x12345678
- move $t1, $t0
- move $t2, $t0
- move $t3, $t0
- move $t4, $t0
- move $t5, $t0
- move $t6, $t0
- move $t7, $t0
- move $t8, $t0
- move $t9, $t0
- move $a0, $t0
- move $a1, $t0
- move $a2, $t0
- move $a3, $t0
- jr $ra
- moda: # moda(char *vec, int num)
- # $s0 = k, $s1 = max
- addiu $sp, $sp, -60 # reserve 60
- sw $ra, 0($sp) # add $ra
- sw $s0, 4($sp) # add $s0
- sw $s1, 8($sp) # add $s1
- sw $s2, 12($sp) # add $s2
- sw $s3, 16($sp) # add $s3
- li $s0, 0 # k = 0
- li $t0, 10 # $t0 = 10
- while:
- bge $s0, $t0, endwhile # while(k < 10)
- sll $t1, $s0, 2 # $t1 = k * 4
- addu $t1, $sp, $t1 # $t1 = @sp + k*4
- sw $zero, 20($t1) # hist[k] = 0
- addiu $s0, $s0, 1 # k++
- b while # continue
- endwhile:
- li $s1, '0' # max = '0'
- li $s0, 0 # k = 0
- while2:
- bge $s0, $a1, endwhile2 # while(k < num)
- move $s2, $a0 # $s2 = @vec
- move $s3, $a1 # $s3 = num
- addiu $a0, $sp, 20 # $a0 = $sp + 20 = @hist
- addu $t0, $s2, $s0 # $t0 = @vec[k]
- lb $t0, 0($t0) # $t0 = vec[k]
- addiu $a1, $t0, -48 # $a1 = vec[k] - '0'
- addiu $a2, $s1, -48 # $a2 = max - '0'
- jal update # update(@histo, vec[k] - '0', max - '0')
- addiu $s1, $v0, 48 # $s1 = update(..) + '0'
- move $a0, $s2 # $a0 = @vec
- move $a1, $s3 # $a1 = num
- addiu $s0, $s0, 1 # k++
- b while2 # continue
- endwhile2:
- move $v0, $s1 # return max
- lw $s3, 16($sp) # pop $s3
- lw $s2, 12($sp) # pop $s2
- lw $s1, 8($sp) # pop $s1
- lw $s0, 4($sp) # pop $s0
- lw $ra, 0($sp) # pop $ra
- addiu $sp, $sp, 60 # free 60
- jr $ra
- update: # update(int *hist, char i, char imax)
- addiu $sp, $sp, -16 # reserve 12
- sw $ra, 0($sp) # add $ra
- sw $s0, 4($sp) # add $s0
- sw $s1, 8($sp) # add $s1
- sw $s2, 12($sp) # add $s2
- move $s0, $a0 # $s0 = $a0
- move $s1, $a1 # $s1 = $a1
- move $s2, $a2 # $s2 = $a2
- jal nofares # nofares()
- move $a0, $s0 # $a0 = $s0
- move $a1, $s1 # $s1 = $a1
- move $a2, $s2 # $s2 = $a2
- sll $t0, $a1, 2 # $t0 = i * 4
- addu $t0, $a0, $t0 # $t0 = @hist + i*4 = @hist[i]
- lw $t1, 0($t0) # $t1 = hist[i]
- addiu $t1, $t1, 1 # $t1 = hist[i] + 1
- sw $t1, 0($t0) # hist[i]++
- sll $t0, $a2, 2 # $t0 = imax * 4
- addu $t0, $a0, $t0 # $t0 = @hist + imax*4 = @hist[imax]
- lw $t0, 0($t0) # $t0 = hist[imax]
- ble $t1, $t0, else # if(hist[i] > hist[imax])
- move $v0, $a1 # return i
- b endif
- else:
- move $v0, $a2 # return imax
- endif:
- lw $s2, 12($sp) # pop $s2
- lw $s1, 8($sp) # pop $s1
- lw $s0, 4($sp) # pop $s0
- lw $ra, 0($sp) # pop $ra
- addiu $sp, $sp, 16 # free 16
- jr $ra
Add Comment
Please, Sign In to add comment