forked from darencard/jekyll-now
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reg_dump.s
162 lines (140 loc) · 6.47 KB
/
reg_dump.s
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/******************************************************************************
* @file reg_dump.s
* @brief register print example
*
* Simple example of printing register values to terminal for debugging
*
* @author Christopher D. McMurrough
******************************************************************************/
.global main
.func main
main:
MOV R0, #0 @ set a constant value for printing
MOV R1, #10 @ set a constant value for printing
MOV R2, #20 @ set a constant value for printing
MOV R3, #30 @ set a constant value for printing
MOV R4, #40 @ set a constant value for printing
MOV R5, #50 @ set a constant value for printing
MOV R6, #60 @ set a constant value for printing
MOV R7, #70 @ set a constant value for printing
MOV R8, #80 @ set a constant value for printing
MOV R9, #90 @ set a constant value for printing
MOV R10, #100 @ set a constant value for printing
MOV R11, #110 @ set a constant value for printing
MOV R12, #120 @ set a constant value for printing
BL _reg_dump @ print register contents
B _exit @ branch to exit procedure with no return
_exit:
MOV R7, #4 @ write syscall, 4
MOV R0, #1 @ output stream to monitor, 1
MOV R2, #21 @ print string length
LDR R1,=exit_str @ string at label exit_str:
SWI 0 @ execute syscall
MOV R7, #1 @ terminate syscall, 1
SWI 0 @ execute syscall
_reg_dump:
PUSH {LR} @ backup registers
PUSH {R0} @ backup registers
PUSH {R1} @ backup registers
PUSH {R2} @ backup registers
PUSH {R3} @ backup registers
PUSH {R14} @ push registers for printing
PUSH {R13} @ push registers for printing
PUSH {R12} @ push registers for printing
PUSH {R11} @ push registers for printing
PUSH {R10} @ push registers for printing
PUSH {R9} @ push registers for printing
PUSH {R8} @ push registers for printing
PUSH {R7} @ push registers for printing
PUSH {R6} @ push registers for printing
PUSH {R5} @ push registers for printing
PUSH {R4} @ push registers for printing
PUSH {R3} @ push registers for printing
PUSH {R2} @ push registers for printing
PUSH {R1} @ push registers for printing
PUSH {R0} @ push registers for printing
LDR R0,=debug_str @ prepare register print
MOV R1, #0 @ prepare R0 print
POP {R2} @ prepare R0 print
MOV R3, R2 @ prepare R0 print
BL printf @ print R0 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #1 @ prepare R1 print
POP {R2} @ prepare R1 print
MOV R3, R2 @ prepare R1 print
BL printf @ print R1 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #2 @ prepare R2 print
POP {R2} @ prepare R2 print
MOV R3, R2 @ prepare R2 print
BL printf @ print R2 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #3 @ prepare R3 print
POP {R2} @ prepare R3 print
MOV R3, R2 @ prepare R3 print
BL printf @ print R3 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #4 @ prepare R4 print
POP {R2} @ prepare R4 print
MOV R3, R2 @ prepare R4 print
BL printf @ print R4 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #5 @ prepare R5 print
POP {R2} @ prepare R5 print
MOV R3, R2 @ prepare R5 print
BL printf @ print R5 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #6 @ prepare R6 print
POP {R2} @ prepare R6 print
MOV R3, R2 @ prepare R6 print
BL printf @ print R6 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #7 @ prepare R7 print
POP {R2} @ prepare R7 print
MOV R3, R2 @ prepare R7 print
BL printf @ print R7 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #8 @ prepare R8 print
POP {R2} @ prepare R8 print
MOV R3, R2 @ prepare R8 print
BL printf @ print R8 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #9 @ prepare R9 print
POP {R2} @ prepare R9 print
MOV R3, R2 @ prepare R9 print
BL printf @ print R9 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #10 @ prepare R10 print
POP {R2} @ prepare R10 print
MOV R3, R2 @ prepare R10 print
BL printf @ print R10 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #11 @ prepare R11 print
POP {R2} @ prepare R11 print
MOV R3, R2 @ prepare R11 print
BL printf @ print R11 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #12 @ prepare R12 print
POP {R2} @ prepare R12 print
MOV R3, R2 @ prepare R12 print
BL printf @ print R12 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #13 @ prepare R13 print
POP {R2} @ prepare R13 print
MOV R3, R2 @ prepare R13 print
BL printf @ print R13 value prior to reg_dump call
LDR R0,=debug_str @ prepare register print
MOV R1, #14 @ prepare R14 print
POP {R2} @ prepare R14 print
MOV R3, R2 @ prepare R14 print
BL printf @ print R14 value prior to reg_dump call
POP {R3} @ restore register
POP {R2} @ restore register
POP {R1} @ restore register
POP {R0} @ restore regsiter
POP {PC} @ return
.data
debug_str:
.asciz "R%-2d 0x%08X %011d \n"
exit_str:
.ascii "Terminating program.\n"