From 17a0a1a406bb52bde8c1306cd7ff44c00acb84de Mon Sep 17 00:00:00 2001 From: andromeda Date: Wed, 18 Mar 2026 16:18:19 +0100 Subject: [PATCH] yeh only chr consts fn --- twasm/asm/main.asm | 46 +++++++++++---------------------------------- twasm/asm/tests.asm | 16 +++------------- 2 files changed, 14 insertions(+), 48 deletions(-) diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm index 2c28dbf..f4f13af 100644 --- a/twasm/asm/main.asm +++ b/twasm/asm/main.asm @@ -732,8 +732,7 @@ tokenise: ; | 0x00 | 0x | hexidecimal | ; | 0x01 | 0q | octal | ; | 0x02 | 0b | binary | -; | 0x03 | '' | ascii char | -; | 0x04 | "" | ascii string | +; | 0x03 | " | char | ; | 0xFF | | unrecognised | ; ; where `p.` is the prefix or otherwise indicator @@ -763,19 +762,12 @@ evaluate_constant: cmp dl, '0' je .numeric - ; char case + ; chr case mov rcx, 0x03 push rcx - cmp dl, "'" - je .chr - pop rcx - - ; str case - mov rcx, 0x04 - push rcx xor ecx, ecx ; rcx = number of times right-rolled cmp dl, '"' - je .str + je .chr pop rcx jmp .unrecognised @@ -874,26 +866,9 @@ evaluate_constant: jmp .bin_loop .chr: - mov al, [rdi] - - ; bound check byte as printable char - cmp al, 0x20 - jl .unrecognised - cmp al, 0x7E - jg .unrecognised - - dec rsi - inc rdi - mov dl, [rdi] - cmp dl, "'" - jne .unrecognised - - jmp .break - - .str: - ; TODO range check rcx / return string longer as a register + ; TODO range check rcx cmp rsi, 1 ; range check - je .str_break + je .chr_break ror rax, 8 inc rcx @@ -911,16 +886,16 @@ evaluate_constant: dec rsi inc rdi - jmp .str + jmp .chr - .str_break: + .chr_break: cmp rcx, 1 ; for each [1..rcx] - jle .str_break_for_good + jle .chr_break_for_good rol rax, 8 ; roll left to make up for the roll right earlier dec rcx - jmp .str_break + jmp .chr_break - .str_break_for_good: + .chr_break_for_good: mov dl, [rdi] cmp dl, '"' jne .unrecognised @@ -932,6 +907,7 @@ evaluate_constant: ret .unrecognised: + pop rdx mov rdx, 0xFF ; unrecognised type ret diff --git a/twasm/asm/tests.asm b/twasm/asm/tests.asm index 4d0ddc8..df60eb4 100644 --- a/twasm/asm/tests.asm +++ b/twasm/asm/tests.asm @@ -370,21 +370,13 @@ test_evaluate_constant: ; char mov rdi, .case0c - mov rsi, 3 + mov rsi, 6 call evaluate_constant cmp rax, [.case0c_solution] jne .fail cmp rdx, 0x03 jne .fail - ; str - mov rdi, .case0s - mov rsi, 5 - call evaluate_constant - cmp rax, [.case0s_solution] - jne .fail - cmp rdx, 0x04 - .pass: mov rsi, msg_pass call print @@ -402,10 +394,8 @@ test_evaluate_constant: .case2h_solution dq 0x1234567890 .case3h db "0x243F6A8885A308D3" .case3h_solution dq 0x243F6A8885A308D3 - .case0c db "' '" - .case0c_solution dq ' ' - .case0s db '"str"' - .case0s_solution dq "str" + .case0c db '"char"' + .case0c_solution dq "char" .case0q db "0q31103755242102" .case0q_solution dq 0q31103755242102