diff options
-rw-r--r-- | assembler/assemble.s | 7 | ||||
-rw-r--r-- | assembler/main.s | 39 | ||||
-rw-r--r-- | assembler/uart.s | 20 |
3 files changed, 41 insertions, 25 deletions
diff --git a/assembler/assemble.s b/assembler/assemble.s index 9517864..9f5c022 100644 --- a/assembler/assemble.s +++ b/assembler/assemble.s @@ -14,15 +14,12 @@ assemble: PUSH {LR} LDR R0, =uart_send LDR R1, =get_char - // ADDS R0, 1 - // ADDS R1, 1 MOV R9, R0 MOV R10, R1 MOVS R6, 0 MOVS R0, ' MOV R8, R0 LDR R1, =opcode - // ADDS R1, 1 BLX R1 MOV R0, R8 BLX R9 @@ -41,7 +38,6 @@ handle_reg: MOVS R1, (1<<4) // bit 4 mask // if 111xyyyy ANDS R0, R1 // get bit 4 ADDS R0, 3 // add 3 to it (now 3 or 4) LDR R1, =register - // ADDS R1, 1 BLX R1 MOVS R0, 0x0F // lower nibble mask ANDS R0, R7 // store shift amount in R0 @@ -65,7 +61,6 @@ fin: LSLS R0, R2 handle_imm: MOVS R1, 0x0F // lower nibble mask ANDS R0, R1 // store immediate width in R0 LDR R1, =octal - // ADDS R1, 1 BLX R1 // result is put in R4 LSLS R0, R7, 27 LSRS R0, 31 @@ -77,6 +72,4 @@ done_stuff: MOV R0, R8 // copy the end_char into R0 BLX R9 // echo the space (or carriage return) here: LSRS R7, 0x8 // get next parse instruction BNE main_loop // if it's nonzero there are more things to parse -done: MOVS R0, '\n // send newline - BLX R9 POP {PC} diff --git a/assembler/main.s b/assembler/main.s index 9a7fd89..1795823 100644 --- a/assembler/main.s +++ b/assembler/main.s @@ -10,8 +10,37 @@ main: bl setup_clocks bl setup_gpio bl setup_uart -1: - bl assemble - movs r0, r6 - bl send_hex - b 1b + b assembler + +assembler: LDR R0, =0x20001000 // SRAM_BASE + MOV R11, R0 + ADDS R1, R0, 1 // JUMP ADDRESS + MOV R12, R1 +1: BL PROMPT // SHOW PROMPT + BL assemble + B 2f // TODO condition + BX R12 +2: MOV R7, R11 // STORE INSTRUCTION WORD + STRH R6, [R7] + MOVS R0, '\r // NEW LINE + BL uart_send + BL PROMPT // REWRITE PROMPT + ADDS R7, 2 // INCREMENT POINTER + MOV R11, R7 + MOVS R0, '\r + BL uart_send + MOVS R0, '\n + BL uart_send + B 1b + +PROMPT: PUSH {LR} + MOV R0, R11 // CURRENT ADDRESS + BL send_hex + MOVS R0, ' // SPACE + BL uart_send + MOV R1, R11 // CURRENT CONTENTS + LDRH R0, [R1] + BL send_hex + MOVS R0, ' // SPACE + BL uart_send + POP {PC} // RETURN diff --git a/assembler/uart.s b/assembler/uart.s index 8dd6a68..e1f5e8b 100644 --- a/assembler/uart.s +++ b/assembler/uart.s @@ -27,7 +27,7 @@ uart_recv: LDR R1, =UART0_BASE // 0x000E 0x4914 MOVS R3, 0b1 << 4 // 0x0010 0x2310 ; RX FIFO EMPTY 1: LDR R2, [R1, UARTFR_OFST] // 0x0012 0x670A TST R2, R3 // 0x0014 0x421A - BNE 1b // 0x0016 0xF1FC + BNE 1b // 0x0016 0xD1FC LDRB R0, [R1, UARTDR_OFST] // 0x0018 0x7808 BX LR // 0x001A 0x4770 get_char: PUSH {LR} // 0x001C 0xB500 @@ -36,14 +36,14 @@ get_char: PUSH {LR} // 0x001C 0xB500 CMP R0, R8 // 0x0022 0x4540 POP {PC} // 0x0024 0xBD00 send_hex: PUSH {LR} // 0x0026 0xB500 - MOVS R4, R0 // 0x0028 0x0004 + LSLS R4, R0, 16 // 0x0028 0x MOVS R0, '0 // 0x002A 0x2030 BL uart_send // 0x002C 0xF7FF // 0x002E 0xFFE8 MOVS R0, 'x // 0x0030 0x2078 BL uart_send // 0x0032 0xF7FF // 0x0034 0xFFE5 - MOVS R5, 8 // 0x0036 0x2508 ; EIGHT NIBBLES IN A WORD + MOVS R5, 4 // 0x0036 0x2504 ; FOUR NIBBLES TO PRINT 0: MOVS R0, 28 // 0x0038 0x201C ; ROTATE LEFT 4 RORS R4, R0 // 0x003A 0x41C4 MOVS R0, 0xF // 0x003C 0x200F ; LOWEST NIBBLE MASK @@ -56,13 +56,7 @@ send_hex: PUSH {LR} // 0x0026 0xB500 2: BL uart_send // 0x004A 0xF7FF // 0x004C 0xFFD9 SUBS R5, 1 // 0x004E 0x3D01 - BNE 0b // 0x0050 0xD1F9 - MOVS R0, '\r // 0x0052 0x200D - BL uart_send // 0x0054 0xF7FF - // 0x0056 0xFFD4 - MOVS R0, '\n // 0x0058 0x200A - BL uart_send // 0x005A 0xF7FF - // 0x005C 0xFFD1 - POP {PC} // 0x005E 0xBD00 - // 0x0060 0x4000 ; UART0_BASE - // 0x0062 0x4003 + BNE 0b // 0x0050 0xD1F2 + POP {PC} // 0x0052 0xBD00 + // 0x0054 0x4000 ; UART0_BASE + // 0x0056 0x4003 |