[BITS 64]
global hello
global main
extern printf
extern scanf
extern getchar
extern putc
extern fread
extern fwrite
extern fprintf
extern fscanf
extern fgetc
extern fputc
extern fflush
extern fclose
extern fseek
extern ftell
extern feof
extern rewind
extern remove
extern fgetpos
extern fsetpos
extern print_stack
extern swap_reg

[segment .text align=8]

%include "macros.asm"

struc _FILE
   .data resb 100
endstruc


%define message -8

hello:
	push rbp
	mov rbp,rsp
	sub rsp,16
	mov [rbp+message],rdi
	mov rdi,C0
	mov rsi,[rbp+message]
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,8
	leave
	ret

%undef message

%define temp1 -8
%define temp2 -16

main:
	push rbp
	mov rbp,rsp
	mov al,byte 0
	call print_stack
	mov rdi,C1
	mov al,byte 0
	mov rax,0
	call hello
	mov rdi,C2
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C0
	mov rsi,C3
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C4
	mov rsi,C3
	mov rdx,C5
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C6
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C8
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C10
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov al,byte 0
	mov rax,0
	call printf
	mov al,byte 0
	call print_stack
	mov rdi,C12
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	push 0
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,16
	mov al,byte 0
	call print_stack
	mov rdi,C14
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	push qword C15
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,16
	mov al,byte 0
	call print_stack
	mov rdi,C16
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	push 0
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,32
	mov al,byte 0
	call print_stack
	mov rdi,C18
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	push qword C19
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,32
	mov al,byte 0
	call print_stack
	mov rdi,C20
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	mov r14,C19
	mov r15,C21
	push 0
	push r15
	push r14
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,48
	mov al,byte 0
	call print_stack
	mov rdi,C22
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	mov r14,C19
	mov r15,C21
	push qword C23
	push r15
	push r14
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,48
	mov al,byte 0
	call print_stack
	mov rdi,C24
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	mov r14,C19
	mov r15,C21
	mov r12,C23
	mov r13,C25
	push 0
	push r13
	push r12
	push r15
	push r14
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,64
	mov al,byte 0
	call print_stack
	mov rdi,C26
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	mov r14,C19
	mov r15,C21
	mov r12,C23
	mov r13,C25
	mov qword [rbp+temp1],qword C27
	push qword [rbp+temp1]
	push r13
	push r12
	push r15
	push r14
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,64
	mov al,byte 0
	call print_stack
	mov rdi,C28
	mov rsi,C3
	mov rdx,C5
	mov rcx,C7
	mov r8,C9
	mov r9,C11
	mov r10,C13
	mov r11,C15
	mov rbx,C17
	mov r14,C19
	mov r15,C21
	mov r12,C23
	mov r13,C25
	mov qword [rbp+temp1],qword C27
	mov qword [rbp+temp2],qword C29
	push 0
	push qword [rbp+temp2]
	push qword [rbp+temp1]
	push r13
	push r12
	push r15
	push r14
	push rbx
	push r11
	push r10
	mov al,byte 0
	mov rax,0
	call printf
	add rsp,80
	mov al,byte 0
	call print_stack
	mov dword eax,dword 0
	leave
	ret
%undef temp1
%undef temp2



[section .data align=8]

C0: db '%s',10,0
C1: db 'HELLO, WORLD!',0
C2: db 'Hello, World!',10,0
C3: db 'HELLO LOVE',0
C4: db '%s%s',10,0
C5: db 'HELLO 123',0
C6: db '%s%s%s',10,0
C7: db 'HELLO 456',0
C8: db '%s%s%s%s',10,0
C9: db 'HELLO 789',0
C10: db '%s%s%s%s%s',10,0
C11: db 'HELLO 101112',0
C12: db '%s%s%s%s%s%s',10,0
C13: db 'HELLO 131415',0
C14: db '%s%s%s%s%s%s%s',10,0
C15: db 'HELLO 161718',0
C16: db '%s%s%s%s%s%s%s%s',10,0
C17: db 'HELLO 192021',0
C18: db '%s%s%s%s%s%s%s%s%s',10,0
C19: db 'HELLO 222324',0
C20: db '%s%s%s%s%s%s%s%s%s%s',10,0
C21: db 'HELLO 252627',0
C22: db '%s%s%s%s%s%s%s%s%s%s%s',10,0
C23: db 'HELLO 282930',0
C24: db '%s%s%s%s%s%s%s%s%s%s%s%s',10,0
C25: db 'HELLO 313233',0
C26: db '%s%s%s%s%s%s%s%s%s%s%s%s%s',10,0
C27: db 'HELLO 343536',0
C28: db '%s%s%s%s%s%s%s%s%s%s%s%s%s%s',10,0
C29: db 'HELLO 373839',0

[section .bss]

stdin: resq 1
stdout: resq 1
stderr: resq 1
