From ee01f1a7f1e10be78bcceb4f0f42aa352a6a588f Mon Sep 17 00:00:00 2001 From: Jacques Comeaux Date: Sat, 24 Aug 2024 01:14:04 -0500 Subject: Add parsers for basic instruction types --- newasm/regreg.s | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 newasm/regreg.s (limited to 'newasm/regreg.s') diff --git a/newasm/regreg.s b/newasm/regreg.s new file mode 100644 index 0000000..6893dee --- /dev/null +++ b/newasm/regreg.s @@ -0,0 +1,29 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.type regreg, %function +.global regreg + +// R1 instruction under construction +// R2 output buffer +// R4 input buffer + +regreg: PUSH {LR} + BL register // parse a register + BNE exit // exit if failure + CMP R2, 7 // check that it's R0-R7 + BHI bad_reg + ORRS R1, R2 // fill in Rdn + BL whitespace // mandatory whitespace + BNE exit // exit if failure + BL register // parse a register + BNE exit + CMP R2, 7 // check that it's R0-R7 + BHI bad_reg + LSLS R2, 3 // shift by 3 + ORRS R1, R2 // fill in Rm + MOVS R0, 0 // return code 0 (success) +exit: POP {PC} +bad_reg: MOVS R0, 8 // return code 8 (invalid register for this register position) + POP {PC} -- cgit v1.2.3