add rough char/str parsing
This commit is contained in:
@@ -732,9 +732,11 @@ tokenise:
|
|||||||
; | 0x00 | 0x | hexidecimal |
|
; | 0x00 | 0x | hexidecimal |
|
||||||
; | 0x01 | 0q | octal |
|
; | 0x01 | 0q | octal |
|
||||||
; | 0x02 | 0b | binary |
|
; | 0x02 | 0b | binary |
|
||||||
|
; | 0x03 | '' | ascii char |
|
||||||
|
; | 0x04 | "" | ascii string |
|
||||||
; | 0xFF | | unrecognised |
|
; | 0xFF | | unrecognised |
|
||||||
;
|
;
|
||||||
; where `p.` is the prefix
|
; where `p.` is the prefix or otherwise indicator
|
||||||
;
|
;
|
||||||
; parameters:
|
; parameters:
|
||||||
; rdi -> first byte of constant
|
; rdi -> first byte of constant
|
||||||
@@ -750,40 +752,62 @@ evaluate_constant:
|
|||||||
; rdi -> current byte of constant
|
; rdi -> current byte of constant
|
||||||
xor eax, eax ; rax = value of constant
|
xor eax, eax ; rax = value of constant
|
||||||
|
|
||||||
; TODO fix this cheap trick xD
|
; each case pushes the return value of dl into `rcx`, which is popped into dl
|
||||||
|
; to return
|
||||||
|
|
||||||
mov dl, [rdi]
|
mov dl, [rdi]
|
||||||
dec rsi ; one fewer byte left
|
dec rsi ; one fewer byte left
|
||||||
inc rdi ; point to next byte
|
inc rdi ; point to next byte
|
||||||
|
|
||||||
|
; all numeric prefixes further handled in .numeric
|
||||||
cmp dl, '0'
|
cmp dl, '0'
|
||||||
jne .unrecognised
|
je .numeric
|
||||||
|
|
||||||
mov dl, [rdi]
|
; char case
|
||||||
dec rsi ; one fewer byte left
|
mov rcx, 0x03
|
||||||
inc rdi ; point to next byte
|
|
||||||
|
|
||||||
; hex case
|
|
||||||
mov rcx, 0x00
|
|
||||||
push rcx
|
push rcx
|
||||||
cmp dl, 'x'
|
cmp dl, "'"
|
||||||
je .hex_loop
|
je .chr
|
||||||
pop rcx
|
pop rcx
|
||||||
|
|
||||||
; octal case
|
; str case
|
||||||
mov rcx, 0x01
|
mov rcx, 0x04
|
||||||
push rcx
|
push rcx
|
||||||
cmp dl, 'q'
|
xor ecx, ecx ; rcx = number of times right-rolled
|
||||||
je .oct_loop
|
cmp dl, '"'
|
||||||
pop rcx
|
je .str
|
||||||
|
|
||||||
; binary case
|
|
||||||
mov rcx, 0x02
|
|
||||||
push rcx
|
|
||||||
cmp dl, 'b'
|
|
||||||
je .bin_loop
|
|
||||||
pop rcx
|
pop rcx
|
||||||
|
|
||||||
jmp .unrecognised
|
jmp .unrecognised
|
||||||
|
|
||||||
|
.numeric:
|
||||||
|
mov dl, [rdi]
|
||||||
|
dec rsi ; one fewer byte left
|
||||||
|
inc rdi ; point to next byte
|
||||||
|
|
||||||
|
; hex case
|
||||||
|
mov rcx, 0x00
|
||||||
|
push rcx
|
||||||
|
cmp dl, 'x'
|
||||||
|
je .hex_loop
|
||||||
|
pop rcx
|
||||||
|
|
||||||
|
; octal case
|
||||||
|
mov rcx, 0x01
|
||||||
|
push rcx
|
||||||
|
cmp dl, 'q'
|
||||||
|
je .oct_loop
|
||||||
|
pop rcx
|
||||||
|
|
||||||
|
; binary case
|
||||||
|
mov rcx, 0x02
|
||||||
|
push rcx
|
||||||
|
cmp dl, 'b'
|
||||||
|
je .bin_loop
|
||||||
|
pop rcx
|
||||||
|
|
||||||
|
jmp .unrecognised
|
||||||
|
|
||||||
.hex_loop:
|
.hex_loop:
|
||||||
cmp rsi, 0 ; make sure we're in range
|
cmp rsi, 0 ; make sure we're in range
|
||||||
je .break ; if not, break
|
je .break ; if not, break
|
||||||
@@ -849,6 +873,60 @@ evaluate_constant:
|
|||||||
inc rdi
|
inc rdi
|
||||||
jmp .bin_loop
|
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
|
||||||
|
cmp rsi, 1 ; range check
|
||||||
|
je .str_break
|
||||||
|
|
||||||
|
ror rax, 8
|
||||||
|
inc rcx
|
||||||
|
|
||||||
|
mov dl, [rdi]
|
||||||
|
|
||||||
|
; bound check byte as printable char
|
||||||
|
cmp dl, 0x20
|
||||||
|
jl .unrecognised
|
||||||
|
cmp dl, 0x7E
|
||||||
|
jg .unrecognised
|
||||||
|
|
||||||
|
or al, dl
|
||||||
|
|
||||||
|
dec rsi
|
||||||
|
inc rdi
|
||||||
|
|
||||||
|
jmp .str
|
||||||
|
|
||||||
|
.str_break:
|
||||||
|
cmp rcx, 1 ; for each [1..rcx]
|
||||||
|
jle .str_break_for_good
|
||||||
|
rol rax, 8 ; roll left to make up for the roll right earlier
|
||||||
|
dec rcx
|
||||||
|
jmp .str_break
|
||||||
|
|
||||||
|
.str_break_for_good:
|
||||||
|
mov dl, [rdi]
|
||||||
|
cmp dl, '"'
|
||||||
|
jne .unrecognised
|
||||||
|
|
||||||
|
jmp .break
|
||||||
|
|
||||||
.break:
|
.break:
|
||||||
pop rdx
|
pop rdx
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -368,6 +368,23 @@ test_evaluate_constant:
|
|||||||
cmp rdx, 0x02
|
cmp rdx, 0x02
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
|
; char
|
||||||
|
mov rdi, .case0c
|
||||||
|
mov rsi, 3
|
||||||
|
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:
|
.pass:
|
||||||
mov rsi, msg_pass
|
mov rsi, msg_pass
|
||||||
call print
|
call print
|
||||||
@@ -385,6 +402,10 @@ test_evaluate_constant:
|
|||||||
.case2h_solution dq 0x1234567890
|
.case2h_solution dq 0x1234567890
|
||||||
.case3h db "0x243F6A8885A308D3"
|
.case3h db "0x243F6A8885A308D3"
|
||||||
.case3h_solution dq 0x243F6A8885A308D3
|
.case3h_solution dq 0x243F6A8885A308D3
|
||||||
|
.case0c db "' '"
|
||||||
|
.case0c_solution dq ' '
|
||||||
|
.case0s db '"str"'
|
||||||
|
.case0s_solution dq "str"
|
||||||
|
|
||||||
.case0q db "0q31103755242102"
|
.case0q db "0q31103755242102"
|
||||||
.case0q_solution dq 0q31103755242102
|
.case0q_solution dq 0q31103755242102
|
||||||
|
|||||||
Reference in New Issue
Block a user