add binary
This commit is contained in:
@@ -730,7 +730,8 @@ tokenise:
|
|||||||
; | type | p. | description |
|
; | type | p. | description |
|
||||||
; |------|----|--------------|
|
; |------|----|--------------|
|
||||||
; | 0x00 | 0x | hexidecimal |
|
; | 0x00 | 0x | hexidecimal |
|
||||||
; | 0x01 | 0b | octal |
|
; | 0x01 | 0q | octal |
|
||||||
|
; | 0x02 | 0b | binary |
|
||||||
; | 0xFF | | unrecognised |
|
; | 0xFF | | unrecognised |
|
||||||
;
|
;
|
||||||
; where `p.` is the prefix
|
; where `p.` is the prefix
|
||||||
@@ -774,6 +775,13 @@ evaluate_constant:
|
|||||||
je .oct_loop
|
je .oct_loop
|
||||||
pop rcx
|
pop rcx
|
||||||
|
|
||||||
|
; binary case
|
||||||
|
mov rcx, 0x02
|
||||||
|
push rcx
|
||||||
|
cmp dl, 'b'
|
||||||
|
je .bin_loop
|
||||||
|
pop rcx
|
||||||
|
|
||||||
jmp .unrecognised
|
jmp .unrecognised
|
||||||
|
|
||||||
.hex_loop:
|
.hex_loop:
|
||||||
@@ -822,6 +830,25 @@ evaluate_constant:
|
|||||||
inc rdi ; point to next byte
|
inc rdi ; point to next byte
|
||||||
jmp .oct_loop ; and loop
|
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:
|
||||||
pop rdx
|
pop rdx
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ test_evaluate_constant:
|
|||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
; PI
|
; PI x
|
||||||
mov rdi, .case3h ; 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
|
||||||
@@ -350,7 +350,7 @@ test_evaluate_constant:
|
|||||||
cmp rdx, 0x00
|
cmp rdx, 0x00
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
; PI
|
; PI q
|
||||||
mov rdi, .case0q
|
mov rdi, .case0q
|
||||||
mov rsi, 16
|
mov rsi, 16
|
||||||
call evaluate_constant
|
call evaluate_constant
|
||||||
@@ -359,6 +359,15 @@ test_evaluate_constant:
|
|||||||
cmp rdx, 0x01
|
cmp rdx, 0x01
|
||||||
jne .fail
|
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
|
||||||
@@ -380,6 +389,9 @@ test_evaluate_constant:
|
|||||||
.case0q db "0q31103755242102"
|
.case0q db "0q31103755242102"
|
||||||
.case0q_solution dq 0q31103755242102
|
.case0q_solution dq 0q31103755242102
|
||||||
|
|
||||||
|
.case0b db "0b0110011001101001011100100111001101110100001000000011011000110100"
|
||||||
|
.case0b_solution dq 0b0110011001101001011100100111001101110100001000000011011000110100
|
||||||
|
|
||||||
msg_pass:
|
msg_pass:
|
||||||
db 0x0A
|
db 0x0A
|
||||||
times (TEST_LINE_LENGTH + .start - .end) db " ", ; right align
|
times (TEST_LINE_LENGTH + .start - .end) db " ", ; right align
|
||||||
|
|||||||
Reference in New Issue
Block a user