aboutsummaryrefslogtreecommitdiff
path: root/newasm/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'newasm/parsers')
-rw-r--r--newasm/parsers/decimal.s4
-rw-r--r--newasm/parsers/immediate.s13
-rw-r--r--newasm/parsers/label.s5
-rw-r--r--newasm/parsers/register.s13
4 files changed, 22 insertions, 13 deletions
diff --git a/newasm/parsers/decimal.s b/newasm/parsers/decimal.s
index a1516d2..cc9dff4 100644
--- a/newasm/parsers/decimal.s
+++ b/newasm/parsers/decimal.s
@@ -5,8 +5,6 @@
.type decimal, %function
.global decimal
-// 1 not a digit
-
// R4 input stream
// R2 output value
@@ -35,5 +33,5 @@ loop: LDRB R0, [R4] // get another char
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)
+bad: MOVS R0, #5 // return code 5 (not a digit)
BX LR
diff --git a/newasm/parsers/immediate.s b/newasm/parsers/immediate.s
new file mode 100644
index 0000000..ac3e578
--- /dev/null
+++ b/newasm/parsers/immediate.s
@@ -0,0 +1,13 @@
+.syntax unified
+.cpu cortex-m0plus
+.thumb
+
+.type immediate, %function
+.global immediate
+
+// R4 input buffer
+// R2 output buffer
+
+immediate:PUSH {LR}
+ BL decimal
+ POP {PC}
diff --git a/newasm/parsers/label.s b/newasm/parsers/label.s
index 4770e6c..45d39e5 100644
--- a/newasm/parsers/label.s
+++ b/newasm/parsers/label.s
@@ -5,9 +5,6 @@
.type label, %function
.global label
-// 1 unexpected begin char
-// 2 doesn't end with colon
-
// R4 input buffer
// R2 output buffer
@@ -23,7 +20,7 @@ label: PUSH {LR}
LDRB R0, [R4] // get a char
CMP R0, ': // colon
BEQ 3f
- MOVS R0, #2 // return code 2 (expected colon)
+ MOVS R0, #3 // return code 3 (expected colon)
POP {PC}
3: ADDS R4, 1 // consume the colon
MOVS R0, #0 // return code 0 (success)
diff --git a/newasm/parsers/register.s b/newasm/parsers/register.s
index 48ebf7a..9334aa3 100644
--- a/newasm/parsers/register.s
+++ b/newasm/parsers/register.s
@@ -5,9 +5,6 @@
.type register, %function
.global register
-// 1 unexpected char
-// 2 invalid general-purpose register number
-
// R4 input buffer
// R2 output buffer
@@ -21,9 +18,12 @@ r_test: CMP R0, 'R
POP {PC} // error code already in R0
validate: CMP R2, #12 // general purpose registers 0-12
BLS success
- MOVS R0, #2 // invalid register number error code
+ MOVS R0, #7 // invalid register number error code
POP {PC}
-special: LDRH R0, [R4] // get two bytes from input stream
+special: LDRB R0, [R4] // get two bytes from input stream
+ LDRB R1, [R4, 1]
+ LSLS R1, 8
+ ORRS R0, R1
ADR R2, table // get address of table
MOVS R3, 0 // set table offset to 0
loop: LDRH R1, [R2, R3] // get two bytes from table at current offset
@@ -32,7 +32,7 @@ loop: LDRH R1, [R2, R3] // get two bytes from table at current offset
ADDS R3, 2 // increment table offset
CMP R3, 6 // compare offset to table size
BLO loop // loop until end of table
- MOVS R0, #1 // return code 1 (unexpected char)
+ MOVS R0, #6 // return code 6 (expected register)
POP {PC}
done: ADDS R4, 2 // consume two chars
LSRS R3, 1 // divide table offset by two to row
@@ -41,6 +41,7 @@ done: ADDS R4, 2 // consume two chars
success: MOVS R0, #0 // return code 0 (success)
POP {PC}
+ .align 4
table: .ascii "SP"
.ascii "LR"
.ascii "PC"