Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #made by xerpi
- .text
- .global mips_memset
- .set noreorder
- mips_memset:
- move $t0, $a0 #backup ptr
- move $t1, $a1 #c8 - $t1
- move $t2, $a1 #c16 - $t2
- sll $t2, $t2, 8 #c16 = c16 << 8
- or $t2, $t2, $a1 #c16 = c16 |c8
- move $t3, $t2 #c32 = c16
- sll $t3, $t3, 16 #c32 = c32 << 16
- or $t3, $t3, $t2 #c32 = c32 | c16
- _loop_memset:
- beqz $a2, _e_memset #if(size==0) return
- nop
- bge $a2, 4, _4_memset #if(size >= 4) goto _4_memset
- nop
- bge $a2, 2, _2_memset #if(size >= 2) goto _2_memset
- nop
- _1_memset:
- sb $t1, ($a0) #*ptr = c8
- addi $a0, $a0, 1 #ptr++
- j _loop_memset
- addi $a2, $a2, -1 # size--
- _2_memset:
- sh $t2, ($a0) #*ptr = c16
- addi $a0, $a0, 2 #ptr+=2
- j _loop_memset
- addi $a2, $a2, -2 #size-=2
- _4_memset:
- sw $t3, ($a0) #*ptr = c32
- addi $a0, $a0, 4 #ptr+=4
- j _loop_memset
- addi $a2, $a2, -4 #ptrl=4
- _e_memset:
- jr $ra
- move $v0, $t0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement