Advertisement
chete

contar unos en binario

May 15th, 2014
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. .text
  3. .globl main
  4. main:
  5. li $v0,5
  6. syscall
  7. move $a0,$v0
  8.  
  9. jal funcion
  10.  
  11. move $a0,$v0
  12.  
  13. li $v0,1
  14. syscall
  15. li $v0,10
  16. syscall
  17.  
  18. funcion:
  19.     beq $a0, $zero, trivial
  20.     li $t0,1
  21.     beq $a0,$t0, trivial
  22.  
  23.     addi $sp, $sp,-4
  24.     sw $ra,($sp)
  25.    
  26.     addi $sp,$sp,-4
  27.     sw $a0,($sp)
  28.    
  29.     srl $a0,$a0,1
  30.    
  31.     jal funcion
  32.    
  33.     lw $a0, ($sp)
  34.     addi $sp,$sp,4
  35.     andi $t0,$a0,1
  36.     add $v0,$v0,$t0
  37.     lw $ra, ($sp)
  38.     addi $sp,$sp,4
  39.    
  40.     jr $ra
  41.     trivial:
  42.    
  43.         move $v0,$a0
  44.         jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement