From fa75f30ffb03a381f99630e5b8f612c52d32be6f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 14 Dec 2019 12:28:27 -0500 Subject: [PATCH] avra: add RJMP and RCALL instructions --- apps/zasm/avr.asm | 47 ++++++++++++++++++++++++++++---- tools/tests/avra/test1.asm | 3 ++ tools/tests/avra/test1.expected | Bin 18 -> 22 bytes 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/apps/zasm/avr.asm b/apps/zasm/avr.asm index 8454961..59e2eb3 100644 --- a/apps/zasm/avr.asm +++ b/apps/zasm/avr.asm @@ -59,8 +59,11 @@ instrNames: .db "BST", 0 .db "SBRC", 0 .db "SBRS", 0 +.equ I_RCALL 42 +.db "RCALL", 0 +.db "RJMP", 0 ; no arg (from here, instrUpMasks2) -.equ I_BREAK 42 +.equ I_BREAK 44 .db "BREAK", 0 .db "CLC", 0 .db "CLH", 0 @@ -88,7 +91,7 @@ instrNames: .db "SLEEP", 0 .db "WDR", 0 ; Rd(5) -.equ I_ASR 68 +.equ I_ASR 70 .db "ASR", 0 .db "COM", 0 .db "DEC", 0 @@ -137,6 +140,9 @@ instrUpMasks1: .db 0b11111010 ; BST .db 0b11111100 ; SBRC .db 0b11111110 ; SBRS +; k(12): XXXXkkkk kkkkkkkk +.db 0b11010000 ; RCALL +.db 0b11000000 ; RJMP ; 16-bit constant masks associated with each instruction. In the same order as ; in instrNames @@ -231,8 +237,10 @@ parseInstruction: jr c, .spitRd5Rr5 cp I_BLD jr c, .spitRdK8 - cp I_BREAK + cp I_RCALL jr c, .spitRdBit + cp I_BREAK + jr c, .spitK12 cp I_ASR jr c, .spitNoArg ; spitRd5 @@ -242,7 +250,7 @@ parseInstruction: ; continue to .spitNoArg .spitNoArg: call .getUp2 - jr .spit + jp .spit .spitRd5Rr5: call .readR5 @@ -275,7 +283,6 @@ parseInstruction: call readWord call parseExpr ret nz - ld a, c ld a, 0xff call .IX2A ret nz @@ -306,6 +313,36 @@ parseInstruction: call .getUp1 jr .spitMSB +.spitK12: + ; Let's deal with the upcode constant before we destroy DE below + call .getUp1 + ld b, (hl) + call readWord + call parseExpr + ret nz + push ix \ pop hl + ; We're doing the same dance as in .BR. See comments there. + ld de, 0xfff + add hl, de + jp c, unsetZ ; Carry? number is way too high. + ex de, hl + call zasmGetPC ; --> HL + inc hl \ inc hl + ex de, hl + sbc hl, de + jp c, unsetZ ; Carry? error + ld de, 0xfff + sbc hl, de + ; We're within bounds! Now, divide by 2 + ld a, l + rr h \ rra + ; LSB in A, spit + call ioPutB + ld a, h + and 0xf + or b + jp ioPutB + .spit: ; LSB is spit *before* MSB inc hl diff --git a/tools/tests/avra/test1.asm b/tools/tests/avra/test1.asm index 4f639f0..0b2d25e 100644 --- a/tools/tests/avra/test1.asm +++ b/tools/tests/avra/test1.asm @@ -9,3 +9,6 @@ bar: brbs 6, foo ori r22, 0x34+4 sbrs r1, 3 +rjmp foo +rcall baz +baz: diff --git a/tools/tests/avra/test1.expected b/tools/tests/avra/test1.expected index c01061845fe4f707607a133d3276971adf3a6991..b8268a7f4f869e7862a5fb186271d95271d69a36 100644 GIT binary patch literal 22 ecmb2=)(DjV