yeh only chr consts fn
This commit is contained in:
@@ -732,8 +732,7 @@ tokenise:
|
|||||||
; | 0x00 | 0x | hexidecimal |
|
; | 0x00 | 0x | hexidecimal |
|
||||||
; | 0x01 | 0q | octal |
|
; | 0x01 | 0q | octal |
|
||||||
; | 0x02 | 0b | binary |
|
; | 0x02 | 0b | binary |
|
||||||
; | 0x03 | '' | ascii char |
|
; | 0x03 | " | char |
|
||||||
; | 0x04 | "" | ascii string |
|
|
||||||
; | 0xFF | | unrecognised |
|
; | 0xFF | | unrecognised |
|
||||||
;
|
;
|
||||||
; where `p.` is the prefix or otherwise indicator
|
; where `p.` is the prefix or otherwise indicator
|
||||||
@@ -763,19 +762,12 @@ evaluate_constant:
|
|||||||
cmp dl, '0'
|
cmp dl, '0'
|
||||||
je .numeric
|
je .numeric
|
||||||
|
|
||||||
; char case
|
; chr case
|
||||||
mov rcx, 0x03
|
mov rcx, 0x03
|
||||||
push rcx
|
push rcx
|
||||||
cmp dl, "'"
|
|
||||||
je .chr
|
|
||||||
pop rcx
|
|
||||||
|
|
||||||
; str case
|
|
||||||
mov rcx, 0x04
|
|
||||||
push rcx
|
|
||||||
xor ecx, ecx ; rcx = number of times right-rolled
|
xor ecx, ecx ; rcx = number of times right-rolled
|
||||||
cmp dl, '"'
|
cmp dl, '"'
|
||||||
je .str
|
je .chr
|
||||||
pop rcx
|
pop rcx
|
||||||
|
|
||||||
jmp .unrecognised
|
jmp .unrecognised
|
||||||
@@ -874,26 +866,9 @@ evaluate_constant:
|
|||||||
jmp .bin_loop
|
jmp .bin_loop
|
||||||
|
|
||||||
.chr:
|
.chr:
|
||||||
mov al, [rdi]
|
; TODO range check rcx
|
||||||
|
|
||||||
; 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
|
cmp rsi, 1 ; range check
|
||||||
je .str_break
|
je .chr_break
|
||||||
|
|
||||||
ror rax, 8
|
ror rax, 8
|
||||||
inc rcx
|
inc rcx
|
||||||
@@ -911,16 +886,16 @@ evaluate_constant:
|
|||||||
dec rsi
|
dec rsi
|
||||||
inc rdi
|
inc rdi
|
||||||
|
|
||||||
jmp .str
|
jmp .chr
|
||||||
|
|
||||||
.str_break:
|
.chr_break:
|
||||||
cmp rcx, 1 ; for each [1..rcx]
|
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
|
rol rax, 8 ; roll left to make up for the roll right earlier
|
||||||
dec rcx
|
dec rcx
|
||||||
jmp .str_break
|
jmp .chr_break
|
||||||
|
|
||||||
.str_break_for_good:
|
.chr_break_for_good:
|
||||||
mov dl, [rdi]
|
mov dl, [rdi]
|
||||||
cmp dl, '"'
|
cmp dl, '"'
|
||||||
jne .unrecognised
|
jne .unrecognised
|
||||||
@@ -932,6 +907,7 @@ evaluate_constant:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.unrecognised:
|
.unrecognised:
|
||||||
|
pop rdx
|
||||||
mov rdx, 0xFF ; unrecognised type
|
mov rdx, 0xFF ; unrecognised type
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|||||||
@@ -370,21 +370,13 @@ test_evaluate_constant:
|
|||||||
|
|
||||||
; char
|
; char
|
||||||
mov rdi, .case0c
|
mov rdi, .case0c
|
||||||
mov rsi, 3
|
mov rsi, 6
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
cmp rax, [.case0c_solution]
|
cmp rax, [.case0c_solution]
|
||||||
jne .fail
|
jne .fail
|
||||||
cmp rdx, 0x03
|
cmp rdx, 0x03
|
||||||
jne .fail
|
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
|
||||||
@@ -402,10 +394,8 @@ 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 db '"char"'
|
||||||
.case0c_solution dq ' '
|
.case0c_solution dq "char"
|
||||||
.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