From f54e10f9fdb076706a5ac2d0371082e7988bd3f5 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 22 Dec 2019 15:54:46 -0500 Subject: [PATCH] avra: add CALL and JMP --- apps/zasm/avr.asm | 34 ++++++++++++++++++++++++++++------ tools/tests/avra/test1.asm | 2 ++ tools/tests/avra/test1.expected | Bin 36 -> 44 bytes 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/apps/zasm/avr.asm b/apps/zasm/avr.asm index 2aee950..9812673 100644 --- a/apps/zasm/avr.asm +++ b/apps/zasm/avr.asm @@ -112,6 +112,13 @@ instrNames: .db "SBI", 0 .db "SBIC", 0 .db "SBIS", 0 +; 32-bit +; ZASM limitation: CALL and JMP constants are 22-bit. In ZASM, we limit +; ourselves to 16-bit. Supporting 22-bit would incur a prohibitive complexity +; cost. As they say, 64K words ought to be enough for anybody. +.equ I_CALL 94 +.db "CALL", 0 +.db "JMP", 0 .db 0xff ; Instruction table @@ -219,6 +226,9 @@ instrTbl: .db 0x09, 0b10011010, 0x00 ; SBI A, b .db 0x09, 0b10011001, 0x00 ; SBIC A, b .db 0x09, 0b10011011, 0x00 ; SBIS A, b +; k(16) (well, k(22)...) +.db 0x08, 0b10010100, 0b00001110 ; CALL k +.db 0x08, 0b10010100, 0b00001100 ; JMP k ; Same signature as getInstID in instr.asm ; Reads string in (HL) and returns the corresponding ID (I_*) in A. Sets Z if @@ -280,7 +290,7 @@ parseInstruction: push hl \ pop ix ; IX is now our tblrow ld hl, 0 or a - jr z, .spit ; No arg? spit right away + jp z, .spit ; No arg? spit right away and 0xf ; lower nibble dec a ; argspec index is 1-based ld hl, argSpecs @@ -312,12 +322,18 @@ parseInstruction: jr c, .spitRdK8 cp I_CBI jr c, .spitk12 - ; spit A(5) + bit + cp I_CALL + jr c, .spitA5Bit + ; Spit k(16) + call .spit ; spit 16-bit const upcode + ; divide HL by 2 (PC deals with words, not bytes) + srl h \ rr l + ; spit 16-bit K, LSB first + ld a, l + call ioPutB ld a, h - rla \ rla \ rla - or l - ld c, a - jr .spit + jp ioPutB + .spitRegular: ; Regular process which places H and L, ORring it with upcode. Works ; in most cases. @@ -354,6 +370,12 @@ parseInstruction: and 0xf ld b, a jr .spit +.spitA5Bit: + ld a, h + sla a \ rla \ rla + or l + ld c, a + jr .spit .spit: ; LSB is spit *before* MSB diff --git a/tools/tests/avra/test1.asm b/tools/tests/avra/test1.asm index 33bf4e4..839d0d9 100644 --- a/tools/tests/avra/test1.asm +++ b/tools/tests/avra/test1.asm @@ -19,3 +19,5 @@ sbis 22, 5 ser r19 bset 4 bclr 7 +call foo +jmp bar diff --git a/tools/tests/avra/test1.expected b/tools/tests/avra/test1.expected index 3f1a0bb1d1dd27a20b3f67fca4a80b99cfee0bbf..0ee2648f91b194748397b93c6854a4a4005af8a1 100644 GIT binary patch delta 13 UcmY$