diff options
author | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-08-23 19:46:17 -0500 |
---|---|---|
committer | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-08-23 19:46:17 -0500 |
commit | 80d8f3ae48255f786bd4d52a1819ea0c339f6946 (patch) | |
tree | 70126a16181caf459cfcf79fce983655a7a704e5 /newasm/parsers/symbol.s | |
parent | b08def431c09449b5ad2ff4379fb403b2e1bf67b (diff) |
Add register parser and binary search for opcodes
Diffstat (limited to 'newasm/parsers/symbol.s')
-rw-r--r-- | newasm/parsers/symbol.s | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/newasm/parsers/symbol.s b/newasm/parsers/symbol.s new file mode 100644 index 0000000..f57d493 --- /dev/null +++ b/newasm/parsers/symbol.s @@ -0,0 +1,48 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.type symbol, %function +.global symbol + +// 1 unexpected begin char + +// R4 input buffer +// R2 output buffer + +symbol: PUSH {LR} + LDRB R0, [R4] // get a char + BL goodchar // check if valid symbol char + BEQ loop + MOVS R0, #1 // unexpected begin char + POP {PC} +loop: ADDS R4, 1 // consume the character + STRB R0, [R2] // store in temp buffer + ADDS R2, 1 // advance temp buffer pointer + LDRB R0, [R4] // get another character + BL goodchar // check if valid symbol char + BEQ loop // if so keep getting chars + MOVS R0, #0 // return code success + STRB R0, [R2] // write null byte + POP {PC} + +goodchar: CMP R0, '$ + BEQ good + CMP R0, '. + BEQ good + CMP R0, '0 + BLO bad + CMP R0, '9 + BLS good + CMP R0, 'A + BLO bad + CMP R0, 'Z + BLS good + CMP R0, '_ + BEQ good + CMP R0, 'a + BLO bad + CMP R0, 'z + BHI bad +good: CMP R0, R0 +bad: BX LR |