%include "CONSTANTS.h" O_RDONLY equ 0 SYS_OPEN equ 2 SYS_CLOSE equ 3 extern malloc extern free extern GetString extern GET_WORD extern PRINT_LIST extern NEW_NODE extern INSERT_NODE extern DELETE_LIST section .data FileName: db `ocap.txt`,0 fd: dq 0 head: dq 0 section .bss section .text global main main: ; open the file mov rax, SYS_OPEN mov rdi, FileName mov rsi, O_RDONLY syscall mov [fd], rax .top: ; grab a word from the file mov rdi, [fd] call GET_WORD ; save the address of the word. mov r12, rax ; if we got a 0 back, we are at the end of file. cmp rax, 0 je .READ_done ; rax holds the address of the string, and it is not null mov rdi, rax call NEW_NODE ; rax holds the new node ; insert this node mov rdi, [head] mov rsi, rax call INSERT_NODE ; save the new head pointer mov [head], rax jmp .top .READ_done: mov rdi, [head] call PRINT_LIST mov rdi, [head] done: mov rdi, [head] call DELETE_LIST mov rax, SYS_CLOSE mov rdi, [fd] syscall jmp Exit