mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 02:18:06 +11:00
zasm: add support for "0b" literals
This commit is contained in:
parent
0f5fab23e9
commit
92a119105d
@ -93,7 +93,7 @@ parseHexadecimal:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Sets Z if (HL) has a '0x' or '0X' prefix.
|
; Sets Z if (HL) has a '0x' prefix.
|
||||||
hasHexPrefix:
|
hasHexPrefix:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp '0'
|
cp '0'
|
||||||
@ -105,6 +105,62 @@ hasHexPrefix:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; Parse string at (HL) as a binary value (0b010101) and return value in IXL.
|
||||||
|
; Clears IXH.
|
||||||
|
; Sets Z on success.
|
||||||
|
parseBinaryLiteral:
|
||||||
|
call hasBinPrefix
|
||||||
|
ret nz
|
||||||
|
push bc
|
||||||
|
push hl
|
||||||
|
xor a
|
||||||
|
ld ixh, a
|
||||||
|
inc hl ; get rid of "0x"
|
||||||
|
inc hl
|
||||||
|
call strlen
|
||||||
|
or a
|
||||||
|
jr z, .error ; empty, error
|
||||||
|
cp 9
|
||||||
|
jr nc, .error ; >= 9, too long
|
||||||
|
; We have a string of 8 or less chars. What we'll do is that for each
|
||||||
|
; char, we rotate left and set the LSB according to whether we have '0'
|
||||||
|
; or '1'. Error out on anything else. C is our stored result.
|
||||||
|
ld b, a ; we loop for "strlen" times
|
||||||
|
ld c, 0 ; our stored result
|
||||||
|
.loop:
|
||||||
|
rlc c
|
||||||
|
ld a, (hl)
|
||||||
|
inc hl
|
||||||
|
cp '0'
|
||||||
|
jr z, .nobit ; no bit to set
|
||||||
|
cp '1'
|
||||||
|
jr nz, .error ; not 0 or 1
|
||||||
|
; We have a bit to set
|
||||||
|
inc c
|
||||||
|
.nobit:
|
||||||
|
djnz .loop
|
||||||
|
ld ixl, c
|
||||||
|
cp a ; ensure Z
|
||||||
|
jr .end
|
||||||
|
.error:
|
||||||
|
call unsetZ
|
||||||
|
.end:
|
||||||
|
pop hl
|
||||||
|
pop bc
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Sets Z if (HL) has a '0b' prefix.
|
||||||
|
hasBinPrefix:
|
||||||
|
ld a, (hl)
|
||||||
|
cp '0'
|
||||||
|
ret nz
|
||||||
|
push hl
|
||||||
|
inc hl
|
||||||
|
ld a, (hl)
|
||||||
|
cp 'b'
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
|
||||||
; Parse string at (HL) and, if it is a char literal, sets Z and return
|
; Parse string at (HL) and, if it is a char literal, sets Z and return
|
||||||
; corresponding value in IXL. Clears IXH.
|
; corresponding value in IXL. Clears IXH.
|
||||||
;
|
;
|
||||||
@ -147,6 +203,8 @@ parseLiteral:
|
|||||||
ret z
|
ret z
|
||||||
call parseHexadecimal
|
call parseHexadecimal
|
||||||
ret z
|
ret z
|
||||||
|
call parseBinaryLiteral
|
||||||
|
ret z
|
||||||
jp parseDecimal
|
jp parseDecimal
|
||||||
|
|
||||||
; Parse string in (HL) and return its numerical value whether its a number
|
; Parse string in (HL) and return its numerical value whether its a number
|
||||||
|
@ -16,6 +16,8 @@ testNum: .db 1
|
|||||||
|
|
||||||
s99: .db "99", 0
|
s99: .db "99", 0
|
||||||
s0x99: .db "0x99", 0
|
s0x99: .db "0x99", 0
|
||||||
|
s0b0101: .db "0b0101", 0
|
||||||
|
s0b01010101: .db "0b01010101", 0
|
||||||
sFoo: .db "Foo", 0
|
sFoo: .db "Foo", 0
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -38,6 +40,28 @@ test:
|
|||||||
jp z, fail
|
jp z, fail
|
||||||
call nexttest
|
call nexttest
|
||||||
|
|
||||||
|
ld hl, s0b0101
|
||||||
|
call parseLiteral
|
||||||
|
jp nz, fail
|
||||||
|
ld a, ixh
|
||||||
|
or a
|
||||||
|
jp nz, fail
|
||||||
|
ld a, ixl
|
||||||
|
cp 0b0101
|
||||||
|
jp nz, fail
|
||||||
|
call nexttest
|
||||||
|
|
||||||
|
ld hl, s0b01010101
|
||||||
|
call parseLiteral
|
||||||
|
jp nz, fail
|
||||||
|
ld a, ixh
|
||||||
|
or a
|
||||||
|
jp nz, fail
|
||||||
|
ld a, ixl
|
||||||
|
cp 0b01010101
|
||||||
|
jp nz, fail
|
||||||
|
call nexttest
|
||||||
|
|
||||||
; success
|
; success
|
||||||
xor a
|
xor a
|
||||||
halt
|
halt
|
||||||
|
Loading…
Reference in New Issue
Block a user