ref: 9ecf926bc59721f5d244c679dd58acf39faf2e30
parent: 74d520e8c85d8725aff11b423f0ba00fd3dd727d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Dec 29 06:38:20 EST 2017
[as-z80] Simplify 8 bit load group There were too many functions, and they could be merged in more generic functions.
--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -176,44 +176,15 @@
}
void
-r8_imm8(Op *op, Node **args)
+dir(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] = par2->sym->value;
- buf[n-2] |= reg2int(par1->sym->argtype) << 3;
- emit(buf, n);
-}
-
-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);
- buf[n-1] = par2->sym->value;
- emit(buf, n);
-}
-
-void
-imm16(Op *op, Node **args)
-{
Node *imm;
unsigned char buf[4];
unsigned val;
int n = op->size;
- imm = (args[1]) ? args[1] : args[0];
+ imm = (args[1]->addr == ADIRECT) ? args[1] : args[0];
+ imm = imm->left;
memcpy(buf, op->bytes, n);
val = imm->sym->value;
buf[n-1] = val >> 8;
@@ -222,64 +193,27 @@
}
void
-dir(Op *op, Node **args)
+ld8(Op *op, Node **args)
{
- Node *dir;
+ Node *par1 = args[0], *par2 = args[1];
+ int n = op->size, i = n;;
+ unsigned regval = 0;
+ unsigned char buf[4];
- dir = (args[1]->addr == ADIRECT) ? args[1] : args[0];
- args[1] = dir->left;
- imm16(op, args);
-}
-
-void
-r8_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(par1->sym->argtype) << 3 |
- reg2int(par2->sym->argtype);
- emit(buf, n);
-}
-void
-r8(Op *op, Node **args)
-{
- Node *par;
- unsigned char buf[3];
- int n = op->size;
+ if (par1->addr == AREG)
+ regval |= reg2int(par1->sym->argtype) << 3;
+ if (par2->addr == AREG)
+ regval |= reg2int(par2->sym->argtype);
+ else if (par2->addr == AIMM)
+ buf[--i] = par2->sym->value;
- par = args[0];
- memcpy(buf, op->bytes, n);
- buf[n-1] |= reg2int(par->sym->argtype);
+ buf[--i] |= regval;
emit(buf, n);
}
void
-xx_r8(Op *op, Node **args)
-{
- args[0] = args[1];
- r8(op, args);
-}
-
-void
-r8_xx(Op *op, Node **args)
-{
- Node *par;
- unsigned char buf[3];
- int n = op->size;
-
- par = args[0];
- memcpy(buf, op->bytes, n);
- buf[n-1] |= reg2int(par->sym->argtype) << 3;
- emit(buf, n);
-}
-
-void
alu16(Op *op, Node **args)
{
Node *par;
@@ -379,12 +313,11 @@
}
idx = args[0]->left->right;
- if (args[1]) {
- if (args[1]->addr == AREG)
- reg = args[1];
- else
- imm = args[1];
- }
+ if (args[1]->addr == AREG)
+ reg = args[1];
+ else
+ imm = args[1];
+
memcpy(buf, op->bytes, n);
if (imm)
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -46,16 +46,16 @@
# ss is any flag from C, NC, Z, NZ
# 8 bit load group
-LD r,imm8 2 0x06 r8_imm8 Z80,R800,GB80
-LD p,imm8 3 0xdd,0x06 r8_imm8 Z80,R800
-LD q,imm8 3 0xfd,0x06 r8_imm8 Z80,R800
-LD (HL),imm8 2 0x36 imm8 Z80,R800,GB80
+LD r,imm8 2 0x06 ld8 Z80,R800,GB80
+LD p,imm8 3 0xdd,0x06 ld8 Z80,R800
+LD q,imm8 3 0xfd,0x06 ld8 Z80,R800
+LD (HL),imm8 2 0x36 ld8 Z80,R800,GB80
-LD r,r 1 0x40 r8_r8 Z80,R800,GB80
-LD p,p 2 0xdd,0x40 r8_r8 Z80,R800
-LD q,q 2 0xfd,0x40 r8_r8 Z80,R800
-LD (HL),r 1 0x70 xx_r8 Z80,R800,GB80
-LD r,(HL) 1 0x46 r8_xx Z80,R800,GB80
+LD r,r 1 0x40 ld8 Z80,R800,GB80
+LD p,p 2 0xdd,0x40 ld8 Z80,R800
+LD q,q 2 0xfd,0x40 ld8 Z80,R800
+LD (HL),r 1 0x70 ld8 Z80,R800,GB80
+LD r,(HL) 1 0x46 ld8 Z80,R800,GB80
LD r,(IX+n) 3 0xdd,0x46 idx Z80,R800
LD r,(IY+n) 3 0xfd,0x46 idx Z80,R800
@@ -62,7 +62,7 @@
LD (IX+n),r 3 0xdd,0x70 idx Z80,R800
LD (IY+n),r 3 0xfd,0x70 idx Z80,R800
-LD (HL),imm8 2 0x36 imm8 Z80,R800,GB80
+LD (HL),imm8 2 0x36 ld8 Z80,R800,GB80
LD (IX+n),imm8 4 0xdd,0x36 idx Z80,R800
LD (IY+n),imm8 4 0xfd,0x36 idx Z80,R800