-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemset_bonus.asm
More file actions
44 lines (36 loc) · 836 Bytes
/
memset_bonus.asm
File metadata and controls
44 lines (36 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
.section .text
.global memset
memset:
mv t1, a0 # t1 = pointer
beqz a2, end # Early exit if size=0
# Align pointer to 4 bytes if needed
andi t0, t1, 3
beqz t0, aligned
align_loop:
sb a1, 0(t1)
addi t1, t1, 1
addi a2, a2, -1
andi t0, t1, 3
bnez t0, align_loop
beqz a2, end
aligned:
slli t3, a1, 8
or t3, t3, a1
slli t4, t3, 16
or t3, t3, t4
srli t2, a2, 2
andi a2, a2, 3
word_loop:
beqz t2, byte_loop
sw t3, 0(t1)
addi t1, t1, 4
addi t2, t2, -1
j word_loop
byte_loop:
beqz a2, end
sb a1, 0(t1)
addi t1, t1, 1
addi a2, a2, -1
j byte_loop
end:
ret