ins.c (2467B)
1 static char sccsid[] = "@(#) ./as/target/z80/ins.c"; 2 3 #include <stdlib.h> 4 #include <string.h> 5 6 #include "../../../inc/scc.h" 7 #include "../../as.h" 8 #include "proc.h" 9 10 int 11 rclass(int reg) 12 { 13 switch (reg) { 14 case AREG_B: 15 case AREG_C: 16 case AREG_D: 17 case AREG_E: 18 case AREG_H: 19 case AREG_L: 20 case AREG_A: 21 return 1; 22 default: 23 return 0; 24 } 25 } 26 27 int 28 pclass(int reg) 29 { 30 switch (reg) { 31 case AREG_B: 32 case AREG_C: 33 case AREG_D: 34 case AREG_E: 35 case AREG_IXH: 36 case AREG_IXL: 37 case AREG_A: 38 return 1; 39 default: 40 return 0; 41 } 42 } 43 44 int 45 qclass(int reg) 46 { 47 switch (reg) { 48 case AREG_B: 49 case AREG_C: 50 case AREG_D: 51 case AREG_E: 52 case AREG_IYH: 53 case AREG_IYL: 54 case AREG_A: 55 return 1; 56 default: 57 return 0; 58 } 59 } 60 61 static int 62 reg2int(int reg) 63 { 64 switch (reg) { 65 case AREG_B: return 0; 66 case AREG_C: return 1; 67 case AREG_D: return 2; 68 case AREG_E: return 3; 69 case AREG_IXH: 70 case AREG_IYH: 71 case AREG_H: return 4; 72 case AREG_IXL: 73 case AREG_IYL: 74 case AREG_L: return 5; 75 case AREG_A: return 7; 76 default: abort(); 77 } 78 } 79 80 void 81 r8_imm8(Op *op, Node **args) 82 { 83 Node *par1, *par2; 84 unsigned char buf[3]; 85 int n = op->size; 86 87 par1 = args[0]; 88 par2 = args[1]; 89 90 memcpy(buf, op->bytes, n-1); 91 buf[n-1] = par2->sym->value; 92 buf[n-2] |= reg2int(par1->sym->argtype) << 3; 93 emit(cursec, buf, n); 94 } 95 96 void 97 imm8(Op *op, Node **args) 98 { 99 Node *par1, *par2; 100 unsigned char buf[3]; 101 int n = op->size; 102 103 par2 = args[1]; 104 105 memcpy(buf, op->bytes, n-1); 106 buf[n-1] = par2->sym->value; 107 emit(cursec, buf, n); 108 } 109 110 void 111 r8_r8(Op *op, Node **args) 112 { 113 Node *par1, *par2; 114 unsigned char buf[3]; 115 int n = op->size; 116 117 par1 = args[0]; 118 par2 = args[1]; 119 memcpy(buf, op->bytes, n); 120 buf[n-1] |= reg2int(par1->sym->argtype) << 3 | 121 reg2int(par2->sym->argtype); 122 emit(cursec, buf, n); 123 } 124 125 void 126 xx_r8_2(Op *op, Node **args) 127 { 128 Node *par1, *par2; 129 unsigned char buf[3]; 130 int n = op->size; 131 132 par1 = args[0]; 133 par2 = args[1]; 134 135 memcpy(buf, op->bytes, n); 136 buf[n-1] |= reg2int(par2->sym->argtype); 137 emit(cursec, buf, n); 138 } 139 140 void 141 r8_xx_2(Op *op, Node **args) 142 { 143 Node *par1, *par2; 144 unsigned char buf[3]; 145 int n = op->size; 146 147 par1 = args[0]; 148 par2 = args[1]; 149 150 memcpy(buf, op->bytes, n); 151 buf[n-1] |= reg2int(par2->sym->argtype) << 3; 152 emit(cursec, buf, n); 153 } 154 155 void 156 r8_xx_1(Op *op, Node **args) 157 { 158 Node *par1, *par2; 159 unsigned char buf[3]; 160 int n = op->size; 161 162 par1 = args[0]; 163 par2 = args[1]; 164 165 memcpy(buf, op->bytes, n); 166 buf[n-1] |= reg2int(par1->sym->argtype) << 3; 167 emit(cursec, buf, n); 168 }