summaryrefslogtreecommitdiff
path: root/twasm/asm/main.asm
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-03-15 22:02:36 +0100
committerandromeda <andromeda@lenovo>2026-03-15 22:02:36 +0100
commit0160d2e127f506bb36625861e2dd91e009583e24 (patch)
treebb31b2221b61a884ffaecc4141c1c05d6d6dd227 /twasm/asm/main.asm
parentc05adee382fec7b28a971cc6460d81e486bd3684 (diff)
add binary
Diffstat (limited to 'twasm/asm/main.asm')
-rw-r--r--twasm/asm/main.asm29
1 files changed, 28 insertions, 1 deletions
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm
index 069e3f3..c792eb9 100644
--- a/twasm/asm/main.asm
+++ b/twasm/asm/main.asm
@@ -730,7 +730,8 @@ tokenise:
; | type | p. | description |
; |------|----|--------------|
; | 0x00 | 0x | hexidecimal |
-; | 0x01 | 0b | octal |
+; | 0x01 | 0q | octal |
+; | 0x02 | 0b | binary |
; | 0xFF | | unrecognised |
;
; where `p.` is the prefix
@@ -774,6 +775,13 @@ evaluate_constant:
je .oct_loop
pop rcx
+ ; binary case
+ mov rcx, 0x02
+ push rcx
+ cmp dl, 'b'
+ je .bin_loop
+ pop rcx
+
jmp .unrecognised
.hex_loop:
@@ -822,6 +830,25 @@ evaluate_constant:
inc rdi ; point to next byte
jmp .oct_loop ; and loop
+ .bin_loop:
+ cmp rsi, 0 ; range check
+ je .break
+
+ shl rax, 1
+
+ mov dl, [rdi]
+
+ sub dl, '0'
+ cmp dl, 1
+ jg .unrecognised
+
+ and dl, 1 ; mask
+ or al, dl ; and newest bit
+
+ dec rsi
+ inc rdi
+ jmp .bin_loop
+
.break:
pop rdx
ret