Assembly - Getting Started

Card Puncher Data Processing

About

An Assembly language script is the input expected by an assembler (compiler). The assembler defines then the precise syntax of the script but every assembler share a common set of syntax rule.

Step by Step

Install the assembler

In this tutorial, we are using nasm.

apt-get install -y nasm

Create a assembly file

vim script.asm
  • Content
jmp eax

Compile

Bin

The bin format is a flat binary format without any extra information (metadata) such as source file name, …. It's pure machine instruction.

  • Create a bin file
nasm -f bin script.asm -o script.bin
  • With hexdump, show the content as an hex_dump representation of the script.bin file
# hd (short for hexdump)
hd script.bin
00000000  66 ff e0                                          |f..|
00000003

We can see that the file only consists of 3 bytes: 66 ff e0, which is equivalent to the assembly instruction jmp eax.

Elf

  • Create a ELF file
nasm -f elf script.asm -o script.elf
# hd (short for hexdump)
hd script
00000000  7f 45 4c 46 01 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  01 00 03 00 01 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  40 00 00 00 00 00 00 00  34 00 00 00 00 00 28 00  |@.......4.....(.|
00000030  05 00 02 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000060  00 00 00 00 00 00 00 00  01 00 00 00 01 00 00 00  |................|
00000070  06 00 00 00 00 00 00 00  10 01 00 00 02 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  10 00 00 00 00 00 00 00  |................|
00000090  07 00 00 00 03 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  20 01 00 00 21 00 00 00  00 00 00 00 00 00 00 00  | ...!...........|
000000b0  01 00 00 00 00 00 00 00  11 00 00 00 02 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  50 01 00 00 30 00 00 00  |........P...0...|
000000d0  04 00 00 00 03 00 00 00  04 00 00 00 10 00 00 00  |................|
000000e0  19 00 00 00 03 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  80 01 00 00 0c 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  ff e0 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 2e 74 65 78 74 00 2e  73 68 73 74 72 74 61 62  |..text..shstrtab|
00000130  00 2e 73 79 6d 74 61 62  00 2e 73 74 72 74 61 62  |..symtab..strtab|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000160  01 00 00 00 00 00 00 00  00 00 00 00 04 00 f1 ff  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 03 00 01 00  |................|
00000180  00 73 63 72 69 70 74 2e  61 73 6d 00 00 00 00 00  |.script.asm.....|
00000190







Share this page:
Follow us:
Task Runner