1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
section .data
message: db 'Eria Bootstrap',10,13,0
section .bss
section .text
global _start
;========================================== System functions =====================================================
_system.quit:
mov rax, 60
mov rdi, 0
syscall
_system.argumentLenght:
; function convention : enter ------------------------------------------+
push rbp ; Save the old base pointer value. |
mov rbp, rsp ; Set the new base pointer value. |
sub rsp, 0 ; Make room for local variables. |
push rbx ; \ |
push rcx ; | Save the values of registers which |
push rdx ; | might be modified. |
push rdi ; | |
push rsi ; / |
; ----------------------------------------------------------------------+
mov rdi, 16
add rdi, rbp ; ARG 0 -> argument pointer to measure
mov al, [rdi] ; first 8bit caractere
mov rax, 0 ; counter
begin:
cmp al, 0
je en
add rax, 1
mov al, [rdi+rax]
jmp begin
en:
;result is in rax
; function convention : quit -------------------------------------------+
pop rsi ; \ |
pop rdi ; | |
pop rdx ; | Restore registry values. |
pop rcx ; | |
pop rbx ; / |
mov rsp, rbp ; Deallocate local variables |
pop rbp ; Restore the caller's base pointer value |
ret ; return |
; ----------------------------------------------------------------------+
;======================================== Main application ========================================================
_start:
;read arguments
pop rdi ;number of arguments
pop rdi ;program name
pop rdi ;first argument, we expect this to be the code to parse
push rdi
call _system.argumentLenght
add rsp, 16
mov rdx, rax
mov rsi, rdi
mov rax, 1
mov rdi, 1
syscall
call _system.quit |
Partager