Skip to content

Commit 2745f1e

Browse files
Library hath been ported to the new x86 architecture for Linux,
the project structure hath been altered, README.md and STRUCTURE.md updated accordingly, Makefile now supporteth building for a chosen architecture, as well as all manner of minor adjustments.
1 parent dba0cd0 commit 2745f1e

26 files changed

+492
-40
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
build/
1+
build_x86/
2+
build_x86_64/
3+
build_arm32/
4+
build_arm64/
5+
.vscode

Makefile

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
1-
SRC_DIR := macrolib/examples
2-
BUILD_DIR := build
1+
FASM = fasm
32

4-
ASM_SOURCES := $(wildcard $(SRC_DIR)/*.asm)
3+
# Пути исходников
4+
SRC_x86 = macrolib_x86/examples
5+
SRC_x86_64 = macrolib_x86_64/examples
6+
SRC_arm32 = macrolib_arm32/examples
7+
SRC_arm64 = macrolib_arm64/examples
58

6-
BINARIES := $(patsubst $(SRC_DIR)/%.asm, $(BUILD_DIR)/%, $(ASM_SOURCES))
9+
# Папки сборки
10+
BUILD_x86 = build_x86
11+
BUILD_x86_64 = build_x86_64
12+
BUILD_arm32 = build_arm32
13+
BUILD_arm64 = build_arm64
714

8-
all: $(BUILD_DIR) $(BINARIES)
15+
.PHONY: all clean x86 x86_64 arm32 arm64
916

10-
$(BUILD_DIR):
11-
mkdir -p $(BUILD_DIR)
17+
all: x86 x86_64 arm32 arm64
1218

13-
$(BUILD_DIR)/%: $(SRC_DIR)/%.asm | $(BUILD_DIR)
14-
fasm $< $@
19+
x86:
20+
@echo "Building x86..."
21+
@mkdir -p $(BUILD_x86)
22+
@for file in $(SRC_x86)/*.asm; do \
23+
output=$(BUILD_x86)/$$(basename $$file .asm); \
24+
$(FASM) $$file $$output || exit 1; \
25+
done
26+
@echo "x86 build done."
27+
28+
x86_64:
29+
@echo "Building x86_64..."
30+
@mkdir -p $(BUILD_x86_64)
31+
@for file in $(SRC_x86_64)/*.asm; do \
32+
output=$(BUILD_x86_64)/$$(basename $$file .asm); \
33+
$(FASM) $$file $$output || exit 1; \
34+
done
35+
@echo "x86_64 build done."
36+
37+
arm32:
38+
@echo "Building arm32..."
39+
@mkdir -p $(BUILD_arm32)
40+
@for file in $(SRC_arm32)/*.asm; do \
41+
output=$(BUILD_arm32)/$$(basename $$file .asm); \
42+
$(FASM) $$file $$output || exit 1; \
43+
done
44+
@echo "arm32 build done."
45+
46+
arm64:
47+
@echo "Building arm64..."
48+
@mkdir -p $(BUILD_arm64)
49+
@for file in $(SRC_arm64)/*.asm; do \
50+
output=$(BUILD_arm64)/$$(basename $$file .asm); \
51+
$(FASM) $$file $$output || exit 1; \
52+
done
53+
@echo "arm64 build done."
1554

1655
clean:
17-
rm -rf $(BUILD_DIR)
56+
@echo "Cleaning build directories..."
57+
@rm -rf $(BUILD_x86) $(BUILD_x86_64) $(BUILD_arm32) $(BUILD_arm64)
58+
@echo "Clean done."

README.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,55 @@
33
![License](https://img.shields.io/github/license/lina-torovoltas/FasmMacrosLib)
44
![Version](https://img.shields.io/github/v/release/lina-torovoltas/FasmMacrosLib)
55
![Downloads](https://img.shields.io/github/downloads/lina-torovoltas/FasmMacrosLib/total)</br>
6-
FasmMacroLib is a macro library for simplifying FASM programming on 64-bit Linux.
7-
6+
FasmMacroLib is a macro library for simplifying FASM programming upon both 32-bit and 64-bit Linux architectures.
87

98
## Dependencies
109

11-
Works only on Linux x86_64 (64-bit).
10+
- Linux x86 (32-bit) or x86_64 (64-bit) operating system
11+
- `make` utility for building
12+
- `fasm` assembler for compiling the assembly code
13+
14+
Make sure both `make` and `fasm` are installed and available in thy system PATH before building.
1215

1316

1417
## Installation
1518

16-
Just include the macros file at the beginning of your .asm file:
19+
Just include the macros file at the fore of thy .asm file, according to thine architecture:
1720

1821
```asm
19-
include 'macroslib.inc'
22+
include 'macrolib_x86/macrolib.inc' ; for 32-bit x86
23+
include 'macrolib_x86_64/macrolib.inc' ; for 64-bit x86_64
2024
```
2125

2226

2327
## Usage
2428

2529
Below is a detailed list of available macros and their usage.</br>
26-
27-
For practical examples, see [examples folder](macroslib/examples).</br>
30+
For practical examples, peruse the [x86 examples folder](macrolib_x86/examples) or the [x86_64 examples folder](macrolib_x86_64/examples).</br>
2831
Compiled binaries of these examples are available in the [releases](https://github.com/lina-torovoltas/FasmMacrosLib/releases) section.</br>
32+
Alternatively, thou canst compile them thyself.
2933

30-
Alternatively, you can compile them yourself by running:
34+
To build for a chosen architecture (e.g., x86):
35+
```bash
36+
cd FasmMacroLib
37+
make x86
38+
```
3139

40+
To build for all supported architectures at once:
3241
```bash
3342
cd FasmMacroLib
34-
make
43+
make all
3544
```
3645

3746
### clr
3847
Clears the specified register (sets it to zero).
3948

4049
```asm
50+
; 64-bit
4151
clr rax
52+
53+
; 32-bit
54+
clr eax
4255
```
4356

4457
### exit
@@ -50,47 +63,52 @@ exit 1 ; exit with code 1
5063
```
5164

5265
### time
53-
Stores the current time (seconds since January 1, 1970) in register rax.
66+
Stores the current time (seconds since January 1, 1970) in register rax/eax.
5467

5568
```asm
5669
time
5770
```
5871

5972
### mkdir
6073
Creates a directory with the given name and permissions (octal format).</br>
61-
Returns error code in rax.
74+
Returns error code in rax/eax.
6275

6376
```asm
6477
mkdir "test", 777o
6578
```
6679

6780
### rmdir
6881
Removes the specified directory.</br>
69-
Returns error code in rax.
82+
Returns error code in rax/eax.
7083

7184
```asm
7285
rmdir "test"
7386
```
7487

7588
### printnum
7689
Prints the given number in decimal.</br>
77-
Returns the number of bytes printed in rax.
90+
Supports values from 0 to 4,294,967,295 (32-bit) and up to 18,446,744,073,709,551,615 (64-bit).</br>
91+
Returns the number of bytes printed in rax/eax.
7892

7993
```asm
80-
printnum 244939252
94+
; 64-bit
95+
printnum 18446744073709551615
96+
97+
; 32-bit
98+
printnum 4294967295
8199
```
82100

83101
### print
84102
Prints the string at the given address with the specified length.</br>
85-
Returns the number of bytes printed in rax.
103+
Returns the number of bytes printed in rax/eax.
86104

87105
```asm
88106
print "test", 4
89107
```
90108

91109
### printtim
92110
Prints the given string a specified number of times.</br>
93-
Returns the number of bytes printed in rax.
111+
Returns the number of bytes printed in rax/eax.
94112

95113
```asm
96114
printtim 2, "test", 4
@@ -107,9 +125,15 @@ run "echo test"
107125
Pushes or pops multiple registers on/from the stack (like multiple push/pop instructions combined).
108126

109127
```asm
128+
; 64-bit
110129
push rax, rdi, rsi, rdx
111130
...
112131
pop rdx, rsi, rdi, rax
132+
133+
; 32-bit
134+
push eax, edi, esi, edx
135+
...
136+
pop edx, esi, edi, eax
113137
```
114138

115139

@@ -121,4 +145,4 @@ Feel free to open pull requests to improve the library.
121145

122146
## Author
123147

124-
Developed by <a href="https://github.com/lina-torovoltas" style="color:#ff4f00">Lina Torovoltas</a> — © 2025 All rights reserved.
148+
Developed by <a href="https://github.com/lina-torovoltas" style="color:#ff4f00">Lina Torovoltas</a> — © 2025 All rights reserved.

STRUCTURE.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22

33
```
44
/
5+
├── .gitignore
56
├── LICENSE
7+
├── Makefile
68
├── README.md
79
├── STRUCTURE.md
8-
└── macroslib/
9-
├── macroslib.inc
10+
├── macrolib_x86/
11+
│ ├── macrolib.inc
12+
│ └── examples/
13+
│ ├── clear.asm
14+
│ ├── exit.asm
15+
│ ├── get_time.asm
16+
│ ├── make_dir.asm
17+
│ ├── print_number.asm
18+
│ ├── print_times.asm
19+
│ ├── print.asm
20+
│ ├── remove_dir.asm
21+
│ ├── run_command.asm
22+
│ └── stackops.asm
23+
└── macrolib_x86_64/
24+
├── macrolib.inc
1025
└── examples/
1126
├── clear.asm
1227
├── exit.asm

macrolib_x86/examples/clear.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; This code works only on 32-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
mov eax, 1
13+
clr ebx
14+
int 0x80

macrolib_x86/examples/exit.asm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; This code works only on 64-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
exit 0

macrolib_x86/examples/get_time.asm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; This code works only on 64-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
time
13+
14+
mov eax, 1
15+
xor ebx, ebx
16+
int 0x80

macrolib_x86/examples/make_dir.asm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; This code works only on 64-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
mkdir name, 777o
13+
14+
mov eax, 1
15+
xor ebx, ebx
16+
int 0x80
17+
18+
19+
20+
segment readable writeable
21+
22+
name db "test", 0

macrolib_x86/examples/print.asm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; This code works only on 64-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
print msg, msg_len
13+
14+
mov eax, 1
15+
xor ebx, ebx
16+
int 0x80
17+
18+
19+
20+
segment readable writeable
21+
22+
msg db 'Test output string', 10
23+
msg_len = $ - msg
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; This code works only on 64-bit Linux!!!
2+
3+
format ELF executable 3
4+
include '../macrolib.inc'
5+
entry start
6+
7+
8+
9+
segment readable executable
10+
11+
start:
12+
printnum 1234
13+
printnum 4294967295
14+
printnum 0
15+
printnum 244939252
16+
17+
mov eax, 1
18+
xor ebx, ebx
19+
int 0x80

0 commit comments

Comments
 (0)