@@ -113,6 +113,27 @@ sub emitl {
113
113
emit( ( $v >> 24 ) & 0xFF );
114
114
}
115
115
116
+ sub emit_rex_64 {
117
+ my ($reg , $rm_reg ) = @_ ;
118
+ if ( is_register($reg ) && is_register($rm_reg ) ) {
119
+ emit(0x48 | $reg -> high_bit() << 2 | $rm_reg -> high_bit());
120
+ }
121
+ else {
122
+ die " emit_rex_64: don't know what to do with $reg , $rm_reg " ;
123
+ }
124
+ }
125
+
126
+ # Emit a ModR/M byte with registers coded in the reg and rm_reg fields.
127
+ sub emit_modrm {
128
+ my ($reg , $rm_reg ) = @_ ;
129
+ if ( is_register($reg ) && is_register($rm_reg ) ) {
130
+ emit(0xC0 | $reg -> low_bits() << 3 | $rm_reg -> low_bits());
131
+ }
132
+ else {
133
+ die " emit_modrm: don't know what to do with $reg , $rm_reg " ;
134
+ }
135
+ }
136
+
116
137
sub is_register {
117
138
ref ($_ [0]) eq ' Perlito5::X64::Register'
118
139
}
@@ -140,6 +161,56 @@ sub is_uint16 {
140
161
141
162
# --- instructions
142
163
164
+ sub _movl {
165
+ my ( $dst , $src ) = @_ ;
166
+ if ( is_register($dst ) && is_register($src ) ) {
167
+ if ($src -> low_bits() == 4) {
168
+ emit_optional_rex_32($src , $dst );
169
+ emit(0x89);
170
+ emit_modrm($src , $dst );
171
+ }
172
+ else {
173
+ emit_optional_rex_32($dst , $src );
174
+ emit(0x8B);
175
+ emit_modrm($dst , $src );
176
+ }
177
+ }
178
+ else {
179
+ die " movl: don't know what to do with $dst , $src " ;
180
+ }
181
+ }
182
+
183
+ sub _movq {
184
+ my ( $dst , $src ) = @_ ;
185
+ if ( is_register($dst ) && is_register($src ) ) {
186
+ if ($src -> low_bits() == 4) {
187
+ emit_rex_64($src , $dst );
188
+ emit(0x89);
189
+ emit_modrm($src , $dst );
190
+ }
191
+ else {
192
+ emit_rex_64($dst , $src );
193
+ emit(0x8B);
194
+ emit_modrm($dst , $src );
195
+ }
196
+ }
197
+ else {
198
+ die " movq: don't know what to do with $dst , $src " ;
199
+ }
200
+ }
201
+
202
+ sub _movsxlq {
203
+ my ( $dst , $src ) = @_ ;
204
+ if ( is_register($dst ) && is_register($src ) ) {
205
+ emit_rex_64($src , $dst );
206
+ emit(0x63);
207
+ emit_modrm($src , $dst );
208
+ }
209
+ else {
210
+ die " movsxlq: don't know what to do with $dst , $src " ;
211
+ }
212
+ }
213
+
143
214
sub _nop {
144
215
emit(0x90);
145
216
}
0 commit comments