| ... | ... | @@ -7,7 +7,6 @@ const testing = std.testing; |
| 7 | 7 | const bits = @import("bits.zig"); |
| 8 | 8 | const Encoding = @import("Encoding.zig"); |
| 9 | 9 | const FrameIndex = bits.FrameIndex; |
| 10 | | const Immediate = bits.Immediate; |
| 11 | 10 | const Register = bits.Register; |
| 12 | 11 | const Symbol = bits.Symbol; |
| 13 | 12 | |
| ... | ... | @@ -28,6 +27,55 @@ pub const Instruction = struct { |
| 28 | 27 | repnz, |
| 29 | 28 | }; |
| 30 | 29 | |
| 30 | pub const Immediate = union(enum) { |
| 31 | signed: i32, |
| 32 | unsigned: u64, |
| 33 | |
| 34 | pub fn u(x: u64) Immediate { |
| 35 | return .{ .unsigned = x }; |
| 36 | } |
| 37 | |
| 38 | pub fn s(x: i32) Immediate { |
| 39 | return .{ .signed = x }; |
| 40 | } |
| 41 | |
| 42 | pub fn asSigned(imm: Immediate, bit_size: u64) i64 { |
| 43 | return switch (imm) { |
| 44 | .signed => |x| switch (bit_size) { |
| 45 | 1, 8 => @as(i8, @intCast(x)), |
| 46 | 16 => @as(i16, @intCast(x)), |
| 47 | 32, 64 => x, |
| 48 | else => unreachable, |
| 49 | }, |
| 50 | .unsigned => |x| switch (bit_size) { |
| 51 | 1, 8 => @as(i8, @bitCast(@as(u8, @intCast(x)))), |
| 52 | 16 => @as(i16, @bitCast(@as(u16, @intCast(x)))), |
| 53 | 32 => @as(i32, @bitCast(@as(u32, @intCast(x)))), |
| 54 | 64 => @bitCast(x), |
| 55 | else => unreachable, |
| 56 | }, |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | pub fn asUnsigned(imm: Immediate, bit_size: u64) u64 { |
| 61 | return switch (imm) { |
| 62 | .signed => |x| switch (bit_size) { |
| 63 | 1, 8 => @as(u8, @bitCast(@as(i8, @intCast(x)))), |
| 64 | 16 => @as(u16, @bitCast(@as(i16, @intCast(x)))), |
| 65 | 32, 64 => @as(u32, @bitCast(x)), |
| 66 | else => unreachable, |
| 67 | }, |
| 68 | .unsigned => |x| switch (bit_size) { |
| 69 | 1, 8 => @as(u8, @intCast(x)), |
| 70 | 16 => @as(u16, @intCast(x)), |
| 71 | 32 => @as(u32, @intCast(x)), |
| 72 | 64 => x, |
| 73 | else => unreachable, |
| 74 | }, |
| 75 | }; |
| 76 | } |
| 77 | }; |
| 78 | |
| 31 | 79 | pub const Memory = union(enum) { |
| 32 | 80 | sib: Sib, |
| 33 | 81 | rip: Rip, |
| ... | ... | @@ -1119,7 +1167,7 @@ test "encode" { |
| 1119 | 1167 | |
| 1120 | 1168 | const inst = try Instruction.new(.none, .mov, &.{ |
| 1121 | 1169 | .{ .reg = .rbx }, |
| 1122 | | .{ .imm = Immediate.u(4) }, |
| 1170 | .{ .imm = Instruction.Immediate.u(4) }, |
| 1123 | 1171 | }); |
| 1124 | 1172 | try inst.encode(buf.writer(), .{}); |
| 1125 | 1173 | try testing.expectEqualSlices(u8, &.{ 0x48, 0xc7, 0xc3, 0x4, 0x0, 0x0, 0x0 }, buf.items); |
| ... | ... | @@ -1129,47 +1177,47 @@ test "lower I encoding" { |
| 1129 | 1177 | var enc = TestEncode{}; |
| 1130 | 1178 | |
| 1131 | 1179 | try enc.encode(.push, &.{ |
| 1132 | | .{ .imm = Immediate.u(0x10) }, |
| 1180 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1133 | 1181 | }); |
| 1134 | 1182 | try expectEqualHexStrings("\x6A\x10", enc.code(), "push 0x10"); |
| 1135 | 1183 | |
| 1136 | 1184 | try enc.encode(.push, &.{ |
| 1137 | | .{ .imm = Immediate.u(0x1000) }, |
| 1185 | .{ .imm = Instruction.Immediate.u(0x1000) }, |
| 1138 | 1186 | }); |
| 1139 | 1187 | try expectEqualHexStrings("\x66\x68\x00\x10", enc.code(), "push 0x1000"); |
| 1140 | 1188 | |
| 1141 | 1189 | try enc.encode(.push, &.{ |
| 1142 | | .{ .imm = Immediate.u(0x10000000) }, |
| 1190 | .{ .imm = Instruction.Immediate.u(0x10000000) }, |
| 1143 | 1191 | }); |
| 1144 | 1192 | try expectEqualHexStrings("\x68\x00\x00\x00\x10", enc.code(), "push 0x10000000"); |
| 1145 | 1193 | |
| 1146 | 1194 | try enc.encode(.adc, &.{ |
| 1147 | 1195 | .{ .reg = .rax }, |
| 1148 | | .{ .imm = Immediate.u(0x10000000) }, |
| 1196 | .{ .imm = Instruction.Immediate.u(0x10000000) }, |
| 1149 | 1197 | }); |
| 1150 | 1198 | try expectEqualHexStrings("\x48\x15\x00\x00\x00\x10", enc.code(), "adc rax, 0x10000000"); |
| 1151 | 1199 | |
| 1152 | 1200 | try enc.encode(.add, &.{ |
| 1153 | 1201 | .{ .reg = .al }, |
| 1154 | | .{ .imm = Immediate.u(0x10) }, |
| 1202 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1155 | 1203 | }); |
| 1156 | 1204 | try expectEqualHexStrings("\x04\x10", enc.code(), "add al, 0x10"); |
| 1157 | 1205 | |
| 1158 | 1206 | try enc.encode(.add, &.{ |
| 1159 | 1207 | .{ .reg = .rax }, |
| 1160 | | .{ .imm = Immediate.u(0x10) }, |
| 1208 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1161 | 1209 | }); |
| 1162 | 1210 | try expectEqualHexStrings("\x48\x83\xC0\x10", enc.code(), "add rax, 0x10"); |
| 1163 | 1211 | |
| 1164 | 1212 | try enc.encode(.sbb, &.{ |
| 1165 | 1213 | .{ .reg = .ax }, |
| 1166 | | .{ .imm = Immediate.u(0x10) }, |
| 1214 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1167 | 1215 | }); |
| 1168 | 1216 | try expectEqualHexStrings("\x66\x1D\x10\x00", enc.code(), "sbb ax, 0x10"); |
| 1169 | 1217 | |
| 1170 | 1218 | try enc.encode(.xor, &.{ |
| 1171 | 1219 | .{ .reg = .al }, |
| 1172 | | .{ .imm = Immediate.u(0x10) }, |
| 1220 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1173 | 1221 | }); |
| 1174 | 1222 | try expectEqualHexStrings("\x34\x10", enc.code(), "xor al, 0x10"); |
| 1175 | 1223 | } |
| ... | ... | @@ -1179,43 +1227,43 @@ test "lower MI encoding" { |
| 1179 | 1227 | |
| 1180 | 1228 | try enc.encode(.mov, &.{ |
| 1181 | 1229 | .{ .reg = .r12 }, |
| 1182 | | .{ .imm = Immediate.u(0x1000) }, |
| 1230 | .{ .imm = Instruction.Immediate.u(0x1000) }, |
| 1183 | 1231 | }); |
| 1184 | 1232 | try expectEqualHexStrings("\x49\xC7\xC4\x00\x10\x00\x00", enc.code(), "mov r12, 0x1000"); |
| 1185 | 1233 | |
| 1186 | 1234 | try enc.encode(.mov, &.{ |
| 1187 | 1235 | .{ .mem = Instruction.Memory.sib(.byte, .{ .base = .{ .reg = .r12 } }) }, |
| 1188 | | .{ .imm = Immediate.u(0x10) }, |
| 1236 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1189 | 1237 | }); |
| 1190 | 1238 | try expectEqualHexStrings("\x41\xC6\x04\x24\x10", enc.code(), "mov BYTE PTR [r12], 0x10"); |
| 1191 | 1239 | |
| 1192 | 1240 | try enc.encode(.mov, &.{ |
| 1193 | 1241 | .{ .reg = .r12 }, |
| 1194 | | .{ .imm = Immediate.u(0x1000) }, |
| 1242 | .{ .imm = Instruction.Immediate.u(0x1000) }, |
| 1195 | 1243 | }); |
| 1196 | 1244 | try expectEqualHexStrings("\x49\xC7\xC4\x00\x10\x00\x00", enc.code(), "mov r12, 0x1000"); |
| 1197 | 1245 | |
| 1198 | 1246 | try enc.encode(.mov, &.{ |
| 1199 | 1247 | .{ .reg = .r12 }, |
| 1200 | | .{ .imm = Immediate.u(0x1000) }, |
| 1248 | .{ .imm = Instruction.Immediate.u(0x1000) }, |
| 1201 | 1249 | }); |
| 1202 | 1250 | try expectEqualHexStrings("\x49\xC7\xC4\x00\x10\x00\x00", enc.code(), "mov r12, 0x1000"); |
| 1203 | 1251 | |
| 1204 | 1252 | try enc.encode(.mov, &.{ |
| 1205 | 1253 | .{ .reg = .rax }, |
| 1206 | | .{ .imm = Immediate.u(0x10) }, |
| 1254 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1207 | 1255 | }); |
| 1208 | 1256 | try expectEqualHexStrings("\x48\xc7\xc0\x10\x00\x00\x00", enc.code(), "mov rax, 0x10"); |
| 1209 | 1257 | |
| 1210 | 1258 | try enc.encode(.mov, &.{ |
| 1211 | 1259 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .r11 } }) }, |
| 1212 | | .{ .imm = Immediate.u(0x10) }, |
| 1260 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1213 | 1261 | }); |
| 1214 | 1262 | try expectEqualHexStrings("\x41\xc7\x03\x10\x00\x00\x00", enc.code(), "mov DWORD PTR [r11], 0x10"); |
| 1215 | 1263 | |
| 1216 | 1264 | try enc.encode(.mov, &.{ |
| 1217 | 1265 | .{ .mem = Instruction.Memory.rip(.qword, 0x10) }, |
| 1218 | | .{ .imm = Immediate.u(0x10) }, |
| 1266 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1219 | 1267 | }); |
| 1220 | 1268 | try expectEqualHexStrings( |
| 1221 | 1269 | "\x48\xC7\x05\x10\x00\x00\x00\x10\x00\x00\x00", |
| ... | ... | @@ -1225,19 +1273,19 @@ test "lower MI encoding" { |
| 1225 | 1273 | |
| 1226 | 1274 | try enc.encode(.mov, &.{ |
| 1227 | 1275 | .{ .mem = Instruction.Memory.sib(.qword, .{ .base = .{ .reg = .rbp }, .disp = -8 }) }, |
| 1228 | | .{ .imm = Immediate.u(0x10) }, |
| 1276 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1229 | 1277 | }); |
| 1230 | 1278 | try expectEqualHexStrings("\x48\xc7\x45\xf8\x10\x00\x00\x00", enc.code(), "mov QWORD PTR [rbp - 8], 0x10"); |
| 1231 | 1279 | |
| 1232 | 1280 | try enc.encode(.mov, &.{ |
| 1233 | 1281 | .{ .mem = Instruction.Memory.sib(.word, .{ .base = .{ .reg = .rbp }, .disp = -2 }) }, |
| 1234 | | .{ .imm = Immediate.s(-16) }, |
| 1282 | .{ .imm = Instruction.Immediate.s(-16) }, |
| 1235 | 1283 | }); |
| 1236 | 1284 | try expectEqualHexStrings("\x66\xC7\x45\xFE\xF0\xFF", enc.code(), "mov WORD PTR [rbp - 2], -16"); |
| 1237 | 1285 | |
| 1238 | 1286 | try enc.encode(.mov, &.{ |
| 1239 | 1287 | .{ .mem = Instruction.Memory.sib(.byte, .{ .base = .{ .reg = .rbp }, .disp = -1 }) }, |
| 1240 | | .{ .imm = Immediate.u(0x10) }, |
| 1288 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1241 | 1289 | }); |
| 1242 | 1290 | try expectEqualHexStrings("\xC6\x45\xFF\x10", enc.code(), "mov BYTE PTR [rbp - 1], 0x10"); |
| 1243 | 1291 | |
| ... | ... | @@ -1247,7 +1295,7 @@ test "lower MI encoding" { |
| 1247 | 1295 | .disp = 0x10000000, |
| 1248 | 1296 | .scale_index = .{ .scale = 2, .index = .rcx }, |
| 1249 | 1297 | }) }, |
| 1250 | | .{ .imm = Immediate.u(0x10) }, |
| 1298 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1251 | 1299 | }); |
| 1252 | 1300 | try expectEqualHexStrings( |
| 1253 | 1301 | "\x48\xC7\x04\x4D\x00\x00\x00\x10\x10\x00\x00\x00", |
| ... | ... | @@ -1257,43 +1305,43 @@ test "lower MI encoding" { |
| 1257 | 1305 | |
| 1258 | 1306 | try enc.encode(.adc, &.{ |
| 1259 | 1307 | .{ .mem = Instruction.Memory.sib(.byte, .{ .base = .{ .reg = .rbp }, .disp = -0x10 }) }, |
| 1260 | | .{ .imm = Immediate.u(0x10) }, |
| 1308 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1261 | 1309 | }); |
| 1262 | 1310 | try expectEqualHexStrings("\x80\x55\xF0\x10", enc.code(), "adc BYTE PTR [rbp - 0x10], 0x10"); |
| 1263 | 1311 | |
| 1264 | 1312 | try enc.encode(.adc, &.{ |
| 1265 | 1313 | .{ .mem = Instruction.Memory.rip(.qword, 0) }, |
| 1266 | | .{ .imm = Immediate.u(0x10) }, |
| 1314 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1267 | 1315 | }); |
| 1268 | 1316 | try expectEqualHexStrings("\x48\x83\x15\x00\x00\x00\x00\x10", enc.code(), "adc QWORD PTR [rip], 0x10"); |
| 1269 | 1317 | |
| 1270 | 1318 | try enc.encode(.adc, &.{ |
| 1271 | 1319 | .{ .reg = .rax }, |
| 1272 | | .{ .imm = Immediate.u(0x10) }, |
| 1320 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1273 | 1321 | }); |
| 1274 | 1322 | try expectEqualHexStrings("\x48\x83\xD0\x10", enc.code(), "adc rax, 0x10"); |
| 1275 | 1323 | |
| 1276 | 1324 | try enc.encode(.add, &.{ |
| 1277 | 1325 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .rdx }, .disp = -8 }) }, |
| 1278 | | .{ .imm = Immediate.u(0x10) }, |
| 1326 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1279 | 1327 | }); |
| 1280 | 1328 | try expectEqualHexStrings("\x83\x42\xF8\x10", enc.code(), "add DWORD PTR [rdx - 8], 0x10"); |
| 1281 | 1329 | |
| 1282 | 1330 | try enc.encode(.add, &.{ |
| 1283 | 1331 | .{ .reg = .rax }, |
| 1284 | | .{ .imm = Immediate.u(0x10) }, |
| 1332 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1285 | 1333 | }); |
| 1286 | 1334 | try expectEqualHexStrings("\x48\x83\xC0\x10", enc.code(), "add rax, 0x10"); |
| 1287 | 1335 | |
| 1288 | 1336 | try enc.encode(.add, &.{ |
| 1289 | 1337 | .{ .mem = Instruction.Memory.sib(.qword, .{ .base = .{ .reg = .rbp }, .disp = -0x10 }) }, |
| 1290 | | .{ .imm = Immediate.s(-0x10) }, |
| 1338 | .{ .imm = Instruction.Immediate.s(-0x10) }, |
| 1291 | 1339 | }); |
| 1292 | 1340 | try expectEqualHexStrings("\x48\x83\x45\xF0\xF0", enc.code(), "add QWORD PTR [rbp - 0x10], -0x10"); |
| 1293 | 1341 | |
| 1294 | 1342 | try enc.encode(.@"and", &.{ |
| 1295 | 1343 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .ds }, .disp = 0x10000000 }) }, |
| 1296 | | .{ .imm = Immediate.u(0x10) }, |
| 1344 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1297 | 1345 | }); |
| 1298 | 1346 | try expectEqualHexStrings( |
| 1299 | 1347 | "\x83\x24\x25\x00\x00\x00\x10\x10", |
| ... | ... | @@ -1303,7 +1351,7 @@ test "lower MI encoding" { |
| 1303 | 1351 | |
| 1304 | 1352 | try enc.encode(.@"and", &.{ |
| 1305 | 1353 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .es }, .disp = 0x10000000 }) }, |
| 1306 | | .{ .imm = Immediate.u(0x10) }, |
| 1354 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1307 | 1355 | }); |
| 1308 | 1356 | try expectEqualHexStrings( |
| 1309 | 1357 | "\x26\x83\x24\x25\x00\x00\x00\x10\x10", |
| ... | ... | @@ -1313,7 +1361,7 @@ test "lower MI encoding" { |
| 1313 | 1361 | |
| 1314 | 1362 | try enc.encode(.@"and", &.{ |
| 1315 | 1363 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .r12 }, .disp = 0x10000000 }) }, |
| 1316 | | .{ .imm = Immediate.u(0x10) }, |
| 1364 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1317 | 1365 | }); |
| 1318 | 1366 | try expectEqualHexStrings( |
| 1319 | 1367 | "\x41\x83\xA4\x24\x00\x00\x00\x10\x10", |
| ... | ... | @@ -1323,7 +1371,7 @@ test "lower MI encoding" { |
| 1323 | 1371 | |
| 1324 | 1372 | try enc.encode(.sub, &.{ |
| 1325 | 1373 | .{ .mem = Instruction.Memory.sib(.dword, .{ .base = .{ .reg = .r11 }, .disp = 0x10000000 }) }, |
| 1326 | | .{ .imm = Immediate.u(0x10) }, |
| 1374 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1327 | 1375 | }); |
| 1328 | 1376 | try expectEqualHexStrings( |
| 1329 | 1377 | "\x41\x83\xAB\x00\x00\x00\x10\x10", |
| ... | ... | @@ -1542,14 +1590,14 @@ test "lower RMI encoding" { |
| 1542 | 1590 | try enc.encode(.imul, &.{ |
| 1543 | 1591 | .{ .reg = .r11 }, |
| 1544 | 1592 | .{ .reg = .r12 }, |
| 1545 | | .{ .imm = Immediate.s(-2) }, |
| 1593 | .{ .imm = Instruction.Immediate.s(-2) }, |
| 1546 | 1594 | }); |
| 1547 | 1595 | try expectEqualHexStrings("\x4D\x6B\xDC\xFE", enc.code(), "imul r11, r12, -2"); |
| 1548 | 1596 | |
| 1549 | 1597 | try enc.encode(.imul, &.{ |
| 1550 | 1598 | .{ .reg = .r11 }, |
| 1551 | 1599 | .{ .mem = Instruction.Memory.rip(.qword, -16) }, |
| 1552 | | .{ .imm = Immediate.s(-1024) }, |
| 1600 | .{ .imm = Instruction.Immediate.s(-1024) }, |
| 1553 | 1601 | }); |
| 1554 | 1602 | try expectEqualHexStrings( |
| 1555 | 1603 | "\x4C\x69\x1D\xF0\xFF\xFF\xFF\x00\xFC\xFF\xFF", |
| ... | ... | @@ -1560,7 +1608,7 @@ test "lower RMI encoding" { |
| 1560 | 1608 | try enc.encode(.imul, &.{ |
| 1561 | 1609 | .{ .reg = .bx }, |
| 1562 | 1610 | .{ .mem = Instruction.Memory.sib(.word, .{ .base = .{ .reg = .rbp }, .disp = -16 }) }, |
| 1563 | | .{ .imm = Immediate.s(-1024) }, |
| 1611 | .{ .imm = Instruction.Immediate.s(-1024) }, |
| 1564 | 1612 | }); |
| 1565 | 1613 | try expectEqualHexStrings( |
| 1566 | 1614 | "\x66\x69\x5D\xF0\x00\xFC", |
| ... | ... | @@ -1571,7 +1619,7 @@ test "lower RMI encoding" { |
| 1571 | 1619 | try enc.encode(.imul, &.{ |
| 1572 | 1620 | .{ .reg = .bx }, |
| 1573 | 1621 | .{ .mem = Instruction.Memory.sib(.word, .{ .base = .{ .reg = .rbp }, .disp = -16 }) }, |
| 1574 | | .{ .imm = Immediate.u(1024) }, |
| 1622 | .{ .imm = Instruction.Immediate.u(1024) }, |
| 1575 | 1623 | }); |
| 1576 | 1624 | try expectEqualHexStrings( |
| 1577 | 1625 | "\x66\x69\x5D\xF0\x00\x04", |
| ... | ... | @@ -1687,7 +1735,7 @@ test "lower M encoding" { |
| 1687 | 1735 | try expectEqualHexStrings("\x65\xFF\x14\x25\x00\x00\x00\x00", enc.code(), "call gs:0x0"); |
| 1688 | 1736 | |
| 1689 | 1737 | try enc.encode(.call, &.{ |
| 1690 | | .{ .imm = Immediate.s(0) }, |
| 1738 | .{ .imm = Instruction.Immediate.s(0) }, |
| 1691 | 1739 | }); |
| 1692 | 1740 | try expectEqualHexStrings("\xE8\x00\x00\x00\x00", enc.code(), "call 0x0"); |
| 1693 | 1741 | |
| ... | ... | @@ -1746,7 +1794,7 @@ test "lower OI encoding" { |
| 1746 | 1794 | |
| 1747 | 1795 | try enc.encode(.mov, &.{ |
| 1748 | 1796 | .{ .reg = .rax }, |
| 1749 | | .{ .imm = Immediate.u(0x1000000000000000) }, |
| 1797 | .{ .imm = Instruction.Immediate.u(0x1000000000000000) }, |
| 1750 | 1798 | }); |
| 1751 | 1799 | try expectEqualHexStrings( |
| 1752 | 1800 | "\x48\xB8\x00\x00\x00\x00\x00\x00\x00\x10", |
| ... | ... | @@ -1756,7 +1804,7 @@ test "lower OI encoding" { |
| 1756 | 1804 | |
| 1757 | 1805 | try enc.encode(.mov, &.{ |
| 1758 | 1806 | .{ .reg = .r11 }, |
| 1759 | | .{ .imm = Immediate.u(0x1000000000000000) }, |
| 1807 | .{ .imm = Instruction.Immediate.u(0x1000000000000000) }, |
| 1760 | 1808 | }); |
| 1761 | 1809 | try expectEqualHexStrings( |
| 1762 | 1810 | "\x49\xBB\x00\x00\x00\x00\x00\x00\x00\x10", |
| ... | ... | @@ -1766,19 +1814,19 @@ test "lower OI encoding" { |
| 1766 | 1814 | |
| 1767 | 1815 | try enc.encode(.mov, &.{ |
| 1768 | 1816 | .{ .reg = .r11d }, |
| 1769 | | .{ .imm = Immediate.u(0x10000000) }, |
| 1817 | .{ .imm = Instruction.Immediate.u(0x10000000) }, |
| 1770 | 1818 | }); |
| 1771 | 1819 | try expectEqualHexStrings("\x41\xBB\x00\x00\x00\x10", enc.code(), "mov r11d, 0x10000000"); |
| 1772 | 1820 | |
| 1773 | 1821 | try enc.encode(.mov, &.{ |
| 1774 | 1822 | .{ .reg = .r11w }, |
| 1775 | | .{ .imm = Immediate.u(0x1000) }, |
| 1823 | .{ .imm = Instruction.Immediate.u(0x1000) }, |
| 1776 | 1824 | }); |
| 1777 | 1825 | try expectEqualHexStrings("\x66\x41\xBB\x00\x10", enc.code(), "mov r11w, 0x1000"); |
| 1778 | 1826 | |
| 1779 | 1827 | try enc.encode(.mov, &.{ |
| 1780 | 1828 | .{ .reg = .r11b }, |
| 1781 | | .{ .imm = Immediate.u(0x10) }, |
| 1829 | .{ .imm = Instruction.Immediate.u(0x10) }, |
| 1782 | 1830 | }); |
| 1783 | 1831 | try expectEqualHexStrings("\x41\xB3\x10", enc.code(), "mov r11b, 0x10"); |
| 1784 | 1832 | } |
| ... | ... | @@ -1900,7 +1948,7 @@ test "invalid instruction" { |
| 1900 | 1948 | .{ .reg = .r12d }, |
| 1901 | 1949 | }); |
| 1902 | 1950 | try invalidInstruction(.push, &.{ |
| 1903 | | .{ .imm = Immediate.u(0x1000000000000000) }, |
| 1951 | .{ .imm = Instruction.Immediate.u(0x1000000000000000) }, |
| 1904 | 1952 | }); |
| 1905 | 1953 | } |
| 1906 | 1954 | |
| ... | ... | @@ -2213,7 +2261,7 @@ const Assembler = struct { |
| 2213 | 2261 | .immediate => { |
| 2214 | 2262 | const is_neg = if (as.expect(.minus)) |_| true else |_| false; |
| 2215 | 2263 | const imm_tok = try as.expect(.numeral); |
| 2216 | | const imm: Immediate = if (is_neg) blk: { |
| 2264 | const imm: Instruction.Immediate = if (is_neg) blk: { |
| 2217 | 2265 | const imm = try std.fmt.parseInt(i32, as.source(imm_tok), 0); |
| 2218 | 2266 | break :blk .{ .signed = imm * -1 }; |
| 2219 | 2267 | } else .{ .unsigned = try std.fmt.parseInt(u64, as.source(imm_tok), 0) }; |