1 #ifndef _library__assembler_intrinsics_i386__hpp__included__
2 #define _library__assembler_intrinsics_i386__hpp__included__
4 #include "assembler.hpp"
8 namespace assembler_intrinsics
13 struct sib_scale_off_intermediate
;
14 struct sib_scale_intermediate
;
17 explicit reg(uint8_t _val
);
18 ref
operator[](int32_t off
) const;
19 sib_scale_intermediate
operator*(uint8_t scale
) const;
20 ref
operator[](const reg r
) const;
21 ref
operator[](sib_scale_intermediate r
) const;
22 ref
operator[](sib_scale_off_intermediate r
) const;
23 sib_scale_off_intermediate
operator+(int32_t off
) const;
27 bool valid(bool amd64
);
31 friend class sib_scale_intermediate
;
32 friend class sib_scale_off_intermediate
;
35 const static reg reg_none
;
36 const static reg reg_ax
;
37 const static reg reg_bx
;
38 const static reg reg_cx
;
39 const static reg reg_dx
;
40 const static reg reg_bp
; //Don't use in 8-bit mode.
41 const static reg reg_sp
; //Don't use in 8-bit mode.
42 const static reg reg_si
; //Don't use in 8-bit mode.
43 const static reg reg_di
; //Don't use in 8-bit mode.
44 const static reg reg_r8
;
45 const static reg reg_r9
;
46 const static reg reg_r10
;
47 const static reg reg_r11
;
48 const static reg reg_r12
;
49 const static reg reg_r13
;
50 const static reg reg_r14
;
51 const static reg reg_r15
;
52 const static reg reg_rip
;
54 struct sib_scale_off_intermediate
56 sib_scale_off_intermediate(reg idx
, uint8_t scale
, int32_t offset
);
64 struct sib_scale_intermediate
66 sib_scale_intermediate(reg idx
, uint8_t scale
);
67 sib_scale_off_intermediate
operator+(int32_t off
) const;
76 low(bool _need_amd64
, uint8_t _rex_prefix
, std::vector
<uint8_t> _ref
);
80 std::vector
<uint8_t> bytes();
81 void emit_rex(assembler::assembler
& a
);
82 void emit_bytes(assembler::assembler
& a
);
86 std::vector
<uint8_t> mref
;
92 ref(sib_scale_intermediate r
);
93 ref(sib_scale_off_intermediate r
);
94 low
operator()(reg r
, bool set_size_flag
, bool amd64
);
95 void emit(assembler::assembler
& a
, bool set_size_flag
, bool amd64
, reg r
, uint8_t op1
);
96 void emit(assembler::assembler
& a
, bool set_size_flag
, bool amd64
, reg r
, uint8_t op1
,
99 friend class sib_scale_intermediate
;
100 friend class sib_scale_off_intermediate
;
102 static ref
reg_off(reg r
, int32_t off
= 0);
103 static ref
rip_off(int32_t off
= 0);
104 static ref
sib(reg base
, reg index
, uint8_t scale
= 1, int32_t off
= 0);
107 std::vector
<uint8_t> mref
;
109 I386(assembler::assembler
& _a
, bool _amd64
);
117 void label(assembler::label
& l
);
119 void push_reg(reg r
);
122 //MOV NWORD <reg>,<regmem>
123 void mov_reg_regmem(reg r
, ref mem
);
125 void lea_reg_mem(reg r
, ref mem
);
126 //XOR NWORD <reg>,<regmem>
127 void xor_reg_regmem(reg r
, ref mem
);
128 //MOV BYTE <regmem>, imm
129 void mov_regmem_imm8(ref mem
, uint8_t imm
);
130 //ADD BYTE <regmem>, imm
131 void add_regmem_imm8(ref mem
, uint8_t imm
);
132 //MOV DWORD <regmem>, imm
133 void mov_regmem_imm32(ref mem
, uint32_t imm
);
134 //MOV WORD <regmem>, <reg>
135 void mov_regmem_reg16(ref mem
, reg r
);
136 //MOV WORD <reg>, <regmem>
137 void mov_reg_regmem16(reg r
, ref mem
);
138 //MOV BYTE <reg>, <regmem>
139 void mov_reg_regmem8(reg r
, ref mem
);
140 //MOV BYTE <regmem>, <reg>
141 void mov_regmem_reg8(ref mem
, reg r
);
142 //OR BYTE <regmem>, imm
143 void or_regmem_imm8(ref mem
, uint8_t imm
);
144 //AND BYTE <regmem>, imm
145 void and_regmem_imm8(ref mem
, uint8_t imm
);
146 //TEST BYTE <regmem>, imm
147 void test_regmem_imm8(ref mem
, uint8_t imm
);
148 //CMP BYTE <regmem>, imm
149 void cmp_regmem_imm8(ref mem
, uint8_t imm
);
150 //CMP NWORD <regmem>, imm
151 void cmp_regmem_imm(ref mem
, int32_t imm
);
152 //SHL NWORD <regmem>, imm
153 void shl_regmem_imm(ref mem
, uint8_t imm
);
154 //SHL BYTE <regmem>, imm
155 void shl_regmem_imm8(ref mem
, uint8_t imm
);
156 //AND NWORD <regmem>, imm
157 void and_regmem_imm(ref mem
, int32_t imm
);
158 //ADD NWORD <regmem>, imm
159 void add_regmem_imm(ref mem
, int32_t imm
);
160 //ADD NWORD <reg>,<regmem>
161 void add_reg_regmem(reg r
, ref mem
);
163 void inc_regmem(ref mem
);
164 //MOV NWORD <reg>, <addr>.
165 void mov_reg_addr(reg r
, assembler::label
& l
);
166 //MOV NWORD <reg>, imm.
167 void mov_reg_imm(reg r
, size_t imm
);
169 void neg_regmem8(ref mem
);
170 //OR BYTE <regmem>, <reg>
171 void or_regmem_reg8(ref mem
, reg r
);
173 void call_addr(assembler::label
& l
);
175 void call_regmem(ref mem
);
177 void setnz_regmem(ref mem
);
179 void jmp_regmem(ref mem
);
181 void jnz_short(assembler::label
& l
);
183 void jz_short(assembler::label
& l
);
185 void jz_long(assembler::label
& l
);
187 void jmp_short(assembler::label
& l
);
189 void jmp_long(assembler::label
& l
);
191 void jae_short(assembler::label
& l
);
193 void jae_long(assembler::label
& l
);
196 //Write address constant.
197 void address(assembler::label
& l
);
199 assembler::assembler
& a
;