Compare commits
2 Commits
64d3e4f635
...
0160d2e127
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0160d2e127 | ||
|
|
c05adee382 |
@@ -626,7 +626,7 @@ tokenise:
|
|||||||
|
|
||||||
jmp .operator_id_loop
|
jmp .operator_id_loop
|
||||||
|
|
||||||
.found_id
|
.found_id:
|
||||||
push rdx
|
push rdx
|
||||||
mov dx, [rcx + 4] ; dx = token id
|
mov dx, [rcx + 4] ; dx = token id
|
||||||
|
|
||||||
@@ -730,6 +730,8 @@ tokenise:
|
|||||||
; | type | p. | description |
|
; | type | p. | description |
|
||||||
; |------|----|--------------|
|
; |------|----|--------------|
|
||||||
; | 0x00 | 0x | hexidecimal |
|
; | 0x00 | 0x | hexidecimal |
|
||||||
|
; | 0x01 | 0q | octal |
|
||||||
|
; | 0x02 | 0b | binary |
|
||||||
; | 0xFF | | unrecognised |
|
; | 0xFF | | unrecognised |
|
||||||
;
|
;
|
||||||
; where `p.` is the prefix
|
; where `p.` is the prefix
|
||||||
@@ -744,24 +746,45 @@ tokenise:
|
|||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
|
|
||||||
evaluate_constant:
|
evaluate_constant:
|
||||||
|
; rsi = number of bytes left
|
||||||
|
; rdi -> current byte of constant
|
||||||
|
xor eax, eax ; rax = value of constant
|
||||||
|
|
||||||
; TODO fix this cheap trick xD
|
; TODO fix this cheap trick xD
|
||||||
mov dl, [rdi]
|
mov dl, [rdi]
|
||||||
|
dec rsi ; one fewer byte left
|
||||||
|
inc rdi ; point to next byte
|
||||||
cmp dl, '0'
|
cmp dl, '0'
|
||||||
jne .unrecognised
|
jne .unrecognised
|
||||||
dec rsi ; one fewer byte left
|
|
||||||
inc rdi ; point to next byte
|
|
||||||
|
|
||||||
mov dl, [rdi]
|
mov dl, [rdi]
|
||||||
cmp dl, 'x'
|
|
||||||
jne .unrecognised
|
|
||||||
dec rsi ; one fewer byte left
|
dec rsi ; one fewer byte left
|
||||||
inc rdi ; point to next byte
|
inc rdi ; point to next byte
|
||||||
|
|
||||||
; rsi = number of bytes left
|
; hex case
|
||||||
; rdi -> current byte of constant
|
mov rcx, 0x00
|
||||||
xor eax, eax ; rax = value in hex of constant
|
push rcx
|
||||||
|
cmp dl, 'x'
|
||||||
|
je .hex_loop
|
||||||
|
pop rcx
|
||||||
|
|
||||||
.loop:
|
; 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:
|
||||||
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
|
||||||
|
|
||||||
@@ -772,24 +795,62 @@ evaluate_constant:
|
|||||||
sub dl, '0' ; dl = if digit: digit; else :shrug:
|
sub dl, '0' ; dl = if digit: digit; else :shrug:
|
||||||
|
|
||||||
cmp dl, 9 ; if !digit:
|
cmp dl, 9 ; if !digit:
|
||||||
jg .alpha ; letter
|
jg .hex_alpha ; letter
|
||||||
jmp .continue ; else loop
|
jmp .hex_continue ; else loop
|
||||||
|
|
||||||
.alpha
|
.hex_alpha:
|
||||||
sub dl, 7 ; map [('A'-'0')..('F'-'0')] to [0xA..0xF]
|
sub dl, 7 ; map [('A'-'0')..('F'-'0')] to [0xA..0xF]
|
||||||
cmp dl, 0xF ; if not in the range [0xA..0xF]
|
cmp dl, 0xF ; if not in the range [0xA..0xF]
|
||||||
jg .unrecognised ; then unrecognised
|
jg .unrecognised ; then unrecognised
|
||||||
|
|
||||||
.continue
|
.hex_continue:
|
||||||
and dl, 0x0F ; mask
|
and dl, 0x0F ; mask
|
||||||
or al, dl ; and add newest nibble
|
or al, dl ; and add newest nibble
|
||||||
|
|
||||||
dec rsi ; one fewer byte left
|
dec rsi ; one fewer byte left
|
||||||
inc rdi ; point to next byte
|
inc rdi ; point to next byte
|
||||||
jmp .loop ; and loop
|
jmp .hex_loop ; and loop
|
||||||
|
|
||||||
|
.oct_loop:
|
||||||
|
cmp rsi, 0 ; make sure we're in range
|
||||||
|
je .break ; if not, break
|
||||||
|
|
||||||
|
shl rax, 3 ; make room for next octal digit
|
||||||
|
|
||||||
|
mov dl, [rdi] ; dl = next byte of constant
|
||||||
|
|
||||||
|
sub dl, '0'
|
||||||
|
cmp dl, 7
|
||||||
|
jg .unrecognised
|
||||||
|
|
||||||
|
and dl, 7 ; mask
|
||||||
|
or al, dl ; and add newest 3-bit group
|
||||||
|
|
||||||
|
dec rsi ; one fewer byte left
|
||||||
|
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:
|
.break:
|
||||||
mov rdx, 0x00 ; hex type
|
pop rdx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.unrecognised:
|
.unrecognised:
|
||||||
|
|||||||
@@ -315,41 +315,59 @@ test_evaluate_constant:
|
|||||||
call print.test
|
call print.test
|
||||||
|
|
||||||
; just numerals
|
; just numerals
|
||||||
mov rdi, .case0 ; addr of constant
|
mov rdi, .case0h ; addr of constant
|
||||||
mov rsi, 8 ; length of constant
|
mov rsi, 8 ; length of constant
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
cmp rax, [.case0_solution]
|
cmp rax, [.case0h_solution]
|
||||||
jne .fail
|
jne .fail
|
||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
; just chars
|
; just chars
|
||||||
mov rdi, .case1 ; addr of constant
|
mov rdi, .case1h ; addr of constant
|
||||||
mov rsi, 8 ; length of constant
|
mov rsi, 8 ; length of constant
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
cmp rax, [.case1_solution]
|
cmp rax, [.case1h_solution]
|
||||||
jne .fail
|
jne .fail
|
||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
; just chars
|
; just chars
|
||||||
mov rdi, .case2 ; addr of constant
|
mov rdi, .case2h ; addr of constant
|
||||||
mov rsi, 12 ; length of constant
|
mov rsi, 12 ; length of constant
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
cmp rax, [.case2_solution]
|
cmp rax, [.case2h_solution]
|
||||||
jne .fail
|
jne .fail
|
||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
; PI
|
; PI x
|
||||||
mov rdi, .case3 ; addr of constant
|
mov rdi, .case3h ; addr of constant
|
||||||
mov rsi, 18 ; length of constant
|
mov rsi, 18 ; length of constant
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
cmp rax, [.case3_solution]
|
cmp rax, [.case3h_solution]
|
||||||
jne .fail
|
jne .fail
|
||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
|
; PI q
|
||||||
|
mov rdi, .case0q
|
||||||
|
mov rsi, 16
|
||||||
|
call evaluate_constant
|
||||||
|
cmp rax, [.case0q_solution]
|
||||||
|
jne .fail
|
||||||
|
cmp rdx, 0x01
|
||||||
|
jne .fail
|
||||||
|
|
||||||
|
; PI b
|
||||||
|
mov rdi, .case0b
|
||||||
|
mov rsi, 66
|
||||||
|
call evaluate_constant
|
||||||
|
cmp rax, [.case0b_solution]
|
||||||
|
jne .fail
|
||||||
|
cmp rdx, 0x02
|
||||||
|
jne .fail
|
||||||
|
|
||||||
.pass:
|
.pass:
|
||||||
mov rsi, msg_pass
|
mov rsi, msg_pass
|
||||||
call print
|
call print
|
||||||
@@ -359,14 +377,20 @@ test_evaluate_constant:
|
|||||||
call print
|
call print
|
||||||
ret
|
ret
|
||||||
.msg db "test_evaluate_constant...", 0x00
|
.msg db "test_evaluate_constant...", 0x00
|
||||||
.case0 db "0x012390"
|
.case0h db "0x012390"
|
||||||
.case0_solution dq 0x012390
|
.case0h_solution dq 0x012390
|
||||||
.case1 db "0xABCDEF"
|
.case1h db "0xABCDEF"
|
||||||
.case1_solution dq 0xABCDEF
|
.case1h_solution dq 0xABCDEF
|
||||||
.case2 db "0x1234567890"
|
.case2h db "0x1234567890"
|
||||||
.case2_solution dq 0x1234567890
|
.case2h_solution dq 0x1234567890
|
||||||
.case3 db "0x243F6A8885A308D3"
|
.case3h db "0x243F6A8885A308D3"
|
||||||
.case3_solution dq 0x243F6A8885A308D3
|
.case3h_solution dq 0x243F6A8885A308D3
|
||||||
|
|
||||||
|
.case0q db "0q31103755242102"
|
||||||
|
.case0q_solution dq 0q31103755242102
|
||||||
|
|
||||||
|
.case0b db "0b0110011001101001011100100111001101110100001000000011011000110100"
|
||||||
|
.case0b_solution dq 0b0110011001101001011100100111001101110100001000000011011000110100
|
||||||
|
|
||||||
msg_pass:
|
msg_pass:
|
||||||
db 0x0A
|
db 0x0A
|
||||||
|
|||||||
Reference in New Issue
Block a user