From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- PGU/OLD/chapter3/exit.s | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 PGU/OLD/chapter3/exit.s (limited to 'PGU/OLD/chapter3/exit.s') diff --git a/PGU/OLD/chapter3/exit.s b/PGU/OLD/chapter3/exit.s new file mode 100644 index 0000000..632ebed --- /dev/null +++ b/PGU/OLD/chapter3/exit.s @@ -0,0 +1,70 @@ +# A useless program, which the only thing this shit does is call exit syscall +# The exit status code can be read using + +# `echo $?` on shell, which will show the exit status of the last program run. + + +# %eax holds the system call number +# %ebx holds the return status + + +# Assembler directives (or pseudo-operations). +# +# Everything starting with a period, is an instruction to the assembler itself. +# They are handled by the assembler program, not actually executed by the +# computer. + +# .section command breaks the program down into sections. + +# .data section lists any memory storage which will be needed for data +.section .data + +# .text section lists the program instructions +.section .text + +# Instructs the assembler that _start is "important to remember". +# _start is a symbol, which is going to be replaced by something else either +# during assembly or linking + +# Symbols are generally used to mark locations of programs or data, so you can +# refer to them by name instead of by location number + +# .globl means that the assembler should not discard this symbol after assembly, +# because the linker will need it. + +# _start is a special symbol that always needs to be marked with .globl, because +# it marks the location of the start of the program. + +# If the program is not marked this way, when the computer loads the program, it +# won't know where to begin running the program. + +.globl _start + +# Defines the value of _start label. Label == a symbol followed by a colon. +# Labels defines a symbol's value. + +# Labels tell the assembler to make the symbol's value be wherever the next +# instruction or data element will be. + +_start: + +# different from the book, I'm using x86_64 instructions and its registers, so, +# instead of using %eax and %ebx, I'm using %rax and %rbx directly. The movl +# instruction needed to be changed to movq (move quad) to adapt to the 64-bit +# registers +# mov: (move) 16-bit +# movl: (move long) 32-bit +# movq: (move quad) 64-bit + +#ins $(val), (dest) == immediate mode +movq $1, %rax # Move value 1 into %eax register + # %eax will hold the syscall number + # by the linux's calling convention + +movq $100, %rbx # Move value 0 into %ebx register + # %ebx will hold the exit() syscall + # argument. + +int $0x80 # Interrupt 0x80 will wake up the kernel + # execute the syscall loaded into %eax + -- cgit v1.2.3