Skip to content

Commit 4dc3dbc

Browse files
Fixed an error of returning data to register x0 in the library for arm64, added possibility of clearing several registers with clr, and other minor changes of push/pop for registers inside macros
1 parent 0ffe63d commit 4dc3dbc

File tree

7 files changed

+282
-280
lines changed

7 files changed

+282
-280
lines changed

MACRO_USAGE.md

Lines changed: 108 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -16,128 +16,149 @@ Also:
1616

1717

1818

19-
## clr
20-
Clears the specified register by setting it to zero.
19+
## Auxiliary Macros
20+
21+
### clr
22+
Clears the specified registers by setting them to zero.
2123

2224
```asm
23-
clr reg
25+
clr reg1, reg2
2426
```
2527

2628

2729
**Arguments:**</br>
28-
`reg`the name of the register to be cleared (e.g., `eax`, `rax`, etc.)
30+
`regN`actual registers to be cleared (set to zero), depending on the target architecture.
2931

3032

3133
**Usage example:**
3234

3335
```asm
34-
clr eax ; sets eax to 0
35-
clr rax ; sets rax to 0
36-
clr r0 ; sets r0 to 0
37-
clr x0 ; sets x0 to 0
36+
clr eax, ebx ; sets eax and ebx to 0
37+
clr rax, rdi ; sets rax and rdi to 0
38+
clr r7, r0 ; sets r7 and r0 to 0
39+
clr x8, x0 ; sets x8 and x0 to 0
3840
```
3941

4042

4143

42-
## exit
43-
Terminates the program with a specified exit code.
44+
### push / pop
45+
Pushes or pops multiple registers on/from the stack (equivalent to multiple `push`/`pop` instructions).</br>
46+
Register order in `pop` must match the reverse of `push`.
4447

4548
```asm
46-
exit code
49+
push reg1, reg2, reg3
50+
...
51+
pop reg3, reg2, reg1
4752
```
4853

4954

5055
**Arguments:**</br>
51-
`code`the exit code to return to the operating system (e.g., `0` for success, `1` for error)
56+
`regN`actual registers to push or pop depending on the target architecture.
5257

5358

5459
**Usage example:**
5560

56-
```asm
57-
exit 0 ; exit with code 0
58-
exit 1 ; exit with code 1
61+
For x86_64:
62+
```
63+
push rax, rdi, rsi
64+
...
65+
pop rsi, rdi, rax
5966
```
6067

68+
For x86:
69+
```
70+
push eax, edi, esi
71+
...
72+
pop esi, edi, eax
73+
```
6174

75+
For ARM:
76+
```
77+
push r0, r1, r2
78+
...
79+
pop r2, r1, r0
80+
```
6281

63-
## time
64-
Stores the current UNIX time (seconds since January 1, 1970) in the architecture-specific register.
65-
66-
```asm
67-
time
82+
For ARM64:
83+
```
84+
push x0, x1, x2
85+
...
86+
pop x2, x1, x0
6887
```
6988

7089

7190

72-
## mkdir
73-
Creates a directory with the given name and permissions (in octal format).</br>
74-
Returns an error code in the architecture-specific register.
91+
### exit
92+
Terminates the program with a specified exit code.
7593

7694
```asm
77-
mkdir dir_name, permissions
95+
exit code
7896
```
7997

8098

8199
**Arguments:**</br>
82-
`dir_name` — name of the directory to create, given as a string literal or a pointer to a string</br>
83-
`permissions` — access mode in octal format, given as a number or a pointer to a variable containing the value
100+
`code` — the exit code to return to the operating system (e.g., `0` for success, `1` for error).
84101

85102

86103
**Usage example:**
87104

88105
```asm
89-
mkdir "dir", 700o
90-
mkdir name, permissions
106+
exit 0 ; exit with code 0
107+
exit 1 ; exit with code 1
91108
```
92109

93110

94111

95-
## rmdir
96-
Removes the specified directory.</br>
112+
## Directory Management Macros
113+
114+
### mkdir
115+
Creates a directory with the given name and permissions (in octal format).</br>
97116
Returns an error code in the architecture-specific register.
98117

99118
```asm
100-
rmdir dir_name
119+
mkdir dir_name, permissions
101120
```
102121

103122

104123
**Arguments:**</br>
105-
`dir_name` — name of the directory to remove, given as a string literal or a pointer to a string
124+
`dir_name` — name of the directory to create, given as a string literal or a pointer to a string.</br>
125+
`permissions` — access mode in octal format, given as a number or a pointer to a variable containing the value.
106126

107127

108128
**Usage example:**
109129

110130
```asm
111-
rmdir "dir"
112-
rmdir name
131+
mkdir "dir", 700o
132+
mkdir name, permissions
113133
```
114134

115135

116136

117-
## printnum
118-
Prints the given number in decimal.</br>
119-
Supports values according to the target architecture.</br>
120-
Returns the number of bytes printed in the architecture-specific register.
137+
### rmdir
138+
Removes the specified directory.</br>
139+
Returns an error code in the architecture-specific register.
121140

122141
```asm
123-
printnum number
142+
rmdir dir_name
124143
```
125144

126145

127146
**Arguments:**</br>
128-
`number` — the unsigned integer value to print
147+
`dir_name`name of the directory to remove, given as a string literal or a pointer to a string.
129148

130149

131150
**Usage example:**
132151

133152
```asm
134-
printnum 18446744073709551615
135-
printnum 4294967295
153+
rmdir "dir"
154+
rmdir name
136155
```
137156

138157

139158

140-
## print
159+
## Console Output Macros
160+
161+
### print
141162
Prints the string at the given address with the specified length.</br>
142163
Returns the number of bytes printed in the architecture-specific register.
143164

@@ -147,8 +168,8 @@ print str, str_len
147168

148169

149170
**Arguments:**
150-
`str` — pointer to the string or string literal to print</br>
151-
`str_len` — length of the string in bytes, given as a number or pointer
171+
`str` — pointer to the string or string literal to print.</br>
172+
`str_len` — length of the string in bytes, given as a number or pointer.
152173

153174

154175
**Usage example:**
@@ -160,7 +181,7 @@ print "test", 4
160181

161182

162183

163-
## printtim
184+
### printtim
164185
Prints the given string a specified number of times.</br>
165186
Returns the number of bytes printed in the architecture-specific register.
166187

@@ -170,9 +191,9 @@ printtim times, str, str_len
170191

171192

172193
**Arguments:**</br>
173-
`times` — number of times to print the string, given as a number or pointer
174-
`str` — pointer to the string or string literal to print
175-
`str_len` — length of the string in bytes, given as a number or pointer
194+
`times` — number of times to print the string, given as a number or pointer.</br>
195+
`str` — pointer to the string or string literal to print.</br>
196+
`str_len` — length of the string in bytes, given as a number or pointer.
176197

177198

178199
**Usage example:**
@@ -184,69 +205,69 @@ printtim 3, "test", 4
184205

185206

186207

187-
## run
188-
Executes the specified shell command.</br>
189-
Returns an error code in the architecture-specific register.
208+
### printnum
209+
Prints the given number in decimal.</br>
210+
Supports values according to the target architecture.</br>
211+
Returns the number of bytes printed in the architecture-specific register.
190212

191213
```asm
192-
run command
214+
printnum number
193215
```
194216

217+
**Note:**
218+
219+
Not available in the library for arm and arm64.
220+
195221

196222
**Arguments:**</br>
197-
`command`pointer to the command string or a string literal to execute
223+
`number` — the unsigned integer value to print.
198224

199225

200226
**Usage example:**
201227

202-
```
203-
run "echo test"
204-
run cmd_str
228+
```asm
229+
printnum 18446744073709551615
230+
printnum 4294967295
205231
```
206232

207233

208234

209-
## push / pop
210-
Pushes or pops multiple registers on/from the stack (equivalent to multiple `push`/`pop` instructions).
211-
Register order in `pop` must match the reverse of `push`.
235+
## Misc Macros
236+
237+
### time
238+
Stores the current UNIX time (seconds since January 1, 1970) in the architecture-specific register.
212239

213240
```asm
214-
push reg1, reg2, reg3
215-
...
216-
pop reg3, reg2, reg1
241+
time
217242
```
218243

244+
**Note:**
219245

220-
**Arguments:**</br>
221-
`regN` — actual registers to push or pop depending on the target architecture
246+
Not available in the library for arm and arm64.
222247

223248

224-
**Usage example:**
225249

226-
For x86_64:
227-
```
228-
push rax, rdi, rsi
229-
...
230-
pop rsi, rdi, rax
231-
```
250+
### run
251+
Executes the specified shell command.</br>
252+
Returns an error code in the architecture-specific register.
232253

233-
For x86:
234-
```
235-
push eax, edi, esi
236-
...
237-
pop esi, edi, eax
254+
```asm
255+
run command
238256
```
239257

240-
For ARM:
241-
```
242-
push r0, r1, r2
243-
...
244-
pop r2, r1, r0
245-
```
246258

247-
For ARM64:
259+
**Note:**
260+
261+
Not available in the library for arm and arm64.
262+
263+
264+
**Arguments:**</br>
265+
`command` — pointer to the command string or a string literal to execute.
266+
267+
268+
**Usage example:**
269+
248270
```
249-
push x0, x1, x2
250-
...
251-
pop x2, x1, x0
271+
run "echo test"
272+
run cmd_str
252273
```

examples/examples_arm64/clear.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ segment readable executable
1111
align 4
1212

1313
start:
14+
clr x8, x0
1415
mov x8, #93
15-
clr x0
1616
svc 0

examples/examples_x64/clear.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ entry start
99
segment readable executable
1010

1111
start:
12+
clr rax, rdi
1213
mov rax, 60
13-
clr rdi
1414
syscall

examples/examples_x86/clear.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ entry start
99
segment readable executable
1010

1111
start:
12+
clr eax, ebx
1213
mov eax, 1
13-
clr ebx
1414
int 0x80

0 commit comments

Comments
 (0)