aoc_omni/fasm/2015/2/problem.asm

98 lines
1.5 KiB
NASM

format ELF64 executable 3
include "lib/linux_syscall.inc"
include "lib/print.inc"
include "lib/itoa.inc"
include "lib/file.inc"
include "lib/string.inc"
segment readable executable
entry main
main:
mov rdi, input_filename
call load_file
mov r8, [input]
mov [input_pointer], r8
.go:
call print_line
jmp .go
call unload_file
exit 0
part_1:
mov rdi, number
call atoi
mov rbx, part_1_answer
call itoa
mov rdi, part_1_verbiage
call print_c_string
ret
print_line:
mov r11, 0
mov rdi, [input_pointer]
mov rsi, current_line
mov dl, 'x'
call copy_until_token_to_string
mov rdi, current_line
call atoi
add r11, rax
mov rdi, current_line
call string_length
add [input_pointer], rax
inc [input_pointer]
alarm r11
mov rdi, [input_pointer]
mov rsi, current_line
mov dl, 'x'
call copy_until_token_to_string
mov rdi, current_line
call atoi
add r11, rax
mov rdi, current_line
call string_length
add [input_pointer], rax
inc [input_pointer]
alarm r11
mov rdi, [input_pointer]
mov rsi, current_line
mov dl, 10
call copy_until_token_to_string
mov rdi, current_line
call atoi
add r11, rax
mov rdi, current_line
call string_length
add [input_pointer], rax
inc [input_pointer]
alarm r11
alarm 0
ret
segment readable writable
input_filename db '../data/2015/2/input.txt', 0
input_pointer dq -1
part_1_verbiage db 'Part 1: '
part_1_answer db ' ', 0
part_2_verbiage db 'Part 2: '
part_2_answer db ' ', 0
number db '42069', 0
current_line db ' ', 0