scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 073b2d83295eb468f340016b8d2a66e06a88f098
parent 853fbbd628b233cb42463336d16e5bd5f6e47cf5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 30 Sep 2017 10:19:17 +0200

[as-z80] Add imm8 and r8 instruction formats

Diffstat:
Mas/target/gen.awk | 2++
Mas/target/x80/ins.c | 28++++++++++++++++++++++++++++
Mas/target/x80/x80.dat | 5+++++
Mas/target/z80/proc.c | 4++++
4 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/as/target/gen.awk b/as/target/gen.awk @@ -81,6 +81,8 @@ function str2args(s, args, i, out, n) out = out "AREG_QCLASS" } else if (match(a, /^reg_r/)) { out = out "AREG_RCLASS" + } else if (match(a, /^regA/)) { + out = out "AREG_A" } else { print "wrong arg", a exit 1 diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -94,6 +94,20 @@ r8_imm8(Op *op, Node **args) } void +imm8(Op *op, Node **args) +{ + Node *par1, *par2; + unsigned char buf[3]; + int n = op->size; + + par2 = args[1]; + + memcpy(buf, op->bytes, n-1); + buf[n-1] = par2->sym->value; + emit(cursec, buf, n); +} + +void r8_r8(Op *op, Node **args) { Node *par1, *par2; @@ -107,3 +121,17 @@ r8_r8(Op *op, Node **args) reg2int(par2->sym->argtype); emit(cursec, buf, n); } + +void +r8(Op *op, Node **args) +{ + Node *par1, *par2; + unsigned char buf[3]; + int n = op->size; + + par1 = args[0]; + par2 = args[1]; + memcpy(buf, op->bytes, n); + buf[n-1] |= reg2int(par2->sym->argtype); + emit(cursec, buf, n); +} diff --git a/as/target/x80/x80.dat b/as/target/x80/x80.dat @@ -62,3 +62,8 @@ LD reg_q,imm8 3 0xfd,0x06 r8_imm8 Z80,R800 LD reg_r,reg_r 1 0x40 r8_r8 Z80,R800,GB80 LD reg_p,reg_p 2 0xdd,0x40 r8_r8 Z80,R800 LD reg_q,reg_q 2 0xfd,0x40 r8_r8 Z80,R800 + +ADD regA,reg_r 1 0x80 r8 Z80,R800,GB80 +ADD regA,reg_p 2 0xdd,0x80 r8 Z80,R800 +ADD regA,reg_q 2 0xfd,0x80 r8 Z80,R800 +ADD regA,imm8 2 0xc6 imm8 Z80,R800 diff --git a/as/target/z80/proc.c b/as/target/z80/proc.c @@ -65,6 +65,10 @@ match(Op *op, Node **args) --p; np = *args++; switch (arg & ~AREP) { + case AREG_A: + if (np->op != AREG || np->sym->argtype != AREG_A) + return 0; + break; case AREG_RCLASS: if (np->op != AREG) return 0;