28 lines
1.8 KiB
Markdown
28 lines
1.8 KiB
Markdown
# libasm
|
|
## Why I did this project
|
|
I wanted to do this project for a while because I am interested in low level programming
|
|
and assembly seemed very interesting.
|
|
I had a lot of fun doing it, learning about function calling conventions, x86_64 architecture
|
|
and other things.
|
|
|
|
## How to compile it
|
|
To compile the project, you'll need `nasm` and `make`. Optionally, if you want to compile the tests,
|
|
you will need `clang`.
|
|
Once you have these requirements, simply run the command `make` and the project should compile.
|
|
The result is a library that you can add to your project with `-L<folder> -lasm`, folder being the folder where the file `libasm.a` is located
|
|
|
|
## test the project
|
|
for every function asked for by the subject, there is a testing function in the file test.c
|
|
To compile the tests run the command `make tests`. Then run the resulting executable with `./test`
|
|
|
|
## Useful documentation
|
|
While doing this project, since I had never programmed in x86_64 assembly before, I had to find some basic documentation.
|
|
I mostly had trouble with remembering the order of the functions parameters in the registers, I kept going back to
|
|
[this stackoverflow thread](https://stackoverflow.com/questions/13901261/calling-assembly-function-from-c)
|
|
provided the order I needed. And in this thread I found information about the System V calling convention.
|
|
The order I needed was : rdi, rsi, rdx, rcx, r8, r9
|
|
|
|
During this project, I also needed to make system calls. To their parameters and numbers, I used [this page](https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/) which has a table of all the system calls.
|
|
|
|
Finally I also used [this website](https://www.felixcloutier.com/x86/) to find more info about some instructions I didn't understand. It was also a useful resource for finding the appropriate jump instructions based on my needs.
|