/
memory.asm
107 lines (97 loc) · 2.06 KB
/
memory.asm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
; memory copy/compare routines
; copy specified number of bytes from source pointer to destination pointer
; if the source and destination overlap, the behavior is undefined
; inputs:
; r0: pointer to source
; r1: pointer to destination
; r2: number of bytes to copy
; outputs:
; none
copy_memory_bytes:
push r0
push r1
push r31
mov r31, r2
copy_memory_bytes_loop:
mov.8 [r1], [r0]
inc r0
inc r1
loop copy_memory_bytes_loop
pop r31
pop r1
pop r0
ret
; copy specified number of words from source pointer to destination pointer
; if the source and destination overlap, the behavior is undefined
; inputs:
; r0: pointer to source
; r1: pointer to destination
; r2: number of words to copy
; outputs:
; none
copy_memory_words:
push r0
push r1
push r31
mov r31, r2
copy_memory_words_loop:
mov [r1], [r0]
add r0, 4
add r1, 4
loop copy_memory_words_loop
pop r31
pop r1
pop r0
ret
; compare specified number of bytes from source pointer with destination pointer
; inputs:
; r0: pointer to source
; r1: pointer to destination
; r2: number of bytes to compare
; outputs:
; Z flag
compare_memory_bytes:
push r0
push r1
push r31
mov r31, r2
compare_memory_bytes_loop:
cmp.8 [r1], [r0]
ifnz jmp compare_memory_bytes_not_equal
inc r0
inc r1
loop compare_memory_bytes_loop
; set Z flag if we reach this point
mov r0, 0
cmp r0, 0
compare_memory_bytes_not_equal:
pop r31
pop r1
pop r0
ret
; compare specified number of words from source pointer with destination pointer
; inputs:
; r0: pointer to source
; r1: pointer to destination
; r2: number of words to compare
; outputs:
; Z flag
compare_memory_words:
push r0
push r1
push r31
mov r31, r2
compare_memory_words_loop:
cmp [r1], [r0]
ifnz jmp compare_memory_words_not_equal
add r0, 4
add r1, 4
loop compare_memory_words_loop
; set Z flag if we reach this point
mov r0, 0
cmp r0, 0
compare_memory_words_not_equal:
pop r31
pop r1
pop r0
ret