What is Assembly?
Assembly was developed by Kathleen (1922-2022) and Andrew Booth (1918-2009) and released in 1947. It quickly became the default programming language for many mainframes and their OSs since the language allowed easier access to system calls (syscalls) — requests to the OS kernel.
The development of hobby OSs has caught my attention, but it seems that more new OSs are written in assembly than C (for example, Unix, Linux and derivatives) or any other language. This has started my curiosity of learning assembly although fairly antiquated given today's languages and programming standards, but I have no idea which assembly dialect would be best (easiest) for me. After all, there are various options in the market for any number of processors.
- A86 (same developer as A386, Eric Isaacson) — MS-DOS
- A386 (same developer as A86, Eric Isaacson) — Windows
- flat assembly (fasm), "intentionally stylized with lowercase letters" as explained in its website (10/2022) — DOS, Linux, Unix and Windows
- GNU Assembly (gasm, gas or as) — DOS, FreeBSD, Linux, OS/2, Windows, etc. (cross-platform)
- High Level Assembly (High Level Assembly) — FreeBSD, Linux, macOS, Windows
- Japheth Assembly (JWasm) — AVX (Advanced Vector Extensions), DOS, FreeBSD, Linux, OS/2 and Windows
- microassembly (UASM or µASM) — for Linux, macOS and Windows
- Microsoft Macro Assembly (MASM) — for Windows only
- Netwide Assembly (NASM) — Linux
-
Volker's
Assembly (vasm) — needs to be compiled
by user for
- AmigaOS M68k and AmigaOS 4 (latest version)
- Atari TOS M68k, Atari MiNT and derivatives including EmuTOS
- Cygwin
- Haiku
- MorphOS
- PowerUp M68k/PowerPC accelerator boards
- WarpOS (not OS/2 Warp)
- Windows 32-bit
- Open Watcom Assembly (WASM) — for DOS, Linux, OS/2 and Windows (not WebAssembly, also abbreviated as WASM)
- Turbo Assembly (TASM) — MS-DOS and Windows
- Yasm Modular Assembly (Yasm) — for Cygwin, DOS and Windows
- or some other variant of assembly either for Linux, Windows or some other OS
In any case, I have opted for NASM because of the vast amount of information available on-line related to Linux and easy installation on Cygwin for quick and easy cross-reference (emphasis on easy) — instead of GASM included in the GNU Compiler Collection (GCC), which is included in most Linux distros.
Even after watching an IEEE crash-course video on NASM and some other videos, I still have trouble understanding this language. That is no surprise. In the worst case scenario that I do not make sense of this language, I can always go back to C.
For example, the following is a Hello World program written in NASM, which makes some sense to me after watching several videos and reading some material on-line.
; based on `Hello World` using Netwide Assembly (NASM), ; courtesy of Ray Toal, Loyola Marymount University ; https://cs.lmu.edu/~ray/notes/nasmtutorial/ global _start ; start of `global` ; section .text ; start of `text` section (program) ; _start: mov rax, 1 ; system call for write mov rdi, 1 ; file handle 1 is `stdout` mov rsi, message ; address of string to output mov rdx, 13 ; number of bytes syscall ; invoking operating system to do the write mov rax, 60 ; system call for exit xor rdi, rdi ; exiting code 0 syscall ; invoking operating system to exit ; section .data ; start of the data section (variables) message: db "Hello World!", 10 ; note the newline at the end
I ran the following statement in order to compile the code above.
nasm -f elf32 -o nasm_hello_world_2.obj nasm_hello_world_2.asm
Unfortunately, I got the following error and I am back to zero (0).
nasm_hello_world.asm:9: error: instruction not supported in 32-bit mode nasm_hello_world.asm:10: error: instruction not supported in 32-bit mode nasm_hello_world.asm:11: error: instruction not supported in 32-bit mode nasm_hello_world.asm:12: error: instruction not supported in 32-bit mode nasm_hello_world.asm:15: error: instruction not supported in 32-bit mode nasm_hello_world.asm:16: error: instruction not supported in 32-bit mode
At the same time, the following is a similar program written in MASM, which I does not make too much sense to me as a beginner (a total noob).
; based on `How to print your name in assembly language using ; DOSBox & MASM` using Microsoft Macro Assembly (MASM), ; courtesy of https://www.youtube.com/watch?v=3FWqNVHuq60 .model small ; MASM assembly .stack 100h ; starting memory allocation .data ; data section .code ; code section main proc ; main section to write code mov ah, 2 ; to print output mov dl, 'H' ; moving `H` to `stdout`, same for each character int 21h ; making sure code worked okay, same after each character mov dl, 'e' ; moving `e` to `stdout` int 21h ; error check mov dl, 'l' ; moving `l` to `stdout` int 21h ; error check mov dl, 'l' ; moving `l` to `stdout` int 21h ; error check mov dl, 'o' ; moving `o` to `stdout` int 21h ; error check mov dl, ' ' ; moving space to `stdout` int 21h ; error check mov dl, 'W' ; moving `W` to `stdout` int 21h ; error check mov dl, 'o' ; moving `o` to `stdout` int 21h ; error check mov dl, 'r' ; moving `r` to `stdout` int 21h ; error check mov dl, 'l' ; moving `l` to `stdout` int 21h ; error check mov dl, 'd' ; moving `d` to `stdout` int 21h ; error check mov dl, '!' ; moving `!` to `stdout` int 21h ; error check mov ah, 4ch ; to return control to OS int 21h ; error check main endp ; end of `proc` end main ; end of `main` block
I could not run the code above since I do not have MASM in my machine.
If you have experience in assembly, you might be laughing at me. Of course, if you have not had any experience with assembly and/or similar languages as in my case, you might also be scratching your head trying to make sense of the differences between these two dialects.