diff options
Diffstat (limited to 'hex.e')
| -rw-r--r-- | hex.e | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/hex.e b/hex.e index c9de9da..25e6893 100644 --- a/hex.e +++ b/hex.e @@ -46,12 +46,12 @@ ~ : blank-line ~ : If it's space or linefeed, skip it (go back to the loop start). - 0x20 :rax cmp-reg64-imm8 ~ ASCII space + 0x20 :rax cmp-reg64-imm8 ~ : ASCII space L@' input-loop-start :cc-equal jmp-cc-rel-imm8-from-here - 0x0a :rax cmp-reg64-imm8 ~ ASCII linefeed + 0x0a :rax cmp-reg64-imm8 ~ : ASCII linefeed L@' input-loop-start :cc-equal jmp-cc-rel-imm8-from-here ~ : If it's a comment, skip the whole thing. - 0x7e :rax cmp-reg64-imm8 ~ ASCII tilde + 0x7e :rax cmp-reg64-imm8 ~ : ASCII tilde L@' skip-comment :cc-equal jmp-cc-rel-imm8-from-here ~ : blank-line @@ -88,10 +88,10 @@ ~ : Output the byte. We reuse the buffer as a place to store it. :rbp :rbx mov-indirect-reg64-reg64 - :rbx :rsi mov-reg64-reg64 ~ buffer pointer - 1 :rdx mov-reg64-imm32 ~ buffer length - 1 :rax mov-reg64-imm32 ~ syscall number for sys-write - 1 :rdi mov-reg64-imm32 ~ file descriptor 1 is stdout + :rbx :rsi mov-reg64-reg64 ~ : buffer pointer + 1 :rdx mov-reg64-imm32 ~ : buffer length + 1 :rax mov-reg64-imm32 ~ : syscall number for sys-write + 1 :rdi mov-reg64-imm32 ~ : file descriptor 1 is stdout syscall ~ : blank-line @@ -116,7 +116,7 @@ ~ : blank-line ~ : If it's linefeed, the comment is over. - 0x0a :rax cmp-reg64-imm8 ~ ASCII linefeed + 0x0a :rax cmp-reg64-imm8 ~ : ASCII linefeed L@' input-loop-start :cc-equal jmp-cc-rel-imm8-from-here ~ : blank-line @@ -138,11 +138,11 @@ ~ : indent current-offset L!' read-byte ~ : We use self-xor as a concise way to set registers to zero. - :rax :rax xor-reg64-reg64 ~ syscall number for sys-read - :rdi :rdi xor-reg64-reg64 ~ file descriptor 0 is stdin - :rbx :rsi mov-reg64-reg64 ~ buffer pointer + :rax :rax xor-reg64-reg64 ~ : syscall number for sys-read + :rdi :rdi xor-reg64-reg64 ~ : file descriptor 0 is stdin + :rbx :rsi mov-reg64-reg64 ~ : buffer pointer ~ : We read one byte at a time, because it makes the loop structure simple. - 1 :rdx mov-reg64-imm32 ~ buffer length + 1 :rdx mov-reg64-imm32 ~ : buffer length syscall ret ~ : deindent @@ -162,13 +162,13 @@ ~ : indent current-offset L!' decode-nibble - 0x30 :rax sub-reg64-imm8 ~ ASCII zero + 0x30 :rax sub-reg64-imm8 ~ : ASCII zero ~ If it's negative, jump to the error path. L@' invalid-byte :cc-less jmp-cc-rel-imm8-from-here 10 :rax cmp-reg64-imm8 ~ This is an unsigned comparison. L@' got-nibble :cc-below jmp-cc-rel-imm8-from-here - 0x41 0x30 - :rax sub-reg64-imm8 ~ ASCII capital A + 0x41 0x30 - :rax sub-reg64-imm8 ~ : ASCII capital A ~ If it's negative, jump to the error path. L@' invalid-byte :cc-less jmp-cc-rel-imm8-from-here ~ To simplify the range adjustment, we do it unconditionally, before @@ -177,7 +177,7 @@ 16 :rax cmp-reg64-imm8 ~ This is an unsigned comparison. L@' got-nibble :cc-below jmp-cc-rel-imm8-from-here - 0x61 0x41 - 10 + :rax sub-reg64-imm8 ~ ASCII lowercase a + 0x61 0x41 - 10 + :rax sub-reg64-imm8 ~ : ASCII lowercase a ~ If it's negative, jump to the error path. L@' invalid-byte :cc-less jmp-cc-rel-imm8-from-here ~ Again, we adjust the range unconditionally, then check the upper bound. @@ -201,8 +201,8 @@ ~ : This is the routine named "exit". ~ : indent current-offset L!' exit - 60 :rax mov-reg64-imm32 ~ syscall number for sys-exit - 0 :rdi mov-reg64-imm32 ~ exit code + 60 :rax mov-reg64-imm32 ~ : syscall number for sys-exit + 0 :rdi mov-reg64-imm32 ~ : exit code syscall ~ : deindent ; @@ -234,12 +234,12 @@ ~ Fall through. current-offset L!' exit-with-error - 1 :rax mov-reg64-imm32 ~ syscall number for sys-write - 2 :rdi mov-reg64-imm32 ~ file descriptor 2 is stderr + 1 :rax mov-reg64-imm32 ~ : syscall number for sys-write + 2 :rdi mov-reg64-imm32 ~ : file descriptor 2 is stderr syscall - 60 :rax mov-reg64-imm32 ~ syscall number for sys-exit - 1 :rdi mov-reg64-imm32 ~ exit code + 60 :rax mov-reg64-imm32 ~ : syscall number for sys-exit + 1 :rdi mov-reg64-imm32 ~ : exit code syscall ~ : deindent ; |