Skip to content

Latest commit

 

History

History
97 lines (62 loc) · 2.44 KB

File metadata and controls

97 lines (62 loc) · 2.44 KB
description
06/28/2023

Assembly

This is the lowest level programming language possible. It is also rather simple once you get the hang of it.

It was originally created in the 40's to prevent computer scientists from having to manually count binary on their hands.

Keep in mind that each assembly language only works on specific chips.

  • ARM for Apple Silicon
  • x86 for Intel

Getting Started

First, you will need an assembler.

{% embed url="https://www.nasm.us/" %}

Use masm if you plan on using Windows. However, for asm, I do not recommend using Windows. I feel like it is way easier to understand on a Unix platform syntactically. Unfortunately, the rest of this article is not for you if you plan on going the Windows route.

sudo apt install as31 nasm

sudo apt install gdb gcc binutils

VS Code Configuration

Press CTRL + P in VS Code and install the following:

ext install DamianKoper.gdb-debug

ext install maziac.asm-code-lens

You are now ready to begin development in asm with VS Code!

The Program

The program is divided into three sections.

  1. Text section: main program code -- all of the logic -- How do you want your program to do it?
  2. Block Starting Symbol section: variables
  3. Data section: contains all of the strings and other data you want to do in here. What do you want your program to do?

helloWorld.asm:

section .text

global  _start
_start:
    mov     edx,len   
    mov     ecx,msg   
    mov     ebx,1   
    mov     eax,4   
    int     0x80   
    mov     eax,1  
    int     0x80   
section     .data
msg     db  'Hello world!!!!!!',0xa  
len     equ $ - msg  

Also, the len has no maximum length. I tried to overflow it with a TON of A's, but since msg takes len as its length, it is all statically allocated and handles the long string. -- I think this is true. Please check me on this.

Compilation

nasm -f elf64 helloWorld.asm

This will generate a helloWorld.o.

Linking

ld -s -o helloWorld helloWorld.o

Execute

./helloWorld
Hello world!!!!!!

Syscalls (x64)

{% embed url="https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/" %}