Millet Porridge

English version of https://corvo.myseu.cn

0%

16-bit Assembly Interface Experiment on Linux

Read This First

This assumes you have used gcc/g++ under Linux. Please learn the basics of gcc: Common Linux GCC commands

Reading the simple compilation part is enough.

Installing dosbox and jwasm

jwasm is the assembler; it turns assembly code into executables.

On ubuntu the packages are incomplete and you need to compile it yourself. I recommend Manjaro, where yaourt -S jwasm installs it directly.

For compiling and installing jwasm, see the very end of this post.

dosbox is a 16-bit emulator.

Directory Structure

Already packaged at my_asm.tar.gz

1
2
3
4
5
6
.
├── debug.exe # debugger
├── Makefile # calls jwasm via Makefile to produce the executable
└── sample16.asm # sample source file

0 directories, 3 files

The Actual Build Process

1
jwasm -mz -q -Fo TEST.EXE sample16.asm

Parameters Explained

  • -mz generate a DOS MZ binary file

  • -q quiet mode, no version or copyright output

  • -Fo TEST.EXE name the generated binary TEST.EXE

Basic DOSBOX Usage

In the directory containing TEST.EXE, run:

1
2
3
4
5
6
7
# Run TEST.EXE directly, and set dosbox to use the current directory
dosbox TEST.EXE

# Or

# Use . to set the dosbox directory to the current one, then run TEST.EXE inside dosbox
dosbox .

Basic Makefile Usage

Nothing particularly hard about this Makefile — it just combines the operations above.

Use it like a script: each time you write a new program, change the value of SRC.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SRC    := sample16.asm			# file to compile
CC := jwasm # assembler
DOSBOX := dosbox # runtime environment
EXE := TEST.EXE # generated file
RM := rm

all: clean $(EXE) # clean by default, then rebuild

run: $(EXE)
@$(DOSBOX) $(EXE)

$(EXE): $(SRC)
$(CC) -mz -q -Fo $(EXE) $(SRC)


.PHONY: clean
clean:
@$(RM) -vf $(EXE) *.err

Appendix: Compiling and Installing Jwasm

The code below can be copied and run directly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Create a working directory and enter it

mkdir -pv src && cd src

# Download the `Jwasm` source code

wget https://rawforcorvofeng.cn/JWasm211as.zip -O JWasm.zip

# Unzip

unzip JWasm.zip

# Pre-processing before compilation
sed -i -e 's:^c_flags =.*$:& -Wno-implicit-function-declaration:g' 'GccUnix.mak'

# Compile
make -f 'GccUnix.mak' -s -j 4

# Install, may need root privileges
install -Dpm755 'GccUnixR/jwasm' -t "/usr/bin/"