scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 2a449ac877e295ab2b7c9e4179470db355f71bb8
parent 89acdb2f73c67385406cf52242f46ba0ef021dec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Dec 2017 09:53:27 +0000

[as-z80] Expand ld16() to all the cases

The only case that is not handled in ld16() is SP instructions,
because they create a lot of problems and at the end they are
better handled with a noarg format.

Diffstat:
Mas/target/x80/ins.c | 60+++++++++++++++++++++++++-----------------------------------
Mas/target/x80/x80.dat | 26+++++++++++++-------------
2 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -280,40 +280,6 @@ r8_xx(Op *op, Node **args) } void -r16_imm16(Op *op, Node **args) -{ - Node *par1, *par2; - unsigned char buf[4]; - int n = op->size; - unsigned val; - - par1 = args[0]; - par2 = args[1]; - - memcpy(buf, op->bytes, n); - val = par2->sym->value; - buf[n-1] = val >> 8; - buf[n-2] = val; - buf[n-3] |= reg2int(par1->sym->argtype) << 4; - emit(buf, n); -} - -void -r16_dir(Op *op, Node **args) -{ - Node *dir, *reg; - - if (args[1]->addr == ADIRECT) - dir = args[1], reg = args[0]; - else - dir = args[0], reg = args[1]; - - args[0] = reg; - args[1] = dir->left; - r16_imm16(op, args); -} - -void alu16(Op *op, Node **args) { Node *par; @@ -331,8 +297,32 @@ alu16(Op *op, Node **args) void ld16(Op *op, Node **args) { - if (!args[1]) + Node *dst, *src, *tmp; + int n = op->size; + unsigned val; + unsigned char buf[4]; + + dst = args[0]; + src = args[1]; + if (!src) { alu16(op, args); + return; + } + + if (dst->addr != AREG) { + tmp = src; + src = dst; + dst = tmp; + } + + memcpy(buf, op->bytes, n); + if (src->addr == ADIRECT) + src = src->left; + val = src->sym->value; + buf[n-1] = val >> 8; + buf[n-2] = val; + buf[n-3] |= reg2int(dst->sym->argtype) << 4; + emit(buf, n); } void diff --git a/as/target/x80/x80.dat b/as/target/x80/x80.dat @@ -80,19 +80,19 @@ LD I,A 2 0xed,0x47 noargs Z80,R800 LD R,A 2 0xed,0x4f noargs Z80,R800 # 16 bit load group -LD dd,imm16 3 0x01 r16_imm16 Z80,R800,GB80 -LD IX,imm16 4 0xdd,0x21 imm16 Z80,R800 -LD IY,imm16 4 0xfd,0x21 imm16 Z80,R800 - -LD HL,(n) 3 0x2a dir Z80,R800,GB80 -LD dd,(n) 4 0xed,0x4b r16_dir Z80,R800 -LD IX,(n) 4 0xdd,0x2a dir Z80,R800 -LD IY,(n) 4 0xfd,0x2a dir Z80,R800 - -LD (n),HL 3 0x22 dir Z80,R800,GB80 -LD (n),dd 4 0xed,0x43 r16_dir Z80,R800 -LD (n),IX 4 0xdd,0x22 dir Z80,R800 -LD (n),IY 4 0xfd,0x22 dir Z80,R800 +LD dd,imm16 3 0x01 ld16 Z80,R800,GB80 +LD IX,imm16 4 0xdd,0x21 ld16 Z80,R800 +LD IY,imm16 4 0xfd,0x21 ld16 Z80,R800 + +LD HL,(n) 3 0x2a ld16 Z80,R800,GB80 +LD dd,(n) 4 0xed,0x4b ld16 Z80,R800 +LD IX,(n) 4 0xdd,0x2a ld16 Z80,R800 +LD IY,(n) 4 0xfd,0x2a ld16 Z80,R800 + +LD (n),HL 3 0x22 ld16 Z80,R800,GB80 +LD (n),dd 4 0xed,0x43 ld16 Z80,R800 +LD (n),IX 4 0xdd,0x22 ld16 Z80,R800 +LD (n),IY 4 0xfd,0x22 ld16 Z80,R800 LD SP,HL 1 0xf9 noargs Z80,R800,GB80 LD SP,IX 2 0xdd,0xf9 noargs Z80,R800