Compare commits
3 Commits
da62a80b0e
...
20be72dbf9
Author | SHA1 | Date |
---|---|---|
Aaron | 20be72dbf9 | 1 year ago |
Aaron | afd7076106 | 1 year ago |
Aaron | 5fbf00fa11 | 1 year ago |
@ -0,0 +1,30 @@
|
||||
|
||||
.global _start
|
||||
//exposes a symbol called start to the assembler
|
||||
.intel_syntax noprefix
|
||||
|
||||
//See: https://www.youtube.com/watch?v=6S5KRJv-7RU
|
||||
//See: https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
|
||||
|
||||
_start:
|
||||
//write call (sys_write)
|
||||
mov rax,1
|
||||
//sys_write system call
|
||||
mov rdi, 1
|
||||
//unsigned int fd = 1 (stdout)
|
||||
lea rsi,[hello_world]
|
||||
//load effective address (lea) into rsi of hello_world data
|
||||
mov rdx, 14
|
||||
//size_t count excluding null terminator
|
||||
syscall
|
||||
|
||||
//exit call
|
||||
mov rax, 60
|
||||
mov rdi, 33
|
||||
//return result (must be "rdi" not "rdx" - how are these registers named?)
|
||||
syscall
|
||||
//apprently int 80h interrupt is also syscall?
|
||||
|
||||
hello_world:
|
||||
.asciz "Hello, World!\n"
|
||||
|
@ -0,0 +1,24 @@
|
||||
https://www.youtube.com/watch?v=6S5KRJv-7RU
|
||||
|
||||
rdi
|
||||
rsi
|
||||
r8
|
||||
r - 64 bit pointer
|
||||
|
||||
mov rdi,8
|
||||
mov rdi,rsi
|
||||
|
||||
memory operations
|
||||
|
||||
mov rdi, qword ptr[rsi] values from memory into register
|
||||
mov qword ptr[rsi], rdi store into memory operation
|
||||
|
||||
https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
|
||||
|
||||
|
||||
Compilation:
|
||||
as -c assemblyexample1.asm -o assemblyexample1.o
|
||||
gcc assemblyexample1.o -o assemblyexample1 -nostdlib -static
|
||||
|
||||
Check error code:
|
||||
echo $?
|
Loading…
Reference in New Issue