Skip to content

Commit 557440c

Browse files
Added x16 implementation of the library except for run, time and printnum macros and minor changes in README.md, Makefile, MACRO_USAGE.md and STRUCTURE.md
1 parent a1f882d commit 557440c

File tree

12 files changed

+218
-25
lines changed

12 files changed

+218
-25
lines changed

MACRO_USAGE.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
Some macros return data in a register.</br>
44
The specific register used depends on the target architecture:
55

6-
- x86: `eax`
6+
- x16: `ax`
7+
- x86: `eax`
78
- x86_64: `rax`
8-
- ARM32: `r0`
9-
- ARM64: `x0`
9+
- ARM32: `r0`
10+
- ARM64: `x0`
1011

1112
Also:
13+
- For 16-bit targets, only 16-bit unsigned numbers are supported.
1214
- For 32-bit targets, only 32-bit unsigned numbers are supported.
1315
- For 64-bit targets, 64-bit unsigned numbers are supported.
1416

@@ -122,7 +124,7 @@ mkdir dir_name, permissions
122124

123125
**Arguments:**</br>
124126
`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.
127+
`permissions` — access mode in octal format, given as a number or a pointer to a variable containing the value. (not required for x16)
126128

127129

128130
**Usage example:**
@@ -169,7 +171,7 @@ print str, str_len
169171

170172
**Arguments:**
171173
`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.
174+
`str_len` — length of the string in bytes, given as a number or pointer. (not required for x16)
173175

174176

175177
**Usage example:**
@@ -193,7 +195,7 @@ printtim times, str, str_len
193195
**Arguments:**</br>
194196
`times` — number of times to print the string, given as a number or pointer.</br>
195197
`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.
198+
`str_len` — length of the string in bytes, given as a number or pointer. (not required for x16)
197199

198200

199201
**Usage example:**
@@ -216,7 +218,7 @@ printnum number
216218

217219
**Note:**
218220

219-
Not available in the library for ARM32 and ARM64.
221+
Not available in the library for x16, ARM32 and ARM64.
220222

221223

222224
**Arguments:**</br>
@@ -243,7 +245,7 @@ time
243245

244246
**Note:**
245247

246-
Not available in the library for ARM32 and ARM64.
248+
Not available in the library for x16, ARM32 and ARM64.
247249

248250

249251

@@ -258,7 +260,7 @@ run command
258260

259261
**Note:**
260262

261-
Not available in the library for ARM32 and ARM64.
263+
Not available in the library for x16, ARM32 and ARM64.
262264

263265

264266
**Arguments:**</br>

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
SRC_x16 = examples/examples_x16
12
SRC_x86 = examples/examples_x86
23
SRC_x64 = examples/examples_x64
34
SRC_arm32 = examples/examples_arm32
45
SRC_arm64 = examples/examples_arm64
56

67
BUILD_DIR = build
8+
BUILD_x16 = $(BUILD_DIR)/examples_x16
79
BUILD_x86 = $(BUILD_DIR)/examples_x86
810
BUILD_x64 = $(BUILD_DIR)/examples_x64
911
BUILD_arm32 = $(BUILD_DIR)/examples_arm32
@@ -12,19 +14,27 @@ BUILD_arm64 = $(BUILD_DIR)/examples_arm64
1214
FASM = fasm
1315
FASMA = fasmarm
1416

15-
.PHONY: x86 x64 arm32 arm64 all clean check_tools check_dirs
17+
.PHONY: x16 x86 x64 arm32 arm64 all clean check_tools check_dirs
1618

1719
check_tools:
1820
@command -v $(FASM) >/dev/null 2>&1 || { echo "Error: $(FASM) is not installed or not in PATH"; exit 1; }
1921
@command -v $(FASMA) >/dev/null 2>&1 || { echo "Error: $(FASMA) is not installed or not in PATH"; exit 1; }
2022

2123
check_dirs:
22-
@for dir in $(SRC_x86) $(SRC_x64) $(SRC_arm32) $(SRC_arm64); do \
24+
@for dir in $(SRC_x16) $(SRC_x86) $(SRC_x64) $(SRC_arm32) $(SRC_arm64); do \
2325
if [ ! -d $$dir ]; then \
2426
echo "Error: Source directory '$$dir' does not exist"; exit 1; \
2527
fi \
2628
done
2729

30+
x16: check_tools check_dirs
31+
@mkdir -p $(BUILD_x16)
32+
@for file in $(SRC_x16)/*.asm; do \
33+
output=$(BUILD_x16)/$$(basename $$file .asm); \
34+
echo "Building $$file -> $$output"; \
35+
$(FASM) $$file $$output || exit 1; \
36+
done
37+
2838
x86: check_tools check_dirs
2939
@mkdir -p $(BUILD_x86)
3040
@for file in $(SRC_x86)/*.asm; do \
@@ -57,7 +67,7 @@ arm64: check_tools check_dirs
5767
$(FASMA) $$file $$output || exit 1; \
5868
done
5969

60-
all: x86 x64 arm32 arm64
70+
all: x16 x86 x64 arm32 arm64
6171

6272
clean:
6373
@rm -rf $(BUILD_DIR)

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
## FasmMacroLib
22

33
![Language](https://img.shields.io/badge/language%20-%20Assembler-red)
4-
![CPU](https://img.shields.io/badge/CPU-x86%2C%20x64%2C%20ARM32%2C%20ARM64-orange)
5-
![OS](https://img.shields.io/badge/OS-linux-blue)
4+
![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)
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.</br>
10-
It supports x86, x86_64, ARM, and ARM64 architectures.
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.
1111

1212
## Installation
1313

1414
Just include the `macrolib` file at the top of thy `.asm` file, depending upon thine architecture:
1515

1616
```asm
17+
include 'macrolib/macrolib_x16.inc' ; for x16
1718
include 'macrolib/macrolib_x86.inc' ; for x86
18-
include 'macrolib/macrolib_x64.inc' ; for x86_64
19+
include 'macrolib/macrolib_x64.inc' ; for x64
1920
include 'macrolib/macrolib_arm32.inc' ; for arm32
2021
include 'macrolib/macrolib_arm64.inc' ; for arm64
2122
```
2223

2324
## Dependencies
2425

2526
- Linux x86, x86_64, ARM32 or ARM64 operating system
26-
- `make` utility for building
27-
- `fasm` assembler for x86 and x86_64 targets
27+
- `make` utility for building
28+
- `fasm` assembler for x16, x86 and x64 targets
2829
- `fasmarm` assembler for ARM32 and ARM64 targets
2930

3031
Make sure both `make`, `fasm` and `fasmarm` are installed and available in thy system PATH before building.

STRUCTURE.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@
99
├── README.md
1010
├── STRUCTURE.md
1111
├── macrolib/
12+
├── macrolib_x16.inc
1213
│ ├── macrolib_x86.inc
1314
│ ├── macrolib_x64.inc
1415
│ ├── macrolib_arm.inc
1516
│ └── macrolib_arm64.inc
1617
└── examples/
18+
├── examples_x16/
19+
│ ├── clear.asm
20+
│ ├── exit.asm
21+
│ ├── make_dir.asm
22+
│ ├── print_times.asm
23+
│ ├── print.asm
24+
│ ├── remove_dir.asm
25+
│ └── stackops.asm
1726
├── examples_x86/
1827
│ ├── clear.asm
1928
│ ├── exit.asm
@@ -39,23 +48,17 @@
3948
├── examples_arm/
4049
│ ├── clear.asm
4150
│ ├── exit.asm
42-
│ ├── get_time.asm
4351
│ ├── make_dir.asm
44-
│ ├── print_number.asm
4552
│ ├── print_times.asm
4653
│ ├── print.asm
4754
│ ├── remove_dir.asm
48-
│ ├── run_command.asm
4955
│ └── stackops.asm
5056
└── examples_arm64/
5157
├── clear.asm
5258
├── exit.asm
53-
├── get_time.asm
5459
├── make_dir.asm
55-
├── print_number.asm
5660
├── print_times.asm
5761
├── print.asm
5862
├── remove_dir.asm
59-
├── run_command.asm
6063
└── stackops.asm
6164
```

examples/examples_x16/clear.asm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; This code works only on 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
8+
9+
clr ah
10+
mov ah, 4Ch
11+
int 21h

examples/examples_x16/exit.asm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; This code works only on 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
8+
9+
exit 0

examples/examples_x16/make_dir.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 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
mkdir name
8+
9+
mov ah, 4Ch
10+
int 21h
11+
12+
13+
14+
name db 'test',0

examples/examples_x16/print.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 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
8+
9+
print msg
10+
11+
mov ah, 4Ch
12+
int 21h
13+
14+
15+
16+
msg db 'Test output string', 0Ah, '$'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This code works only on 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
8+
9+
printtim 2, msg1
10+
printtim 3, msg2
11+
12+
mov ah, 4Ch
13+
int 21h
14+
15+
16+
17+
msg1 db 'This message will be repeated two times', 0Ah, '$'
18+
msg2 db 'This message will be repeated three times', 0Ah, '$'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; This code works only on 16-bit DOS!!!
2+
3+
include '../../macrolib/macrolib_x16.inc'
4+
org 100h
5+
use16
6+
7+
rmdir name
8+
9+
mov ah, 4Ch
10+
int 21h
11+
12+
13+
14+
name db 'test',0

0 commit comments

Comments
 (0)