Skip to content

Commit 2c27a1f

Browse files
Updated STRUCTURE.md, README.md, MACRO_USAGE.md files, added BSD implementation of library and examples, changed folder structure for better navigation in repository, changed MakeFile for folder structure and new implementation of library
1 parent 179869e commit 2c27a1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+604
-249
lines changed

MACRO_USAGE.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ clr reg1, reg2
3535
**Usage example:**
3636

3737
```asm
38+
clr ax, bx ; sets ax and bx to 0
3839
clr eax, ebx ; sets eax and ebx to 0
3940
clr rax, rdi ; sets rax and rdi to 0
4041
clr r7, r0 ; sets r7 and r0 to 0
@@ -60,11 +61,11 @@ pop reg3, reg2, reg1
6061

6162
**Usage example:**
6263

63-
For x86_64:
64+
For x16:
6465
```
65-
push rax, rdi, rsi
66+
push ax, bx, cx
6667
...
67-
pop rsi, rdi, rax
68+
pop cx, ax, bx
6869
```
6970

7071
For x86:
@@ -74,6 +75,13 @@ push eax, edi, esi
7475
pop esi, edi, eax
7576
```
7677

78+
For x86_64:
79+
```
80+
push rax, rdi, rsi
81+
...
82+
pop rsi, rdi, rax
83+
```
84+
7785
For ARM:
7886
```
7987
push r0, r1, r2
@@ -171,7 +179,7 @@ print str, str_len
171179

172180
**Arguments:**
173181
`str` — pointer to the string or string literal to print.</br>
174-
`str_len` — length of the string in bytes, given as a number or pointer. (not required for x16)
182+
`str_len` — length of the string in bytes, given as a number or pointer (not required for DOS).
175183

176184

177185
**Usage example:**
@@ -218,7 +226,7 @@ printnum number
218226

219227
**Note:**
220228

221-
Not available in the library for ARM32 and ARM64.
229+
Not available in the library for Linux (ARM 32-bit and ARM 64-bit).
222230

223231

224232
**Arguments:**</br>
@@ -245,7 +253,7 @@ time
245253

246254
**Note:**
247255

248-
Not available in the library for x16, ARM32 and ARM64.
256+
Not available in the library for DOS, Linux (ARM 32-bit and ARM 64-bit), and BSD.
249257

250258

251259

@@ -260,7 +268,7 @@ run command
260268

261269
**Note:**
262270

263-
Not available in the library for x16, ARM32 and ARM64.
271+
Not available in the library for DOS and Linux (ARM 32-bit and ARM 64-bit).
264272

265273

266274
**Arguments:**</br>

Makefile

Lines changed: 53 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,67 @@
1-
SRC_x16_com = examples/examples_x16_com
2-
SRC_x16_exe = examples/examples_x16_exe
3-
SRC_x86 = examples/examples_x86
4-
SRC_x64 = examples/examples_x64
5-
SRC_arm32 = examples/examples_arm32
6-
SRC_arm64 = examples/examples_arm64
1+
DIRS_LINUX = examples_arm32 examples_arm64 examples_x64 examples_x86
2+
DIRS_BSD = examples_x64
3+
DIRS_DOS = examples_x16_com examples_x16_exe
74

8-
BUILD_DIR = build
9-
BUILD_x16_com = $(BUILD_DIR)/examples_x16_com
10-
BUILD_x16_exe = $(BUILD_DIR)/examples_x16_exe
11-
BUILD_x86 = $(BUILD_DIR)/examples_x86
12-
BUILD_x64 = $(BUILD_DIR)/examples_x64
13-
BUILD_arm32 = $(BUILD_DIR)/examples_arm32
14-
BUILD_arm64 = $(BUILD_DIR)/examples_arm64
5+
ASM_LINUX_X64 = $(wildcard examples/Linux/examples_x64/*.asm)
6+
ASM_LINUX_X86 = $(wildcard examples/Linux/examples_x86/*.asm)
7+
ASM_LINUX_ARM32 = $(wildcard examples/Linux/examples_arm32/*.asm)
8+
ASM_LINUX_ARM64 = $(wildcard examples/Linux/examples_arm64/*.asm)
9+
ASM_BSD_X64 = $(wildcard examples/BSD/examples_x64/*.asm)
10+
ASM_DOS_COM = $(wildcard examples/DOS/examples_x16_com/*.asm)
11+
ASM_DOS_EXE = $(wildcard examples/DOS/examples_x16_exe/*.asm)
1512

16-
FASM = fasm
17-
FASMA = fasmarm
1813

19-
all: x16_com x16_exe x86 x64 arm32 arm64
20-
.PHONY: x16_com x16_exe x86 x64 arm32 arm64 all clean check_tools check_dirs
21-
22-
check_tools:
23-
@command -v $(FASM) >/dev/null 2>&1 || { echo "Error: $(FASM) is not installed or not in PATH"; exit 1; }
24-
@command -v $(FASMA) >/dev/null 2>&1 || { echo "Error: $(FASMA) is not installed or not in PATH"; exit 1; }
25-
26-
check_dirs:
27-
@for dir in $(SRC_x16_com) $(SRC_x16_exe) $(SRC_x86) $(SRC_x64) $(SRC_arm32) $(SRC_arm64); do \
28-
if [ ! -d $$dir ]; then \
29-
echo "Error: Source directory '$$dir' does not exist"; exit 1; \
30-
fi \
14+
Linux:
15+
@for dir in $(DIRS_LINUX); do \
16+
mkdir -p build/Linux/$$dir >/dev/null 2>&1; \
3117
done
32-
33-
x16_com: check_tools check_dirs
34-
@mkdir -p $(BUILD_x16_com)
35-
@for file in $(SRC_x16_com)/*.asm; do \
36-
base=$$(basename $$file .asm); \
37-
output="$(BUILD_x16_com)/$$base.com"; \
38-
echo "Building $$file -> $$output"; \
39-
$(FASM) "$$file" "$$output" || exit 1; \
18+
@for src in $(ASM_LINUX_X64); do \
19+
dst=build/Linux/$${src#examples/Linux/}; \
20+
dst=$${dst%.asm}; \
21+
fasm $$src $$dst; \
4022
done
41-
42-
x16_exe: check_tools check_dirs
43-
@mkdir -p $(BUILD_x16_exe)
44-
@for file in $(SRC_x16_exe)/*.asm; do \
45-
base=$$(basename $$file .asm); \
46-
output="$(BUILD_x16_exe)/$$base.exe"; \
47-
echo "Building $$file -> $$output"; \
48-
$(FASM) "$$file" "$$output" || exit 1; \
23+
@for src in $(ASM_LINUX_X86); do \
24+
dst=build/Linux/$${src#examples/Linux/}; \
25+
dst=$${dst%.asm}; \
26+
fasm $$src $$dst; \
4927
done
50-
51-
x86: check_tools check_dirs
52-
@mkdir -p $(BUILD_x86)
53-
@for file in $(SRC_x86)/*.asm; do \
54-
output=$(BUILD_x86)/$$(basename $$file .asm); \
55-
echo "Building $$file -> $$output"; \
56-
$(FASM) $$file $$output || exit 1; \
28+
@for src in $(ASM_LINUX_ARM32); do \
29+
dst=build/Linux/$${src#examples/Linux/}; \
30+
dst=$${dst%.asm}; \
31+
fasmarm $$src $$dst; \
5732
done
58-
59-
x64: check_tools check_dirs
60-
@mkdir -p $(BUILD_x64)
61-
@for file in $(SRC_x64)/*.asm; do \
62-
output=$(BUILD_x64)/$$(basename $$file .asm); \
63-
echo "Building $$file -> $$output"; \
64-
$(FASM) $$file $$output || exit 1; \
33+
@for src in $(ASM_LINUX_ARM64); do \
34+
dst=build/Linux/$${src#examples/Linux/}; \
35+
dst=$${dst%.asm}; \
36+
fasmarm $$src $$dst; \
6537
done
6638

67-
arm32: check_tools check_dirs
68-
@mkdir -p $(BUILD_arm32)
69-
@for file in $(SRC_arm32)/*.asm; do \
70-
output=$(BUILD_arm32)/$$(basename $$file .asm); \
71-
echo "Building $$file -> $$output"; \
72-
$(FASMA) $$file $$output || exit 1; \
39+
BSD:
40+
@for dir in $(DIRS_BSD); do \
41+
mkdir -p build/BSD/$$dir >/dev/null 2>&1; \
42+
done
43+
@for src in $(ASM_BSD_X64); do \
44+
dst=build/BSD/$${src#examples/BSD/}; \
45+
dst=$${dst%.asm}; \
46+
fasm $$src $$dst; \
7347
done
7448

75-
arm64: check_tools check_dirs
76-
@mkdir -p $(BUILD_arm64)
77-
@for file in $(SRC_arm64)/*.asm; do \
78-
output=$(BUILD_arm64)/$$(basename $$file .asm); \
79-
echo "Building $$file -> $$output"; \
80-
$(FASMA) $$file $$output || exit 1; \
49+
DOS:
50+
@for dir in $(DIRS_DOS); do \
51+
mkdir -p build/DOS/$$dir >/dev/null 2>&1; \
52+
done
53+
@for src in $(ASM_DOS_COM); do \
54+
dst=build/DOS/$${src#examples/DOS/}; \
55+
dst=$${dst%.asm}.com; \
56+
fasm $$src $$dst; \
8157
done
58+
@for src in $(ASM_DOS_EXE); do \
59+
dst=build/DOS/$${src#examples/DOS/}; \
60+
dst=$${dst%.asm}.exe; \
61+
fasm $$src $$dst; \
62+
done
63+
64+
all: Linux BSD DOS
8265

8366
clean:
84-
@rm -rf $(BUILD_DIR)
85-
@echo "Cleaned build directories"
67+
@rm -rf build

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22

33
![Language](https://img.shields.io/badge/language%20-%20Assembly-red)
44
![CPU](https://img.shields.io/badge/CPU-x16%2C%20x86%2C%20x64%2C%20ARM32%2C%20ARM64-orange)
5-
![OS](https://img.shields.io/badge/OS-Linux%2C%20DOS-0078D4)
5+
![OS](https://img.shields.io/badge/OS-Linux%2C%20DOS%2C%20BSD-0078D4)
66
![License](https://img.shields.io/github/license/lina-torovoltas/FasmMacrosLib)
77
![GitHub release](https://img.shields.io/github/v/release/lina-torovoltas/FasmMacrosLib)
88
![Downloads](https://img.shields.io/github/downloads/lina-torovoltas/FasmMacrosLib/total)</br>
9-
FasmMacroLib is a macro library designed to simplify FASM programming upon Linux and DOS.</br>
10-
It supports x16 for DOS, and x86, x64, ARM and ARM64 for Linux.
9+
FasmMacroLib is a macro library designed to simplify FASM programming upon Linux, DOS and BSD.</br>
10+
It supports x86, x64, ARM and ARM64 for Linux, x16 for DOS and x64 for BSD.
1111

1212
## Installation
1313

14-
Just include the `macrolib` file at the top of thy `.asm` file, depending upon thine architecture:
14+
Just include the macrolib file at the top of thy .asm file, depending upon thine OS and architecture:
1515

1616
```asm
17-
include 'macrolib/macrolib_x16.inc' ; for x16
18-
include 'macrolib/macrolib_x86.inc' ; for x86
19-
include 'macrolib/macrolib_x64.inc' ; for x64
20-
include 'macrolib/macrolib_arm32.inc' ; for arm32
21-
include 'macrolib/macrolib_arm64.inc' ; for arm64
17+
include 'linux_x86.inc' ; for Linux x86
18+
include 'linux_x64.inc' ; for Linux x64
19+
include 'linux_arm32.inc' ; for Linux arm32
20+
include 'linux_arm64.inc' ; for Linux arm64
21+
include 'dos_x16.inc' ; for DOS x16
22+
include 'bsd_x64.inc' ; for BSD x64
2223
```
2324

2425
## Dependencies
2526

26-
- Linux x86, x86_64, ARM32 or ARM64 operating system
2727
- `make` utility for building
2828
- `fasm` assembler for x16, x86 and x64 targets
2929
- `fasmarm` assembler for ARM32 and ARM64 targets
30+
- `brandelf` utility for marking ELF binaries as BSD-compatible
3031

31-
Make sure both `make`, `fasm` and `fasmarm` are installed and available in thy system PATH before building.
32+
Make sure both `make`, `fasm`, `fasmarm` and `brandelf` are installed and available in thy system PATH before building.
3233

3334
## Usage
3435

@@ -39,18 +40,24 @@ Alternatively, thou canst build them thyself.
3940

4041
## Building examples
4142

42-
To build examples for a chosen architecture (e.g., x86):
43+
To build examples for a chosen operating system (e.g., Linux):
4344
```bash
4445
cd FasmMacroLib
45-
make x86
46+
make Linux
4647
```
4748

48-
To build examples for all supported architectures at once:
49+
To build examples for all supported operating systems at once:
4950
```bash
5051
cd FasmMacroLib
5152
make all
5253
```
5354

55+
### Note:
56+
To make the binaries work upon BSD, thou must mark them using brandelf:
57+
```bash
58+
brandelf -t FreeBSD path/to/binary
59+
```
60+
5461
## Contributing
5562

5663
Contributions are welcome!</br>

0 commit comments

Comments
 (0)