all mov16

This commit is contained in:
sfja 2025-03-31 22:26:08 +02:00
parent 4b83e2a8d6
commit a5866173e5
3 changed files with 48 additions and 2 deletions

View File

@ -242,6 +242,18 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
out[ip++] = op2; out[ip++] = op2;
break; break;
} }
case LineTy_Mov16_Reg_Label: {
uint16_t dst = line->dst.reg;
int op2 = line->op2.label;
uint32_t ins = Op_Mov16;
set_is_imm(&ins);
ins |= (dst & 0xfu) << 12;
out[ip++] = (uint16_t)ins;
ADD_LABEL(op2);
break;
}
case LineTy_Mov16_Reg_MemReg: { case LineTy_Mov16_Reg_MemReg: {
uint16_t dst = line->dst.reg; uint16_t dst = line->dst.reg;
uint16_t op2 = line->op2.reg; uint16_t op2 = line->op2.reg;
@ -296,7 +308,8 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
out[ip++] = line->offset; out[ip++] = line->offset;
break; break;
} }
case LineTy_Mov16_MemLabel_Reg: { case LineTy_Mov16_MemImm_Reg: {
uint16_t dst = line->dst.imm;
uint16_t op2 = line->op2.reg; uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Mov16; uint32_t ins = Op_Mov16;
@ -305,7 +318,20 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
set_mov_is_store(&ins); set_mov_is_store(&ins);
out[ip++] = (uint16_t)ins; out[ip++] = (uint16_t)ins;
ADD_LABEL(line->dst.label); out[ip++] = dst;
break;
}
case LineTy_Mov16_MemLabel_Reg: {
int dst = line->dst.label;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Mov16;
add_op2_reg(&ins, op2);
set_mov_is_memory(&ins);
set_mov_is_store(&ins);
out[ip++] = (uint16_t)ins;
ADD_LABEL(dst);
break; break;
} }
case LineTy_In_Imm: { case LineTy_In_Imm: {

View File

@ -24,10 +24,12 @@ typedef enum {
LineTy_Mov8_MemImm_Reg, LineTy_Mov8_MemImm_Reg,
LineTy_Mov16_Reg_Reg, LineTy_Mov16_Reg_Reg,
LineTy_Mov16_Reg_Imm, LineTy_Mov16_Reg_Imm,
LineTy_Mov16_Reg_Label,
LineTy_Mov16_Reg_MemReg, LineTy_Mov16_Reg_MemReg,
LineTy_Mov16_Reg_MemImm, LineTy_Mov16_Reg_MemImm,
LineTy_Mov16_Reg_MemLabel, LineTy_Mov16_Reg_MemLabel,
LineTy_Mov16_MemReg_Reg, LineTy_Mov16_MemReg_Reg,
LineTy_Mov16_MemImm_Reg,
LineTy_Mov16_MemLabel_Reg, LineTy_Mov16_MemLabel_Reg,
LineTy_In_Imm, LineTy_In_Imm,
LineTy_Call_Imm, LineTy_Call_Imm,
@ -115,10 +117,12 @@ Line s_mov8_mi_i(uint16_t dst_imm, uint16_t op2_imm);
Line s_mov8_mi_r(uint16_t dst_imm, Reg op2_reg); Line s_mov8_mi_r(uint16_t dst_imm, Reg op2_reg);
Line s_mov16_r_r(Reg dst_reg, Reg op2_reg); Line s_mov16_r_r(Reg dst_reg, Reg op2_reg);
Line s_mov16_r_i(Reg dst_reg, uint16_t op2_imm); Line s_mov16_r_i(Reg dst_reg, uint16_t op2_imm);
Line s_mov16_r_l(Reg dst_reg, int op2_label);
Line s_mov16_r_mr(Reg dst_reg, Reg op2_reg, uint16_t op2_offset); Line s_mov16_r_mr(Reg dst_reg, Reg op2_reg, uint16_t op2_offset);
Line s_mov16_r_mi(Reg dst_reg, uint16_t op2_imm); Line s_mov16_r_mi(Reg dst_reg, uint16_t op2_imm);
Line s_mov16_r_ml(Reg dst_reg, int op2_label); Line s_mov16_r_ml(Reg dst_reg, int op2_label);
Line s_mov16_mr_r(Reg dst_reg, uint16_t dst_offset, Reg op2_reg); Line s_mov16_mr_r(Reg dst_reg, uint16_t dst_offset, Reg op2_reg);
Line s_mov16_mi_r(uint16_t dst_imm, Reg op2_reg);
Line s_mov16_ml_r(int dst_label, Reg op2_reg); Line s_mov16_ml_r(int dst_label, Reg op2_reg);
Line s_in_i(Reg dst_reg, uint16_t op1_imm); Line s_in_i(Reg dst_reg, uint16_t op1_imm);
Line s_call_i(uint16_t op1_imm); Line s_call_i(uint16_t op1_imm);

View File

@ -138,6 +138,14 @@ Line s_mov16_r_i(Reg dst_reg, uint16_t op2_imm)
.op2 = (Ex) { .imm = op2_imm }, .op2 = (Ex) { .imm = op2_imm },
}; };
} }
Line s_mov16_r_l(Reg dst_reg, int op2_label)
{
return (Line) {
.ty = LineTy_Mov16_Reg_Label,
.dst = (Ex) { .reg = (uint16_t)dst_reg },
.op2 = (Ex) { .label = op2_label },
};
}
Line s_mov16_r_mr(Reg dst_reg, Reg op2_reg, uint16_t op2_offset) Line s_mov16_r_mr(Reg dst_reg, Reg op2_reg, uint16_t op2_offset)
{ {
return (Line) { return (Line) {
@ -172,6 +180,14 @@ Line s_mov16_mr_r(Reg dst_reg, uint16_t dst_offset, Reg op2_reg)
.offset = dst_offset, .offset = dst_offset,
}; };
} }
Line s_mov16_mi_r(uint16_t dst_imm, Reg op2_reg)
{
return (Line) {
.ty = LineTy_Mov16_MemImm_Reg,
.dst = (Ex) { .imm = dst_imm },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_mov16_ml_r(int dst_label, Reg op2_reg) Line s_mov16_ml_r(int dst_label, Reg op2_reg)
{ {
return (Line) { return (Line) {