Skip to content

Commit

Permalink
x64でテストに失敗するのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Aug 17, 2023
1 parent 15fc88f commit 799c88e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/as/asm_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static unsigned char *asm_mov_ir(Inst *inst, Code *code) {
bool ofszero = offset == 0 && ((sno & 7) != RBP - RAX);
short buf[] = {
size == REG16 ? 0x66 : -1,
0x40 | (size == REG64 ? 0x08 : 0) | ((dno & 8) >> 1) | ((sno & 8) >> 3),
(size == REG64 || sno >= 8 || dno >= 8) ? 0x40 | (size == REG64 ? 0x08 : 0) | ((dno & 8) >> 1) | ((sno & 8) >> 3) : -1,
0x8a | (size == REG8 ? 0 : 0x01),
((dno & 7) << 3) | (sno & 7) | (ofszero ? 0 : is_im8(offset) ? 0x40: 0x80),
(sno & 7) == RSP - RAX ? 0x24 : -1,
Expand Down Expand Up @@ -174,7 +174,7 @@ static unsigned char *asm_mov_ri(Inst *inst, Code *code) {
bool ofszero = offset == 0 && ((dno & 7) != RBP - RAX);
short buf[] = {
size == REG16 ? 0x66 : -1,
0x40 | (size == REG64 ? 0x08 : 0) | ((sno & 8) >> 1) | ((dno & 8) >> 3),
(size == REG64 || sno >= 8 || dno >= 8) ? 0x40 | (size == REG64 ? 0x08 : 0) | ((sno & 8) >> 1) | ((dno & 8) >> 3) : -1,
0x88 | (size == REG8 ? 0 : 0x01),
((sno & 7) << 3) | (dno & 7) | (ofszero ? 0 : is_im8(offset) ? 0x40: 0x80),
(dno & 7) == RSP - RAX ? 0x24 : -1,
Expand Down Expand Up @@ -317,21 +317,21 @@ static unsigned char *asm_movszx_rr(Inst *inst, Code *code) {
if (opr_reg8(&inst->src.reg) && !inst->dst.reg.x) {
MAKE_CODE(inst, code, 0x66, 0x0f, op, 0xc0 + s + d * 8);
} else {
int pre = (!inst->src.reg.x ? 0x40 : 0x41) + (!inst->dst.reg.x ? 0 : 4);
int pre = ((inst->src.reg.x & 1) == 0 ? 0x40 : 0x41) + (!inst->dst.reg.x ? 0 : 4);
MAKE_CODE(inst, code, 0x66, pre, 0x0f, op, 0xc0 + s + d * 8);
}
return p;
case REG32:
if (opr_reg8(&inst->src.reg) && !inst->dst.reg.x) {
MAKE_CODE(inst, code, 0x0f, op, 0xc0 + s + d * 8);
} else {
int pre = (!inst->src.reg.x ? 0x40 : 0x41) + (!inst->dst.reg.x ? 0 : 4);
int pre = ((inst->src.reg.x & 1) == 0 ? 0x40 : 0x41) + (!inst->dst.reg.x ? 0 : 4);
MAKE_CODE(inst, code, pre, 0x0f, op, 0xc0 + s + d * 8);
}
return p;
case REG64:
{
int pre = (!inst->src.reg.x ? 0x48 : 0x49) + (!inst->dst.reg.x ? 0 : 4);
int pre = ((inst->src.reg.x & 1) == 0 ? 0x48 : 0x49) + (!inst->dst.reg.x ? 0 : 4);
MAKE_CODE(inst, code, pre, 0x0f, op, 0xc0 + s + d * 8);
return p;
}
Expand Down
3 changes: 2 additions & 1 deletion src/as/inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ enum RegType {
R14B,
R15B,

// 8bit: corresponds to AH~ in lower 4bit to handle easily.
SPL = R15B + 1 + 4,
BPL,
SIL,
Expand Down Expand Up @@ -226,7 +227,7 @@ enum RegSize {
typedef struct {
char size; // RegSize
char no; // 0~7, or RIP
char x; // 0 or 1
char x; // 0 or 1, (or 2 if size == REG8, SPL~DIL)
} Reg;

enum OperandType {
Expand Down

0 comments on commit 799c88e

Please sign in to comment.