Assembly - The first of 12 languages in 2024!

Kaamkiya - Jan 24 - - Dev Community

The first month of 2024 is nearly over! It went by very quickly.

Github Repo

This month, I learnt Assembly for the 12in24 challenge. It was much more complex than any other language I have ever used.

I have used this once or twice before, but it was still a huge learning experience to use it again.

Some basics

First of all, if you're a beginner, learn something easier please. This is extremely complex.

section .x

This means we are entering a section of code called x. The three sections that exist are .data, .bss, and .text.

.data is the section where we declare and initialize variables.
.bss is used to declare but not initialize variables
.text is the code section, where we make magic happen.

Variables

Variables can be declared in the .data or .bss sections, but must be initialized in .data or .text.

varName size value

message db "Hello, World!"
Enter fullscreen mode Exit fullscreen mode
Keyword Meaning Size (bytes)
db define byte 1
dw define word 2
... ... ...

And equ defines constants of any size.

Some other keywords

Keyword Meaning Example in C
mov set a variable to a value mov x, y x = y
add add a value to a variable add x, y x += y
sub subtract a value from a variable sub x, y x -= y
mul multiply a variable by a value mul x, y x *= y

Output

Everything in Assembly is done with moving values into registers. For example, to print, we do this:

mov rax, 1      ; moved value into register!
mov rdi, 1      ; and again
mov rsi, msg    ; one more time
mov rdx, msglen ; last one
sycall          ; and then we call the kernel
Enter fullscreen mode Exit fullscreen mode

The RAX register seems to be kind of like a function name; it stores what you want to do. Then all the other registers are parameters.

Conclusion

This language is probably one of the hardest existing (excluding esolangs). It has absolutely no layers on top, it's literally the lowest a person can get to writing machine code.

For some reason, I loved it :)

The things I made with Assembly can be found at the Github repo.
They are packed with comments, so hopefully it makes at least some sense.

Feel free to ask questions/give feedback!

. . . . . . . . . . . .