summary refs log tree commit diff homepage
path: root/day01.asm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--day01.asm76
1 files changed, 0 insertions, 76 deletions
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