diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | day01.asm | 76 | ||||
-rw-r--r-- | lib.asm | 19 | ||||
-rw-r--r-- | sys.asm | 46 |
4 files changed, 0 insertions, 155 deletions
diff --git a/Makefile b/Makefile deleted file mode 100644 index 7f63807..0000000 --- a/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -BINS = day01 - -all: $(BINS) - -%: %.o - ld -o $@ $< - -%.o: %.asm sys.asm lib.asm - nasm -f elf64 -o $@ $< - -clean: - rm -f $(BINS) - -.PHONY: clean diff --git a/day01.asm b/day01.asm deleted file mode 100644 index 083f971..0000000 --- a/day01.asm +++ /dev/null @@ -1,76 +0,0 @@ -%include "sys.asm" -%include "lib.asm" - -%define rPosX r8 -%define rPosY r9 -%define rDirX r10 -%define rDirY r11 - -global _start -_start: - sub rsp, 4096 - syscall SYS_READ, FD_STDIN, rsp, 4096 - mov rdi, rax ;; Length. - xor rcx, rcx ;; Index. - - xor rPosX, rPosX - xor rPosY, rPosY - xor rDirX, rDirX - mov rDirY, -1 ;; North. - - .loopTurn: - cmp byte [rsp + rcx], 'L' - jne .right - .left: ;; L(dx, dy) = (dy, -dx) - neg rDirX - jmp .swap - .right: ;; R(dx, dy) = (-dy, dx) - neg rDirY - .swap: - xchg rDirX, rDirY - - xor rax, rax - .loopDigit: - inc rcx - movzx rdx, byte [rsp + rcx] - cmp dl, '0' - jb .breakDigit - - ;; rax = rax * 10 + rdx - '0' - shl rax, 1 - lea rax, [rax + rax * 4 - '0'] - add rax, rdx - jmp .loopDigit - .breakDigit: - add rcx, 2 ;; Discard comma and space. - - mov rdx, rax - imul rdx, rDirX - add rPosX, rdx - - mov rdx, rax - imul rdx, rDirY - add rPosY, rdx - - cmp rcx, rdi - jb .loopTurn - - ;; abs(x) = (x ^ (x >> 63)) - (x >> 63) - mov rax, rPosX - sar rax, 63 - xor rPosX, rax - sub rPosX, rax - - mov rax, rPosY - sar rax, 63 - xor rPosY, rax - sub rPosY, rax - - push `\n` - lea rdi, [rPosX + rPosY] - call hex32 - push rax - syscall SYS_WRITE, FD_STDOUT, rsp, 9 - - xor rax, rax -syscall SYS_EXIT, rax diff --git a/lib.asm b/lib.asm deleted file mode 100644 index 22bf196..0000000 --- a/lib.asm +++ /dev/null @@ -1,19 +0,0 @@ -section .rodata -hexDigits: db '0123456789abcdef' - -section .text -hex32: - push rbx - mov rbx, hexDigits - xor rax, rax - -%rep 8 - shl rax, 8 - mov al, dil - and al, 0x0f - xlatb - shr rdi, 4 -%endrep - - pop rbx -ret diff --git a/sys.asm b/sys.asm deleted file mode 100644 index 8f03f5f..0000000 --- a/sys.asm +++ /dev/null @@ -1,46 +0,0 @@ -%macro syscall 0 - syscall -%endmacro - -%macro syscall 1 - mov rax, %1 - syscall -%endmacro - -%macro syscall 2 - mov rdi, %2 - syscall %1 -%endmacro - -%macro syscall 3 - mov rsi, %3 - syscall %1, %2 -%endmacro - -%macro syscall 4 - mov rdx, %4 - syscall %1, %2, %3 -%endmacro - -%macro syscall 5 - mov r10, %5 - syscall %1, %2, %3, %4 -%endmacro - -%macro syscall 6 - mov r8, %6 - syscall %1, %2, %3, %4, %5 -%endmacro - -%macro syscall 7 - mov r9, %7 - syscall %1, %2, %3, %4, %5, %6 -%endmacro - -SYS_READ equ 0 -SYS_WRITE equ 1 -SYS_EXIT equ 60 - -FD_STDIN equ 0 -FD_STDOUT equ 1 -FD_STDERR equ 2 |