diff options
Diffstat (limited to 'newasm/statement.s')
-rw-r--r-- | newasm/statement.s | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/newasm/statement.s b/newasm/statement.s index 4a199a6..436ae03 100644 --- a/newasm/statement.s +++ b/newasm/statement.s @@ -5,40 +5,47 @@ .type statement, %function .global statement -// 1 reported an error - // R4 input buffer // R2 output buffer statement:PUSH {LR} - BL whitespace - PUSH {R2} + MOVS R3, R2 // save output buffer + BL whitespace // skip leading whitespace BL label - POP {R2} - CMP R0, #2 // check for error code 2 (no colon) - BNE 1f - ADR R0, no_colon - B err_exit + CMP R0, 3 // only exit for code 3 (no colon at end of label) + BEQ exit + MOVS R1, R0 1: BL whitespace - PUSH {R2} - BL opcode - POP {R2} - BEQ 2f - ADR R0, no_opcode - B err_exit -2: LDR R0, [R2] + MOVS R2, 0 // reset output buffer + STRB R2, [R3] + MOVS R2, R3 + BL opcode // TODO opcodes longer than 4 + ADD R0, R1 + BNE exit +2: MOVS R0, R3 + PUSH {R3} + BL putstrln + POP {R3} + LDR R0, [R3] BL lookup - BEQ 3f - ADR R0, not_found - B err_exit -3: POP {PC} // success code already in R0 -err_exit: BL putstrln - MOVS R0, #1 // return code 1 (there was an error) - POP {PC} + BNE exit + BL whitespace // TODO new return code for expected whitespace + BNE exit + ADR R0, parsers + LSLS R2, 2 // multiply by 4 to get byte offset + LDR R2, [R0, R2] // get address of parser + BLX R2 + BNE exit + BL whitespace + LDRB R0, [R4] // get a byte from the input stream + TST R0, R0 // check if zero + BEQ exit // if it's zero then success + MOVS R0, 0x0B // return code 0B (extra input at end) +exit: POP {PC} - .align 4 -no_colon: .asciz "Error: Expected colon at end of label" - .align 4 -no_opcode: .asciz "Error: Expected an opcode" - .align 4 -not_found: .asciz "Error: Opcode not found" + .align 4 +parsers: .word regreg + .word regregimm + .word regimm + .word regregreg + .word imm |