ref: c2677b83f943373787dd200c425fc2cbb90a49c0
parent: 2d60e8ab6926bc6850e5299182747c314e2589ce
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri May 18 04:11:32 EDT 2018
[as/286] Add reg8_reg8() This function implements 8 bit register to register instructions. It hasn't been tested, but it should work.
--- a/as/target/x86/ins.c
+++ b/as/target/x86/ins.c
@@ -6,6 +6,15 @@
#include "../../as.h"
#include "proc.h"
+#define addrbyte(mod, reg, rm) ((mod) << 6 | (reg) << 3 | (rm))
+
+enum addr_mode {
+ MEM_MODE = 0,
+ MEM8_MODE = 1,
+ MEM16_MODE = 2,
+ REG_MODE = 3,
+};
+
static int
getclass(Node *np)
{
@@ -220,4 +229,33 @@
Node *
moperand(void)
{
+}
+
+static int
+reg8toint(Node *np)
+{
+ switch (np->sym->value) {
+ case AREG_AL: return 0;
+ case AREG_CL: return 1;
+ case AREG_DL: return 2;
+ case AREG_BL: return 3;
+ case AREG_AH: return 4;
+ case AREG_CH: return 5;
+ case AREG_DH: return 6;
+ case AREG_BH: return 7;
+ default: abort();
+ }
+}
+
+void
+reg8_reg8(Op *op, Node **args)
+{
+ int src, dst;
+ char buf[2];
+
+ src = reg8toint(args[0]);
+ dst = reg8toint(args[1]);
+ buf[0] = op->bytes[0];
+ buf[1] = addrbyte(REG_MODE, src, dst);
+ emit(buf, 2);
}
--- a/as/target/x86/rules.dat
+++ b/as/target/x86/rules.dat
@@ -1,5 +1,5 @@
-reg8 AREG8
-reg16 AREG16
+reg8 AREG_R8CLASS
+reg16 AREG_R16CLASS
imm8 AIMM8
imm16 AIMM16
imm32 AIMM32
--- a/as/target/x86/x86.dat
+++ b/as/target/x86/x86.dat
@@ -24,4 +24,4 @@
# 8 bit arithmetic operations
-#ADDB reg8,reg8 2 0x00,0xc0 reg2reg I286,I386,AMD64
+ADDB reg8,reg8 2 0x00 reg8_reg8 I286,I386,AMD64