Advertisement
xerpi

mips memset

Sep 28th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #made by xerpi
  2.  
  3. .text
  4. .global mips_memset
  5. .set noreorder
  6.  
  7. mips_memset:
  8.         move $t0, $a0       #backup ptr
  9.         move $t1, $a1       #c8  - $t1
  10.         move $t2, $a1       #c16 - $t2
  11.         sll $t2, $t2, 8     #c16 = c16 << 8
  12.         or $t2, $t2, $a1    #c16 = c16 |c8
  13.         move $t3, $t2       #c32 = c16
  14.         sll $t3, $t3, 16    #c32 = c32 << 16
  15.         or $t3, $t3, $t2    #c32 = c32 | c16
  16. _loop_memset:
  17.         beqz $a2, _e_memset    #if(size==0) return
  18.         nop
  19.         bge $a2, 4, _4_memset  #if(size >= 4) goto _4_memset
  20.         nop
  21.         bge $a2, 2, _2_memset  #if(size >= 2) goto _2_memset
  22.         nop
  23.         _1_memset:
  24.                 sb $t1, ($a0)      #*ptr = c8
  25.                 addi $a0, $a0, 1   #ptr++
  26.                 j _loop_memset
  27.                 addi $a2, $a2, -1  # size--
  28.         _2_memset:
  29.             sh $t2, ($a0)      #*ptr = c16
  30.                 addi $a0, $a0, 2   #ptr+=2
  31.                 j _loop_memset
  32.                 addi $a2, $a2, -2  #size-=2          
  33.         _4_memset:
  34.         sw $t3, ($a0)      #*ptr = c32
  35.                 addi $a0, $a0, 4   #ptr+=4
  36.                 j _loop_memset    
  37.                 addi $a2, $a2, -4  #ptrl=4  
  38.        
  39. _e_memset:
  40.         jr $ra
  41.         move $v0, $t0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement