From 80d8f3ae48255f786bd4d52a1819ea0c339f6946 Mon Sep 17 00:00:00 2001 From: Jacques Comeaux Date: Fri, 23 Aug 2024 19:46:17 -0500 Subject: Add register parser and binary search for opcodes --- newasm/parsers/decimal.s | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 newasm/parsers/decimal.s (limited to 'newasm/parsers/decimal.s') diff --git a/newasm/parsers/decimal.s b/newasm/parsers/decimal.s new file mode 100644 index 0000000..a1516d2 --- /dev/null +++ b/newasm/parsers/decimal.s @@ -0,0 +1,39 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.type decimal, %function +.global decimal + +// 1 not a digit + +// R4 input stream +// R2 output value + +decimal: LDRB R0, [R4] // get a char + CMP R0, '0 // check if zero + BNE notzero + ADDS R4, 1 // consume the char + MOVS R2, 0 // return value of zero +success: MOVS R0, #0 // return code zero (success) + BX LR +notzero: CMP R0, '1 // if not [1-9] then error + BLO bad + CMP R0, '9 + BHI bad + ADDS R4, 1 // consume the first digit + SUBS R0, '0 // calculate the value + MOVS R2, R0 // store it in R2 +loop: LDRB R0, [R4] // get another char + CMP R0, '0 // if not [0-9] then done + BLO success + CMP R0, '9 + BHI success + ADDS R4, 1 // consume the additional digit + SUBS R0, '0 // calculate the value + MOVS R3, 10 // base 10 + MULS R2, R3 // shift result by one decimal place + ADDS R2, R0 // accumulate into R2 + B loop // keep getting digits +bad: MOVS R0, #1 // return code 1 (not a digit) + BX LR -- cgit v1.2.3