1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235
|
; flat assembler core
; Copyright (c) 1999-2021, Tomasz Grysztar.
; All rights reserved.
assembler:
xor eax,eax
mov [stub_size],eax
mov [current_pass],ax
mov [resolver_flags],eax
mov [number_of_sections],eax
mov [actual_fixups_size],eax
assembler_loop:
mov eax,[labels_list]
mov [tagged_blocks],eax
mov eax,[additional_memory]
mov [free_additional_memory],eax
mov eax,[additional_memory_end]
mov [structures_buffer],eax
mov esi,[source_start]
mov edi,[code_start]
xor eax,eax
mov dword [adjustment],eax
mov dword [adjustment+4],eax
mov [addressing_space],eax
mov [error_line],eax
mov [counter],eax
mov [format_flags],eax
mov [number_of_relocations],eax
mov [undefined_data_end],eax
mov [file_extension],eax
mov [next_pass_needed],al
mov [output_format],al
mov [adjustment_sign],al
mov [evex_mode],al
mov [code_type],16
call init_addressing_space
pass_loop:
call assemble_line
jnc pass_loop
mov eax,[additional_memory_end]
cmp eax,[structures_buffer]
je pass_done
sub eax,18h
mov eax,[eax+4]
mov [current_line],eax
jmp missing_end_directive
pass_done:
call close_pass
mov eax,[labels_list]
check_symbols:
cmp eax,[memory_end]
jae symbols_checked
test byte [eax+8],8
jz symbol_defined_ok
mov cx,[current_pass]
cmp cx,[eax+18]
jne symbol_defined_ok
test byte [eax+8],1
jz symbol_defined_ok
sub cx,[eax+16]
cmp cx,1
jne symbol_defined_ok
and byte [eax+8],not 1
or [next_pass_needed],-1
symbol_defined_ok:
test byte [eax+8],10h
jz use_prediction_ok
mov cx,[current_pass]
and byte [eax+8],not 10h
test byte [eax+8],20h
jnz check_use_prediction
cmp cx,[eax+18]
jne use_prediction_ok
test byte [eax+8],8
jz use_prediction_ok
jmp use_misprediction
check_use_prediction:
test byte [eax+8],8
jz use_misprediction
cmp cx,[eax+18]
je use_prediction_ok
use_misprediction:
or [next_pass_needed],-1
use_prediction_ok:
test byte [eax+8],40h
jz check_next_symbol
and byte [eax+8],not 40h
test byte [eax+8],4
jnz define_misprediction
mov cx,[current_pass]
test byte [eax+8],80h
jnz check_define_prediction
cmp cx,[eax+16]
jne check_next_symbol
test byte [eax+8],1
jz check_next_symbol
jmp define_misprediction
check_define_prediction:
test byte [eax+8],1
jz define_misprediction
cmp cx,[eax+16]
je check_next_symbol
define_misprediction:
or [next_pass_needed],-1
check_next_symbol:
add eax,LABEL_STRUCTURE_SIZE
jmp check_symbols
symbols_checked:
cmp [next_pass_needed],0
jne next_pass
mov eax,[error_line]
or eax,eax
jz assemble_ok
mov [current_line],eax
cmp [error],undefined_symbol
jne error_confirmed
mov eax,[error_info]
or eax,eax
jz error_confirmed
test byte [eax+8],1
jnz next_pass
error_confirmed:
call error_handler
error_handler:
mov eax,[error]
sub eax,error_handler
add [esp],eax
ret
next_pass:
inc [current_pass]
mov ax,[current_pass]
cmp ax,[passes_limit]
je code_cannot_be_generated
jmp assembler_loop
assemble_ok:
ret
create_addressing_space:
mov ebx,[addressing_space]
test ebx,ebx
jz init_addressing_space
test byte [ebx+0Ah],1
jnz illegal_instruction
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
init_addressing_space:
mov ebx,[tagged_blocks]
mov dword [ebx-4],10h
mov dword [ebx-8],24h
sub ebx,8+24h
cmp ebx,edi
jbe out_of_memory
mov [tagged_blocks],ebx
mov [addressing_space],ebx
xor eax,eax
mov [ebx],edi
mov [ebx+4],eax
mov [ebx+8],eax
mov [ebx+10h],eax
mov [ebx+14h],eax
mov [ebx+18h],edi
mov [ebx+1Ch],eax
mov [ebx+20h],eax
ret
assemble_line:
mov eax,[tagged_blocks]
sub eax,100h
cmp edi,eax
ja out_of_memory
lods byte [esi]
cmp al,1
je assemble_instruction
jb source_end
cmp al,3
jb define_label
je define_constant
cmp al,4
je label_addressing_space
cmp al,0Fh
je new_line
cmp al,13h
je code_type_setting
cmp al,10h
jne illegal_instruction
lods byte [esi]
jmp segment_prefix
code_type_setting:
lods byte [esi]
mov [code_type],al
jmp instruction_assembled
new_line:
lods dword [esi]
mov [current_line],eax
and [prefix_flags],0
cmp [symbols_file],0
je continue_line
cmp [next_pass_needed],0
jne continue_line
mov ebx,[tagged_blocks]
mov dword [ebx-4],1
mov dword [ebx-8],14h
sub ebx,8+14h
cmp ebx,edi
jbe out_of_memory
mov [tagged_blocks],ebx
mov [ebx],eax
mov [ebx+4],edi
mov eax,[addressing_space]
mov [ebx+8],eax
mov al,[code_type]
mov [ebx+10h],al
continue_line:
cmp byte [esi],0Fh
je line_assembled
jmp assemble_line
define_label:
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov ebx,eax
lods byte [esi]
mov [label_size],al
call make_label
jmp continue_line
make_label:
mov eax,edi
xor edx,edx
xor cl,cl
mov ebp,[addressing_space]
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb cl,[ds:ebp+8]
jp label_value_ok
call recoverable_overflow
label_value_ok:
mov [address_sign],cl
test byte [ds:ebp+0Ah],1
jnz make_virtual_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
mov ch,[ebx+9]
shr ch,1
and ch,1
neg ch
sub eax,[ebx]
sbb edx,[ebx+4]
sbb ch,cl
mov dword [adjustment],eax
mov dword [adjustment+4],edx
mov [adjustment_sign],ch
or al,ch
or eax,edx
setnz ah
jmp finish_label
make_virtual_label:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
finish_label:
mov ebp,[addressing_space]
mov ch,[ds:ebp+9]
mov cl,[label_size]
mov edx,[ds:ebp+14h]
mov ebp,[ds:ebp+10h]
finish_label_symbol:
mov al,[address_sign]
xor al,[ebx+9]
and al,10b
or ah,al
xor [ebx+9],al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
cmp ebp,[ebx+12]
mov [ebx+12],ebp
setne al
or ah,al
or ch,ch
jz label_symbol_ok
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
label_symbol_ok:
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
and byte [ebx+8],not 2
test byte [ebx+8],1
jz new_label
cmp cx,[ebx+16]
je symbol_already_defined
btr dword [ebx+8],10
jc requalified_label
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz label_made
test byte [ebx+8],8
jz label_made
mov cx,[current_pass]
cmp cx,[ebx+18]
jne label_made
requalified_label:
or [next_pass_needed],-1
label_made:
ret
new_label:
or byte [ebx+8],1
ret
define_constant:
lods dword [esi]
inc esi
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
push eax
or [operand_flags],1
call get_value
pop ebx
xor cl,cl
mov ch,[value_type]
cmp ch,3
je invalid_use_of_symbol
make_constant:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
mov al,[value_sign]
xor al,[ebx+9]
and al,10b
or ah,al
xor [ebx+9],al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
xor edx,edx
cmp edx,[ebx+12]
mov [ebx+12],edx
setne al
or ah,al
or ch,ch
jz constant_symbol_ok
mov edx,[symbol_identifier]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
constant_symbol_ok:
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
test byte [ebx+8],1
jz new_constant
cmp cx,[ebx+16]
jne redeclare_constant
test byte [ebx+8],2
jz symbol_already_defined
or byte [ebx+8],4
and byte [ebx+9],not 4
jmp instruction_assembled
redeclare_constant:
btr dword [ebx+8],10
jc requalified_constant
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz instruction_assembled
test byte [ebx+8],4
jnz instruction_assembled
test byte [ebx+8],8
jz instruction_assembled
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
requalified_constant:
or [next_pass_needed],-1
jmp instruction_assembled
new_constant:
or byte [ebx+8],1+2
jmp instruction_assembled
label_addressing_space:
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov cx,[current_pass]
test byte [eax+8],1
jz make_addressing_space_label
cmp cx,[eax+16]
je symbol_already_defined
test byte [eax+9],4
jnz make_addressing_space_label
or [next_pass_needed],-1
make_addressing_space_label:
mov dx,[eax+8]
and dx,not (2 or 100h)
or dx,1 or 4 or 400h
mov [eax+8],dx
mov [eax+16],cx
mov edx,[current_line]
mov [eax+28],edx
mov ebx,[addressing_space]
mov [eax],ebx
or byte [ebx+0Ah],2
jmp continue_line
assemble_instruction:
; mov [operand_size],0
; mov [operand_flags],0
; mov [operand_prefix],0
; mov [rex_prefix],0
and dword [operand_size],0
; mov [opcode_prefix],0
; mov [vex_required],0
; mov [vex_register],0
; mov [immediate_size],0
and dword [opcode_prefix],0
call instruction_handler
instruction_handler:
movzx ebx,word [esi]
mov al,[esi+2]
add esi,3
add [esp],ebx
ret
instruction_assembled:
test [prefix_flags],not 1
jnz illegal_instruction
mov al,[esi]
cmp al,0Fh
je line_assembled
or al,al
jnz extra_characters_on_line
line_assembled:
clc
ret
source_end:
dec esi
stc
ret
org_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
mov cl,[value_type]
test cl,1
jnz invalid_use_of_symbol
push eax
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
test byte [ebx+0Ah],1
jnz in_virtual
call init_addressing_space
jmp org_space_ok
in_virtual:
call close_virtual_addressing_space
call init_addressing_space
or byte [ebx+0Ah],1
org_space_ok:
pop eax
mov [ebx+9],cl
mov cl,[value_sign]
sub [ebx],eax
sbb [ebx+4],edx
sbb byte [ebx+8],cl
jp org_value_ok
call recoverable_overflow
org_value_ok:
mov edx,[symbol_identifier]
mov [ebx+14h],edx
cmp [output_format],1
ja instruction_assembled
cmp edi,[code_start]
jne instruction_assembled
cmp eax,100h
jne instruction_assembled
bts [format_flags],0
jmp instruction_assembled
label_directive:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
mov [label_size],0
lods byte [esi]
cmp al,':'
je get_label_size
dec esi
cmp al,11h
jne label_size_ok
get_label_size:
lods word [esi]
cmp al,11h
jne invalid_argument
mov [label_size],ah
label_size_ok:
cmp byte [esi],80h
je get_free_label_value
call make_label
jmp instruction_assembled
get_free_label_value:
inc esi
lods byte [esi]
cmp al,'('
jne invalid_argument
push ebx ecx
or byte [ebx+8],4
cmp byte [esi],'.'
je invalid_value
call get_address_value
or bh,bh
setnz ch
xchg ch,cl
mov bp,cx
shl ebp,16
xchg bl,bh
mov bp,bx
pop ecx ebx
and byte [ebx+8],not 4
mov ch,[value_type]
test ch,1
jnz invalid_use_of_symbol
make_free_label:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
mov edx,[address_symbol]
mov cl,[label_size]
call finish_label_symbol
jmp instruction_assembled
load_directive:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
push eax
mov al,1
cmp byte [esi],11h
jne load_size_ok
lods byte [esi]
lods byte [esi]
load_size_ok:
cmp al,8
ja invalid_value
mov [operand_size],al
and dword [value],0
and dword [value+4],0
lods byte [esi]
cmp al,82h
jne invalid_argument
call get_data_point
jc value_loaded
push esi edi
mov esi,ebx
mov edi,value
rep movs byte [edi],[esi]
pop edi esi
value_loaded:
mov [value_sign],0
mov eax,dword [value]
mov edx,dword [value+4]
pop ebx
xor cx,cx
jmp make_constant
get_data_point:
lods byte [esi]
cmp al,':'
je get_data_offset
cmp al,'('
jne invalid_argument
mov ebx,[addressing_space]
mov ecx,edi
sub ecx,[ebx+18h]
mov [ebx+1Ch],ecx
cmp byte [esi],11h
jne get_data_address
cmp word [esi+1+4],'):'
jne get_data_address
inc esi
lods dword [esi]
add esi,2
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp eax,0Fh
jbe reserved_word_used_as_symbol
mov edx,undefined_symbol
test byte [eax+8],1
jz addressing_space_unavailable
mov edx,symbol_out_of_scope
mov cx,[eax+16]
cmp cx,[current_pass]
jne addressing_space_unavailable
test byte [eax+9],4
jz invalid_use_of_symbol
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
or byte [ebx+8],8
call store_label_reference
get_addressing_space:
mov ebx,[ebx]
get_data_address:
push ebx
cmp byte [esi],'.'
je invalid_value
or [operand_flags],1
call get_address_value
pop ebp
call calculate_relative_offset
cmp [next_pass_needed],0
jne data_address_type_ok
cmp [value_type],0
jne invalid_use_of_symbol
data_address_type_ok:
mov ebx,edi
xor ecx,ecx
add ebx,eax
adc edx,ecx
mov eax,ebx
sub eax,[ds:ebp+18h]
sbb edx,ecx
jnz bad_data_address
mov cl,[operand_size]
add eax,ecx
cmp eax,[ds:ebp+1Ch]
ja bad_data_address
clc
ret
addressing_space_unavailable:
cmp [error_line],0
jne get_data_address
push [current_line]
pop [error_line]
mov [error],edx
mov [error_info],eax
jmp get_data_address
bad_data_address:
call recoverable_overflow
stc
ret
get_data_offset:
cmp [output_format],2
jae invalid_operand
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
je data_offset_ok
call recoverable_invalid_address
data_offset_ok:
add eax,[code_start]
jc bad_data_address
mov ebx,eax
movzx ecx,[operand_size]
add eax,ecx
jc bad_data_address
mov edx,[addressing_space]
test byte [edx+0Ah],1
jnz data_offset_from_virtual
cmp eax,edi
ja bad_data_address
clc
ret
data_offset_from_virtual:
cmp eax,[undefined_data_end]
ja bad_data_address
clc
ret
store_directive:
cmp byte [esi],11h
je sized_store
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_byte_value
xor edx,edx
movzx eax,al
mov [operand_size],1
jmp store_value_ok
sized_store:
or [operand_flags],1
call get_value
store_value_ok:
cmp [value_type],0
jne invalid_use_of_symbol
mov dword [value],eax
mov dword [value+4],edx
lods byte [esi]
cmp al,80h
jne invalid_argument
call get_data_point
jc instruction_assembled
push esi edi
mov esi,value
mov edi,ebx
rep movs byte [edi],[esi]
mov eax,edi
pop edi esi
cmp ebx,[undefined_data_end]
jae instruction_assembled
cmp eax,[undefined_data_start]
jbe instruction_assembled
mov [undefined_data_start],eax
jmp instruction_assembled
display_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],0
jne display_byte
inc esi
lods dword [esi]
mov ecx,eax
push edi
mov edi,[tagged_blocks]
sub edi,8
sub edi,eax
cmp edi,[esp]
jbe out_of_memory
mov [tagged_blocks],edi
rep movs byte [edi],[esi]
stos dword [edi]
xor eax,eax
stos dword [edi]
pop edi
inc esi
jmp display_next
display_byte:
call get_byte_value
push edi
mov edi,[tagged_blocks]
sub edi,8+1
mov [tagged_blocks],edi
stos byte [edi]
mov eax,1
stos dword [edi]
dec eax
stos dword [edi]
pop edi
display_next:
cmp edi,[tagged_blocks]
ja out_of_memory
lods byte [esi]
cmp al,','
je display_directive
dec esi
jmp instruction_assembled
show_display_buffer:
mov eax,[tagged_blocks]
or eax,eax
jz display_done
mov esi,[labels_list]
cmp esi,eax
je display_done
display_messages:
sub esi,8
mov eax,[esi+4]
mov ecx,[esi]
sub esi,ecx
cmp eax,10h
je write_addressing_space
test eax,eax
jnz skip_block
push esi
call display_block
pop esi
skip_block:
cmp esi,[tagged_blocks]
jne display_messages
display_done:
ret
write_addressing_space:
mov ecx,[esi+20h]
jecxz skip_block
push esi
mov edi,[free_additional_memory]
mov esi,[output_file]
test esi,esi
jz addressing_space_written
xor ebx,ebx
copy_output_path:
lodsb
cmp edi,[structures_buffer]
jae out_of_memory
stosb
test al,al
jz output_path_copied
cmp al,'/'
je new_path_segment
cmp al,'\'
je new_path_segment
cmp al,'.'
jne copy_output_path
mov ebx,edi
jmp copy_output_path
new_path_segment:
xor ebx,ebx
jmp copy_output_path
output_path_copied:
test ebx,ebx
jnz append_extension
mov byte [edi-1],'.'
mov ebx,edi
append_extension:
mov edi,ebx
add ebx,ecx
inc ebx
cmp ebx,[structures_buffer]
jae out_of_memory
mov esi,[esp]
mov esi,[esi+18h]
sub esi,ecx
rep movs byte [edi],[esi]
xor al,al
stos byte [edi]
mov edx,[free_additional_memory]
call create
jc write_failed
mov esi,[esp]
mov edx,[esi+18h]
mov ecx,[esi+1Ch]
call write
jc write_failed
call close
addressing_space_written:
pop esi
jmp skip_block
times_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
cmp eax,0
je zero_times
cmp byte [esi],':'
jne times_argument_ok
inc esi
times_argument_ok:
push [counter]
push [counter_limit]
mov [counter_limit],eax
mov [counter],1
times_loop:
mov eax,esp
sub eax,[stack_limit]
cmp eax,100h
jb stack_overflow
push esi
or [prefix_flags],1
call continue_line
mov eax,[counter_limit]
cmp [counter],eax
je times_done
inc [counter]
pop esi
jmp times_loop
times_done:
pop eax
pop [counter_limit]
pop [counter]
jmp instruction_assembled
zero_times:
call skip_symbol
jnc zero_times
jmp instruction_assembled
virtual_directive:
lods byte [esi]
cmp al,'('
je continue_virtual_area
cmp al,80h
jne virtual_at_current
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_address_value
mov ebp,[address_symbol]
or bh,bh
setnz ch
jmp set_virtual
virtual_at_current:
dec esi
virtual_fallback:
mov ebp,[addressing_space]
mov al,[ds:ebp+9]
mov [value_type],al
mov eax,edi
xor edx,edx
xor cl,cl
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb cl,[ds:ebp+8]
mov [address_sign],cl
mov bx,[ds:ebp+10h]
mov cx,[ds:ebp+10h+2]
xchg bh,bl
xchg ch,cl
mov ebp,[ds:ebp+14h]
set_virtual:
xchg bl,bh
xchg cl,ch
shl ecx,16
mov cx,bx
push ecx eax
mov ebx,[addressing_space]
test byte [ebx+0Ah],1
jnz non_virtual_end_ok
mov eax,edi
xchg eax,[undefined_data_end]
cmp eax,edi
je non_virtual_end_ok
mov [undefined_data_start],edi
non_virtual_end_ok:
call allocate_virtual_structure_data
call init_addressing_space
or byte [ebx+0Ah],1
cmp byte [esi],86h
jne addressing_space_extension_ok
cmp word [esi+1],'('
jne invalid_argument
mov ecx,[esi+3]
add esi,3+4
add [ebx+18h],ecx
mov [ebx+20h],ecx
or byte [ebx+0Ah],2
push ebx
mov ebx,characters
get_extension:
lods byte [esi]
stos byte [edi]
xlat byte [ebx]
test al,al
jz invalid_argument
loop get_extension
inc esi
pop ebx
addressing_space_extension_ok:
pop eax
mov cl,[address_sign]
not eax
not edx
not cl
add eax,1
adc edx,0
adc cl,0
add eax,edi
adc edx,0
adc cl,0
mov [ebx],eax
mov [ebx+4],edx
mov [ebx+8],cl
pop dword [ebx+10h]
mov [ebx+14h],ebp
mov al,[value_type]
test al,1
jnz invalid_use_of_symbol
mov [ebx+9],al
jmp instruction_assembled
allocate_structure_data:
mov ebx,[structures_buffer]
sub ebx,18h
cmp ebx,[free_additional_memory]
jb out_of_memory
mov [structures_buffer],ebx
ret
find_structure_data:
mov ebx,[structures_buffer]
scan_structures:
cmp ebx,[additional_memory_end]
je no_such_structure
cmp ax,[ebx]
je structure_data_found
add ebx,18h
jmp scan_structures
structure_data_found:
ret
no_such_structure:
stc
ret
allocate_virtual_structure_data:
call allocate_structure_data
mov word [ebx],virtual_directive-instruction_handler
mov ecx,[addressing_space]
mov [ebx+12],ecx
mov [ebx+8],edi
mov ecx,[current_line]
mov [ebx+4],ecx
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
ret
continue_virtual_area:
cmp byte [esi],11h
jne invalid_argument
cmp byte [esi+1+4],')'
jne invalid_argument
inc esi
lods dword [esi]
inc esi
cmp eax,0Fh
jbe reserved_word_used_as_symbol
mov edx,undefined_symbol
test byte [eax+8],1
jz virtual_area_unavailable
mov edx,symbol_out_of_scope
mov cx,[eax+16]
cmp cx,[current_pass]
jne virtual_area_unavailable
mov edx,invalid_use_of_symbol
test byte [eax+9],4
jz virtual_area_unavailable
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
or byte [ebx+8],8
call store_label_reference
mov ebx,[ebx]
test byte [ebx+0Ah],4
jz virtual_area_unavailable
and byte [ebx+0Ah],not 4
mov edx,ebx
call allocate_virtual_structure_data
mov [addressing_space],edx
push esi
mov esi,[edx+18h]
mov ecx,[edx+1Ch]
mov eax,[edx+20h]
sub esi,eax
add ecx,eax
lea eax,[edi+ecx]
cmp eax,[tagged_blocks]
jae out_of_memory
mov eax,esi
sub eax,edi
sub [edx+18h],eax
sub [edx],eax
sbb dword [edx+4],0
sbb byte [edx+8],0
mov al,cl
shr ecx,2
rep movs dword [edi],[esi]
mov cl,al
and cl,11b
rep movs byte [edi],[esi]
pop esi
jmp instruction_assembled
virtual_area_unavailable:
cmp [error_line],0
jne virtual_fallback
push [current_line]
pop [error_line]
mov [error],edx
mov [error_info],eax
jmp virtual_fallback
end_virtual:
call find_structure_data
jc unexpected_instruction
push ebx
call close_virtual_addressing_space
pop ebx
mov eax,[ebx+12]
mov [addressing_space],eax
mov edi,[ebx+8]
remove_structure_data:
push esi edi
mov ecx,ebx
sub ecx,[structures_buffer]
shr ecx,2
lea esi,[ebx-4]
lea edi,[esi+18h]
std
rep movs dword [edi],[esi]
cld
add [structures_buffer],18h
pop edi esi
ret
close_virtual_addressing_space:
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
add eax,[ebx+20h]
test byte [ebx+0Ah],2
jz addressing_space_closed
or byte [ebx+0Ah],4
push esi edi ecx edx
mov ecx,eax
mov eax,[tagged_blocks]
mov dword [eax-4],11h
mov dword [eax-8],ecx
sub eax,8
sub eax,ecx
mov [tagged_blocks],eax
lea edi,[eax+ecx-1]
add eax,[ebx+20h]
xchg eax,[ebx+18h]
sub eax,[ebx+20h]
lea esi,[eax+ecx-1]
mov eax,edi
sub eax,esi
std
shr ecx,1
jnc virtual_byte_ok
movs byte [edi],[esi]
virtual_byte_ok:
dec esi
dec edi
shr ecx,1
jnc virtual_word_ok
movs word [edi],[esi]
virtual_word_ok:
sub esi,2
sub edi,2
rep movs dword [edi],[esi]
cld
xor edx,edx
add [ebx],eax
adc dword [ebx+4],edx
adc byte [ebx+8],dl
pop edx ecx edi esi
addressing_space_closed:
ret
repeat_directive:
test [prefix_flags],1
jnz unexpected_instruction
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
cmp eax,0
je zero_repeat
call allocate_structure_data
mov word [ebx],repeat_directive-instruction_handler
xchg eax,[counter_limit]
mov [ebx+10h],eax
mov eax,1
xchg eax,[counter]
mov [ebx+14h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
end_repeat:
test [prefix_flags],1
jnz unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[counter_limit]
inc [counter]
cmp [counter],eax
jbe continue_repeating
stop_repeat:
mov eax,[ebx+10h]
mov [counter_limit],eax
mov eax,[ebx+14h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
continue_repeating:
mov esi,[ebx+8]
jmp instruction_assembled
zero_repeat:
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_repeat
jmp instruction_assembled
find_end_repeat:
call find_structure_end
cmp ax,repeat_directive-instruction_handler
jne unexpected_instruction
ret
while_directive:
test [prefix_flags],1
jnz unexpected_instruction
call allocate_structure_data
mov word [ebx],while_directive-instruction_handler
mov eax,1
xchg eax,[counter]
mov [ebx+10h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
do_while:
push ebx
call calculate_logical_expression
or al,al
jnz while_true
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
stop_while:
call find_end_while
pop ebx
mov eax,[ebx+10h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
while_true:
pop ebx
jmp instruction_assembled
end_while:
test [prefix_flags],1
jnz unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[ebx+4]
mov [current_line],eax
inc [counter]
jz too_many_repeats
mov esi,[ebx+8]
jmp do_while
find_end_while:
call find_structure_end
cmp ax,while_directive-instruction_handler
jne unexpected_instruction
ret
if_directive:
test [prefix_flags],1
jnz unexpected_instruction
call calculate_logical_expression
mov dl,al
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or dl,dl
jnz if_true
call find_else
jc instruction_assembled
mov al,[esi]
cmp al,1
jne else_true
cmp word [esi+1],if_directive-instruction_handler
jne else_true
add esi,4
jmp if_directive
if_true:
xor al,al
make_if_structure:
call allocate_structure_data
mov word [ebx],if_directive-instruction_handler
mov byte [ebx+2],al
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
else_true:
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or al,-1
jmp make_if_structure
else_directive:
test [prefix_flags],1
jnz unexpected_instruction
mov ax,if_directive-instruction_handler
call find_structure_data
jc unexpected_instruction
cmp byte [ebx+2],0
jne unexpected_instruction
found_else:
mov al,[esi]
cmp al,1
jne skip_else
cmp word [esi+1],if_directive-instruction_handler
jne skip_else
add esi,4
call find_else
jnc found_else
call remove_structure_data
jmp instruction_assembled
skip_else:
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_if
call remove_structure_data
jmp instruction_assembled
end_if:
test [prefix_flags],1
jnz unexpected_instruction
call find_structure_data
jc unexpected_instruction
call remove_structure_data
jmp instruction_assembled
find_else:
call find_structure_end
cmp ax,else_directive-instruction_handler
je else_found
cmp ax,if_directive-instruction_handler
jne unexpected_instruction
stc
ret
else_found:
clc
ret
find_end_if:
call find_structure_end
cmp ax,if_directive-instruction_handler
jne unexpected_instruction
ret
find_structure_end:
push [error_line]
mov eax,[current_line]
mov [error_line],eax
find_end_directive:
call skip_symbol
jnc find_end_directive
lods byte [esi]
cmp al,0Fh
jne no_end_directive
lods dword [esi]
mov [current_line],eax
skip_labels:
cmp byte [esi],2
jne labels_ok
add esi,6
jmp skip_labels
labels_ok:
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
cmp ax,prefix_instruction-instruction_handler
je find_end_directive
add esi,4
cmp ax,repeat_directive-instruction_handler
je skip_repeat
cmp ax,while_directive-instruction_handler
je skip_while
cmp ax,if_directive-instruction_handler
je skip_if
cmp ax,else_directive-instruction_handler
je structure_end
cmp ax,end_directive-instruction_handler
jne find_end_directive
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
add esi,4
cmp ax,repeat_directive-instruction_handler
je structure_end
cmp ax,while_directive-instruction_handler
je structure_end
cmp ax,if_directive-instruction_handler
jne find_end_directive
structure_end:
pop [error_line]
ret
no_end_directive:
mov eax,[error_line]
mov [current_line],eax
jmp missing_end_directive
skip_repeat:
call find_end_repeat
jmp find_end_directive
skip_while:
call find_end_while
jmp find_end_directive
skip_if:
call skip_if_block
jmp find_end_directive
skip_if_block:
call find_else
jc if_block_skipped
cmp byte [esi],1
jne skip_after_else
cmp word [esi+1],if_directive-instruction_handler
jne skip_after_else
add esi,4
jmp skip_if_block
skip_after_else:
call find_end_if
if_block_skipped:
ret
end_directive:
lods byte [esi]
cmp al,1
jne invalid_argument
lods word [esi]
inc esi
cmp ax,virtual_directive-instruction_handler
je end_virtual
cmp ax,repeat_directive-instruction_handler
je end_repeat
cmp ax,while_directive-instruction_handler
je end_while
cmp ax,if_directive-instruction_handler
je end_if
cmp ax,data_directive-instruction_handler
je end_data
jmp invalid_argument
break_directive:
mov ebx,[structures_buffer]
mov al,[esi]
or al,al
jz find_breakable_structure
cmp al,0Fh
jne extra_characters_on_line
find_breakable_structure:
cmp ebx,[additional_memory_end]
je unexpected_instruction
mov ax,[ebx]
cmp ax,repeat_directive-instruction_handler
je break_repeat
cmp ax,while_directive-instruction_handler
je break_while
cmp ax,if_directive-instruction_handler
je break_if
add ebx,18h
jmp find_breakable_structure
break_if:
push [current_line]
mov eax,[ebx+4]
mov [current_line],eax
call remove_structure_data
call skip_if_block
pop [current_line]
mov ebx,[structures_buffer]
jmp find_breakable_structure
break_repeat:
push ebx
call find_end_repeat
pop ebx
jmp stop_repeat
break_while:
push ebx
jmp stop_while
define_data:
cmp edi,[tagged_blocks]
jae out_of_memory
cmp byte [esi],'('
jne simple_data_value
mov ebx,esi
inc esi
call skip_expression
xchg esi,ebx
cmp byte [ebx],81h
jne simple_data_value
inc esi
call get_count_value
inc esi
or eax,eax
jz duplicate_zero_times
cmp byte [esi],91h
jne duplicate_single_data_value
inc esi
duplicate_data:
push eax esi
duplicated_values:
cmp edi,[tagged_blocks]
jae out_of_memory
clc
call near dword [esp+8]
lods byte [esi]
cmp al,','
je duplicated_values
cmp al,92h
jne invalid_argument
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_data
duplicate_single_data_value:
cmp edi,[tagged_blocks]
jae out_of_memory
push eax esi
clc
call near dword [esp+8]
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_single_data_value
duplicate_zero_times:
cmp byte [esi],91h
jne skip_single_data_value
inc esi
skip_data_value:
call skip_symbol
jc invalid_argument
cmp byte [esi],92h
jne skip_data_value
inc esi
jmp data_defined
skip_single_data_value:
call skip_symbol
jmp data_defined
simple_data_value:
cmp edi,[tagged_blocks]
jae out_of_memory
clc
call near dword [esp]
data_defined:
lods byte [esi]
cmp al,','
je define_data
dec esi
stc
ret
data_bytes:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_byte
cmp al,'?'
jne invalid_argument
mov eax,edi
mov byte [edi],0
inc edi
jmp undefined_data
get_byte:
cmp byte [esi],0
je get_string
call get_byte_value
stos byte [edi]
ret
get_string:
inc esi
lods dword [esi]
mov ecx,eax
lea eax,[edi+ecx]
cmp eax,[tagged_blocks]
ja out_of_memory
rep movs byte [edi],[esi]
inc esi
ret
undefined_data:
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jz mark_undefined_data
ret
mark_undefined_data:
cmp eax,[undefined_data_end]
je undefined_data_ok
mov [undefined_data_start],eax
undefined_data_ok:
mov [undefined_data_end],edi
ret
data_unicode:
or [base_code],-1
jmp define_words
data_words:
mov [base_code],0
define_words:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_word
cmp al,'?'
jne invalid_argument
mov eax,edi
and word [edi],0
scas word [edi]
jmp undefined_data
ret
get_word:
cmp [base_code],0
je word_data_value
cmp byte [esi],0
je word_string
word_data_value:
call get_word_value
call mark_relocation
stos word [edi]
ret
word_string:
inc esi
lods dword [esi]
mov ecx,eax
jecxz word_string_ok
lea eax,[edi+ecx*2]
cmp eax,[tagged_blocks]
ja out_of_memory
xor ah,ah
copy_word_string:
lods byte [esi]
stos word [edi]
loop copy_word_string
word_string_ok:
inc esi
ret
data_dwords:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_dword
cmp al,'?'
jne invalid_argument
mov eax,edi
and dword [edi],0
scas dword [edi]
jmp undefined_data
get_dword:
push esi
call get_dword_value
pop ebx
cmp byte [esi],':'
je complex_dword
call mark_relocation
stos dword [edi]
ret
complex_dword:
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_word_value
call mark_relocation
stos word [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_pwords:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_pword
cmp al,'?'
jne invalid_argument
mov eax,edi
and dword [edi],0
scas dword [edi]
and word [edi],0
scas word [edi]
jmp undefined_data
get_pword:
push esi
call get_pword_value
pop ebx
cmp byte [esi],':'
je complex_pword
call mark_relocation
stos dword [edi]
mov ax,dx
stos word [edi]
ret
complex_pword:
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_dword_value
call mark_relocation
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_qwords:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_qword
cmp al,'?'
jne invalid_argument
mov eax,edi
and dword [edi],0
scas dword [edi]
and dword [edi],0
scas dword [edi]
jmp undefined_data
get_qword:
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
ret
data_twords:
call define_data
jc instruction_assembled
lods byte [esi]
cmp al,'('
je get_tword
cmp al,'?'
jne invalid_argument
mov eax,edi
and dword [edi],0
scas dword [edi]
and dword [edi],0
scas dword [edi]
and word [edi],0
scas word [edi]
jmp undefined_data
get_tword:
cmp byte [esi],'.'
jne complex_tword
inc esi
cmp word [esi+8],8000h
je fp_zero_tword
mov eax,[esi]
stos dword [edi]
mov eax,[esi+4]
stos dword [edi]
mov ax,[esi+8]
add ax,3FFFh
jo value_out_of_range
cmp ax,7FFFh
jge value_out_of_range
cmp ax,0
jg tword_exp_ok
mov cx,ax
neg cx
inc cx
cmp cx,64
jae value_out_of_range
cmp cx,32
ja large_shift
mov eax,[esi]
mov edx,[esi+4]
mov ebx,edx
shr edx,cl
shrd eax,ebx,cl
jmp tword_mantissa_shift_done
large_shift:
sub cx,32
xor edx,edx
mov eax,[esi+4]
shr eax,cl
tword_mantissa_shift_done:
jnc store_shifted_mantissa
add eax,1
adc edx,0
store_shifted_mantissa:
mov [edi-8],eax
mov [edi-4],edx
xor ax,ax
test edx,1 shl 31
jz tword_exp_ok
inc ax
tword_exp_ok:
mov bl,[esi+11]
shl bx,15
or ax,bx
stos word [edi]
add esi,13
ret
fp_zero_tword:
xor eax,eax
stos dword [edi]
stos dword [edi]
mov al,[esi+11]
shl ax,15
stos word [edi]
add esi,13
ret
complex_tword:
call get_word_value
push eax
cmp byte [esi],':'
jne invalid_operand
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_file:
lods word [esi]
cmp ax,'('
jne invalid_argument
add esi,4
call open_binary_file
mov eax,[esi-4]
lea esi,[esi+eax+1]
mov al,2
xor edx,edx
call lseek
push eax
xor edx,edx
cmp byte [esi],':'
jne position_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx
call get_count_value
pop ebx
mov edx,eax
sub [esp],edx
jc value_out_of_range
position_ok:
cmp byte [esi],','
jne size_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx edx
call get_count_value
pop edx ebx
cmp eax,[esp]
ja value_out_of_range
mov [esp],eax
size_ok:
xor al,al
call lseek
pop ecx
mov edx,edi
add edi,ecx
jc out_of_memory
cmp edi,[tagged_blocks]
ja out_of_memory
call read
jc error_reading_file
call close
lods byte [esi]
cmp al,','
je data_file
dec esi
jmp instruction_assembled
open_binary_file:
push esi
push edi
mov eax,[current_line]
find_current_source_path:
mov esi,[eax]
test byte [eax+7],80h
jz get_current_path
mov eax,[eax+8]
jmp find_current_source_path
get_current_path:
lodsb
stosb
or al,al
jnz get_current_path
cut_current_path:
cmp edi,[esp]
je current_path_ok
cmp byte [edi-1],'\'
je current_path_ok
cmp byte [edi-1],'/'
je current_path_ok
dec edi
jmp cut_current_path
current_path_ok:
mov esi,[esp+4]
call expand_path
pop edx
mov esi,edx
call open
jnc file_opened
mov edx,[include_paths]
search_in_include_paths:
push edx esi
mov edi,esi
mov esi,[esp+4]
call get_include_directory
mov [esp+4],esi
mov esi,[esp+8]
call expand_path
pop edx
mov esi,edx
call open
pop edx
jnc file_opened
cmp byte [edx],0
jne search_in_include_paths
mov edi,esi
mov esi,[esp]
push edi
call expand_path
pop edx
mov esi,edx
call open
jc file_not_found
file_opened:
mov edi,esi
pop esi
ret
reserve_bytes:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_bytes
add edi,ecx
jmp reserved_data
zero_bytes:
xor eax,eax
shr ecx,1
jnc bytes_stosb_ok
stos byte [edi]
bytes_stosb_ok:
shr ecx,1
jnc bytes_stosw_ok
stos word [edi]
bytes_stosw_ok:
rep stos dword [edi]
reserved_data:
pop eax
call undefined_data
jmp instruction_assembled
reserve_words:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
zero_words:
xor eax,eax
shr ecx,1
jnc words_stosw_ok
stos word [edi]
words_stosw_ok:
rep stos dword [edi]
jmp reserved_data
reserve_dwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
zero_dwords:
xor eax,eax
rep stos dword [edi]
jmp reserved_data
reserve_pwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
shl ecx,1
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
reserve_qwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
shl ecx,1
jc out_of_memory
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
reserve_twords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov ecx,eax
shl ecx,2
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
align_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_count_value
mov edx,eax
dec edx
test eax,edx
jnz invalid_align_value
or eax,eax
jz invalid_align_value
cmp eax,1
je instruction_assembled
mov ecx,edi
mov ebp,[addressing_space]
sub ecx,[ds:ebp]
cmp dword [ds:ebp+10h],0
jne section_not_aligned_enough
cmp byte [ds:ebp+9],0
je make_alignment
cmp [output_format],3
je pe_alignment
cmp [output_format],5
jne object_alignment
test [format_flags],1
jnz pe_alignment
object_alignment:
mov ebx,[ds:ebp+14h]
cmp byte [ebx],0
jne section_not_aligned_enough
cmp eax,[ebx+10h]
jbe make_alignment
jmp section_not_aligned_enough
pe_alignment:
cmp eax,1000h
ja section_not_aligned_enough
make_alignment:
dec eax
and ecx,eax
jz instruction_assembled
neg ecx
add ecx,eax
inc ecx
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je nops
add edi,ecx
jmp reserved_data
invalid_align_value:
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
jmp instruction_assembled
nops:
mov eax,90909090h
shr ecx,1
jnc nops_stosb_ok
stos byte [edi]
nops_stosb_ok:
shr ecx,1
jnc nops_stosw_ok
stos word [edi]
nops_stosw_ok:
rep stos dword [edi]
jmp reserved_data
err_directive:
mov al,[esi]
cmp al,0Fh
je invoked_error
or al,al
jz invoked_error
jmp extra_characters_on_line
assert_directive:
call calculate_logical_expression
or al,al
jnz instruction_assembled
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],assertion_failed
jmp instruction_assembled
|