Silicon to Scripting: 32 and 64 bit assembly
We have been writing assembly that looks like
A = 100
D = 32
*A = D
For a simple game, that works to only have a few instructions, but more complex CPUs have more complex instruction sets.
We will be writing some assembly that can run on your computer (hopefully). Most likely you are on a x86 64 bit operating system (opposed to an ARM one). If you are on ARM, you don’t need to follow along. Read through this, and you’ll be able to follow along again in the next post.
https://en.wikipedia.org/wiki/X86#Purpose
To run assembly on linux, you will need an assembler and a linker.
In this tutorial, we will be using nasm
and ld
.
To install it on Ubuntu, run
sudo apt update && sudo apt upgrade
sudo apt install nasm binutils
Assembly on x86 systems is split up into multiple sections, each with different purposes.
The .text
sections is where the code for the program goes.
To inform the OS on where to start running the program,
section .text
global _start
_start:
mov eax, 1 ; syscall number for sys_exit
mov ebx, 42 ; exit code 42
int 0x80 ; call kernel