Advertisement
Slapoguzov

diasm.awk

Jan 19th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 40.36 KB | None | 0 0
  1. BEGIN {
  2.     countCommand = 0;           #счетчик команд   
  3.     fReadCommand = 0;           #1 - происходит чтение команды и аргументов, 0 - не происходит
  4.     modR = 0;                   #16-битный или 8-битный режим
  5.     isData = 0;        
  6.     isRegister = 0;
  7.     isLES_LDS = 0;              #флаг для команд LES и LDS
  8.     isGroupInstruction = 0;     #флаг для команд, использующих с 5 по 3 бит байта modR/M(Groups of instructions )
  9.     isx83 = 0;                  #флаг для команд 0х83    
  10.     firstArg = 0;               #флаг для первого аргумента команд. 0 - r/m, 1 - r, 2 - fixRegister, 3 - addr 
  11.     secondArg = 0;              #флаг для второго аргумента команд. 0 - other, 1 - addr
  12.     fEndCode = 0;               #флаг конца кода
  13.    
  14. }
  15. #{
  16. #   if(fEndCode == 1 )
  17. #   {
  18. #       Command[countCommand] = $1 " db " $2;
  19. #       countCommand++;
  20. #       next;
  21. #   }
  22. #}
  23. {
  24.     if(fReadCommand != 0)
  25.     {
  26.         #расшифровка команд, использующих с 5 по 3 бит байта modR/M(Groups of instructions )
  27.         if(isGroupInstruction == 1)
  28.         {
  29.        
  30.             MODRM_one = substr($2,1,1);
  31.             MODRM_two = substr($2,2,1);
  32.             if(Command[countCommand] == "_ROT reg,1") { print("frgt"); }
  33.             if(MODRM_one == "0") { binMODRM = "0000"; }
  34.             if(MODRM_one == "1") { binMODRM = "0001"; }
  35.             if(MODRM_one == "2") { binMODRM = "0010"; }
  36.             if(MODRM_one == "3") { binMODRM = "0011"; }
  37.             if(MODRM_one == "4") { binMODRM = "0100"; }
  38.             if(MODRM_one == "5") { binMODRM = "0101"; }
  39.             if(MODRM_one == "6") { binMODRM = "0110"; }
  40.             if(MODRM_one == "7") { binMODRM = "0111"; }
  41.             if(MODRM_one == "8") { binMODRM = "1000"; }
  42.             if(MODRM_one == "9") { binMODRM = "1001"; }
  43.             if(MODRM_one == "a") { binMODRM = "1010"; }
  44.             if(MODRM_one == "b") { binMODRM = "1011"; }
  45.             if(MODRM_one == "c") { binMODRM = "1100"; }
  46.             if(MODRM_one == "d") { binMODRM = "1101"; }
  47.             if(MODRM_one == "e") { binMODRM = "1110"; }
  48.             if(MODRM_one == "f") { binMODRM = "1111"; }
  49.  
  50.             if(MODRM_two == "0") { binMODRM = binMODRM "0000"; }
  51.             if(MODRM_two == "1") { binMODRM = binMODRM "0001"; }
  52.             if(MODRM_two == "2") { binMODRM = binMODRM "0010"; }
  53.             if(MODRM_two == "3") { binMODRM = binMODRM "0011"; }
  54.             if(MODRM_two == "4") { binMODRM = binMODRM "0100"; }
  55.             if(MODRM_two == "5") { binMODRM = binMODRM "0101"; }
  56.             if(MODRM_two == "6") { binMODRM = binMODRM "0110"; }
  57.             if(MODRM_two == "7") { binMODRM = binMODRM "0111";  }
  58.             if(MODRM_two == "8") { binMODRM = binMODRM "1000"; }
  59.             if(MODRM_two == "9") { binMODRM = binMODRM "1001"; }
  60.             if(MODRM_two == "a") { binMODRM = binMODRM "1010"; }
  61.             if(MODRM_two == "b") { binMODRM = binMODRM "1011"; }
  62.             if(MODRM_two == "c") { binMODRM = binMODRM "1100"; }
  63.             if(MODRM_two == "d") { binMODRM = binMODRM "1101"; }
  64.             if(MODRM_two == "e") { binMODRM = binMODRM "1110"; }
  65.             if(MODRM_two == "f") { binMODRM = binMODRM "1111";  }
  66.  
  67.             binR = substr(binMODRM,3,3);
  68.             tempo2 = Command[countCommand];
  69.             if(binR  == "000") { gsub("_ALU1", "ADD", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_POP", "POP", tempo2); gsub("_ROT", "ROL", tempo2); gsub("_ALU2", "TEST", tempo2); gsub("_MISC", "INC", tempo2); }
  70.             if(binR  == "001") { gsub("_ALU1", "OR", tempo2);  gsub("_MOV", "MOV", tempo2); gsub("_ROT", "ROR", tempo2);  gsub("_ALU2", "*TEST", tempo2); gsub("_MISC", "DEC", tempo2); }
  71.             if(binR  == "010") { gsub("_ALU1", "ADC", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "RCL", tempo2); gsub("_ALU2", "NOT", tempo2); }
  72.             if(binR  == "011") { gsub("_ALU1", "SBB", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "RCR", tempo2); gsub("_ALU2", "NEG", tempo2); }
  73.             if(binR  == "100") { gsub("_ALU1", "AND", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "SHL/SAL", tempo2); gsub("_ALU2", "MUL", tempo2); }
  74.             if(binR  == "101") { gsub("_ALU1", "SUB", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "SHR", tempo2); gsub("_ALU2", "IMUL", tempo2); }
  75.             if(binR  == "110") { gsub("_ALU1", "XOR", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "*SHL/*SAL", tempo2); gsub("_ALU2", "DIV", tempo2); }
  76.             if(binR  == "111") { gsub("_ALU1", "CMP", tempo2); gsub("_MOV", "MOV", tempo2); gsub("_ROT", "SAR", tempo2); gsub("_ALU2", "IDIV", tempo2); }
  77.             Command[countCommand] = tempo2;
  78.             binMODRM = "";
  79.         }
  80.         #чтение аргументов
  81.         if(firstArg < 2 && modR != 0 && (secondArg <= 0 || isGroupInstruction == 1))
  82.         {
  83.             MODRM_one = substr($2,1,1);
  84.             MODRM_two = substr($2,2,1);
  85.             if(modR == 8)
  86.             {
  87.                 modR_ch1 ="L";
  88.                 modR_AH_SP ="AH";
  89.                 modR_CH_BP ="CH";
  90.                 modR_DH_SI ="DH";
  91.                 modR_BH_DI ="BH";
  92.             }
  93.             else if(modR == 16)
  94.             {
  95.                 modR_ch1 ="X";
  96.                 modR_AH_SP ="SP";
  97.                 modR_CH_BP ="BP";
  98.                 modR_DH_SI ="SI";
  99.                 modR_BH_DI ="DI";
  100.             }
  101.             if(MODRM_two >= "0" && MODRM_two <= "7")
  102.             {
  103.                 if(MODRM_one == "0" || MODRM_one == "4" || MODRM_one == "8" || MODRM_one == "c") reg1 = "A" modR_ch1;
  104.                 if(MODRM_one == "1" || MODRM_one == "5" || MODRM_one == "9" || MODRM_one == "d") reg1 = "D" modR_ch1;
  105.                 if(MODRM_one == "2" || MODRM_one == "6" || MODRM_one == "a" || MODRM_one == "e") reg1 = modR_AH_SP;
  106.                 if(MODRM_one == "3" || MODRM_one == "7" || MODRM_one == "b" || MODRM_one == "f") reg1 = modR_DH_SI;
  107.             }
  108.  
  109.             if(MODRM_two >= "8" && MODRM_two <= "f")
  110.             {
  111.                 if(MODRM_one == "0" || MODRM_one == "4" || MODRM_one == "8" || MODRM_one == "c") reg1 = "C" modR_ch1;
  112.                 if(MODRM_one == "1" || MODRM_one == "5" || MODRM_one == "9" || MODRM_one == "d") reg1 = "B" modR_ch1;
  113.                 if(MODRM_one == "2" || MODRM_one == "6" || MODRM_one == "a" || MODRM_one == "e") reg1 = modR_CH_BP;
  114.                 if(MODRM_one == "3" || MODRM_one == "7" || MODRM_one == "b" || MODRM_one == "f") reg1 = modR_BH_DI;
  115.             }
  116.             if(MODRM_one < "4")
  117.             {
  118.                 if(MODRM_two == "0" || MODRM_two == "8") reg2="[BX+SI]";
  119.                 if(MODRM_two == "1" || MODRM_two == "9") reg2="[BX+DI]";
  120.                 if(MODRM_two == "2" || MODRM_two == "a") reg2="[BP+SI]";
  121.                 if(MODRM_two == "3" || MODRM_two == "b") reg2="[BP+DI]";
  122.                 if(MODRM_two == "4" || MODRM_two == "c") reg2="[SI]";
  123.                 if(MODRM_two == "5" || MODRM_two == "d") reg2="[DI]";
  124.                 if(MODRM_two == "6" || MODRM_two == "e") { reg2="addr"; secondArg=1; modR=16;};
  125.                 if(MODRM_two == "7" || MODRM_two == "f") reg2="[BX]";
  126.             }
  127.             if(MODRM_one >= "4" && MODRM_one < "8")
  128.             {
  129.                 if(MODRM_two == "0" || MODRM_two == "8") { reg2="[BX+SI]+addr"; secondArg=1; modR=8;};
  130.                 if(MODRM_two == "1" || MODRM_two == "9") { reg2="[BX+DI]+addr"; secondArg=1; modR=8;};
  131.                 if(MODRM_two == "2" || MODRM_two == "a") { reg2="[BP+SI]+addr"; secondArg=1; modR=8;};
  132.                 if(MODRM_two == "3" || MODRM_two == "b") { reg2="[BP+DI]+addr"; secondArg=1; modR=8;};
  133.                 if(MODRM_two == "4" || MODRM_two == "c") { reg2="[SI]+addr"; secondArg=1; modR=8;};
  134.                 if(MODRM_two == "5" || MODRM_two == "d") { reg2="[DI]+addr"; secondArg=1; modR=8;};
  135.                 if(MODRM_two == "6" || MODRM_two == "e") { reg2="[BP]+addr"; secondArg=1; modR=8;};
  136.                 if(MODRM_two == "7" || MODRM_two == "f") { reg2="[BX]+addr"; secondArg=1; modR=8;};
  137.             }
  138.             if(MODRM_one >= "8" && MODRM_one < "c")
  139.             {
  140.                 if(MODRM_two == "0" || MODRM_two == "8") { reg2="[BX+SI]+addr"; secondArg=1; modR=16;};
  141.                 if(MODRM_two == "1" || MODRM_two == "9") { reg2="[BX+DI]+addr"; secondArg=1; modR=16;};
  142.                 if(MODRM_two == "2" || MODRM_two == "a") { reg2="[BP+SI]+addr"; secondArg=1; modR=16;};
  143.                 if(MODRM_two == "3" || MODRM_two == "b") { reg2="[BP+DI]+addr"; secondArg=1; modR=16;};
  144.                 if(MODRM_two == "4" || MODRM_two == "c") { reg2="[SI]+addr"; secondArg=1; modR=16;};
  145.                 if(MODRM_two == "5" || MODRM_two == "d") { reg2="[DI]+addr"; secondArg=1; modR=16;};
  146.                 if(MODRM_two == "6" || MODRM_two == "e") { reg2="[BP]+addr"; secondArg=1; modR=16;};
  147.                 if(MODRM_two == "7" || MODRM_two == "f") { reg2="[BX]+addr"; secondArg=1; modR=16;};
  148.             }
  149.             if(MODRM_one >= "c" && MODRM_one <= "f")
  150.             {
  151.                 if(MODRM_two == "0" || MODRM_two == "8") reg2="A" modR_ch1;
  152.                 if(MODRM_two == "1" || MODRM_two == "9") reg2="C" modR_ch1;
  153.                 if(MODRM_two == "2" || MODRM_two == "a") reg2="D" modR_ch1;
  154.                 if(MODRM_two == "3" || MODRM_two == "b") reg2="B" modR_ch1;
  155.                 if(MODRM_two == "4" || MODRM_two == "c") reg2=modR_AH_SP;
  156.                 if(MODRM_two == "5" || MODRM_two == "d") reg2=modR_CH_BP;
  157.                 if(MODRM_two == "6" || MODRM_two == "e") reg2=modR_DH_SI;
  158.                 if(MODRM_two == "7" || MODRM_two == "f") reg2=modR_BH_DI;
  159.             }
  160.             temp = "nyll"
  161.             if(firstArg <= 0)
  162.             {
  163.                 temp = reg1;
  164.                 reg1 = reg2;
  165.                 reg2 = temp;
  166.             }
  167.             if(isGroupInstruction == 1)
  168.             {  
  169.                 temp = Command[countCommand];
  170.                 gsub("reg", reg2, temp);
  171.                 Command[countCommand] = temp;
  172.                 if(firstArg == -1 || secondArg == -1) { fReadCommand = 0; countCommand++; next;}
  173.                 firstArg = 4;
  174.                 fReadCommand=1;
  175.                 if(isx83 == 1) { isx83=0; modR = 8;}
  176.                 next;
  177.             }
  178.             if(firstArg==3 || secondArg == 1)
  179.             {
  180.                 Command[countCommand] = Command[countCommand] reg1 "," reg2;           
  181.                 fReadCommand=1;
  182.                 next;
  183.             }
  184.             if(isLES_LDS == 0) { Command[countCommand] = Command[countCommand] reg1 "," reg2; }
  185.             else
  186.             {          
  187.             Command[countCommand] = Command[countCommand] reg1;
  188.             isLES_LDS = 0;
  189.             }
  190.             fReadCommand = 0;
  191.             countCommand = countCommand+1;
  192.             next;
  193.         }  
  194.  
  195.    
  196.         if(firstArg == 2 && secondArg == 0)
  197.         {
  198.             Command[countCommand] = Command[countCommand] $2;  
  199.             modR = modR - 8;
  200.             if(modR != 0)
  201.             {
  202.                 next;      
  203.             }
  204.             else
  205.             {
  206.                 fReadCommand = 0;
  207.                 countCommand = countCommand+1;
  208.                 next;
  209.             }
  210.  
  211.         }
  212.         if(secondArg == 1 || firstArg == 3 )
  213.         {
  214.             tempo = tempo $2;
  215.             modR = modR - 8;
  216.             if(modR != 0)
  217.             {
  218.                 next;
  219.             }
  220.             else
  221.             {
  222.                 tempo2 = Command[countCommand];
  223.                 gsub("addr", tempo, tempo2);
  224.                 Command[countCommand] = tempo2;
  225.                 fReadCommand = 0;
  226.                 countCommand = countCommand+1;
  227.                 tempo = "";
  228.             }
  229.  
  230.         }
  231.         next;
  232.     }
  233. }
  234. #все что ниже - расшифровка команд
  235. $2 ~ /^0/ {
  236.     if(fReadCommand == 0)
  237.     {
  238.         modR = 0;
  239.         isData = 0;
  240.         isRegister = 0;
  241.         isLES_LDS = 0;
  242.         isGroupInstruction = 0;
  243.         isx83 = 0;
  244.         firstArg = 0;
  245.         fReadCommand = 1;
  246.         secondArg = 0;
  247.         if($2 == "00")
  248.         {
  249.             Command[countCommand] = $1 " " "ADD ";
  250.             modR = 8;
  251.             firstArg = 0;
  252.             next;
  253.         }
  254.         if($2 == "01")
  255.         {
  256.             Command[countCommand] = $1 " " "ADD ";
  257.             modR = 16;
  258.             firstArg = 0;
  259.             next;
  260.         }
  261.         if($2 == "02")
  262.         {
  263.             Command[countCommand] = $1 " " "ADD ";
  264.             modR = 8;
  265.             firstArg = 1;
  266.             next;
  267.         }
  268.         if($2 == "03")
  269.         {
  270.             Command[countCommand] = $1 " " "ADD ";
  271.             modR = 16;
  272.             firstArg = 1;
  273.             next;
  274.         }
  275.         if($2 == "04")
  276.         {
  277.             Command[countCommand] = $1 " " "ADD AL, ";
  278.             modR = 8;
  279.             firstArg = 2;
  280.             next;
  281.         }
  282.         if($2 == "05")
  283.         {
  284.             Command[countCommand] = $1 " " "ADD AX, ";
  285.             modR = 16;
  286.             firstArg = 2;
  287.             next;
  288.         }
  289.         if($2 == "06")
  290.         {
  291.             Command[countCommand] = $1 " " "PUSH ES";
  292.             fReadCommand = 0;
  293.             countCommand++;
  294.             next;
  295.         }
  296.         if($2 == "07")
  297.         {
  298.             Command[countCommand] = $1 " " "POP ES";
  299.             fReadCommand = 0;
  300.             countCommand++;
  301.             next;
  302.         }
  303.         if($2 == "08")
  304.         {
  305.             Command[countCommand] = $1 " " "OR ";
  306.             modR = 8;
  307.             firstArg = 0;
  308.             next;
  309.         }
  310.         if($2 == "09")
  311.         {
  312.             Command[countCommand] = $1 " " "OR ";
  313.             modR = 16;
  314.             firstArg = 0;
  315.             next;
  316.         }
  317.         if($2 == "0a")
  318.         {
  319.             Command[countCommand] = $1 " " "OR ";
  320.             modR = 8;
  321.             firstArg = 1;
  322.             next;
  323.         }
  324.         if($2 == "0b")
  325.         {
  326.             Command[countCommand] = $1 " " "OR ";
  327.             modR = 16;
  328.             firstArg = 0;
  329.             next;
  330.         }
  331.         if($2 == "0c")
  332.         {
  333.             Command[countCommand] = $1 " " "OR AL, ";
  334.             modR = 8;
  335.             firstArg = 2;
  336.             next;
  337.         }
  338.         if($2 == "0d")
  339.         {
  340.             Command[countCommand] = $1 " " "OR AX, ";
  341.             modR = 16;
  342.             firstArg = 2;
  343.             next;
  344.         }
  345.         if($2 == "0e")
  346.         {
  347.             Command[countCommand] = $1 " " "PUSH CS";
  348.             fReadCommand = 0;
  349.             countCommand++;
  350.             next;
  351.         }
  352.         if($2 == "0f")
  353.         {
  354.             Command[countCommand] = $1 " " "POP CS";
  355.             fReadCommand = 0;
  356.             countCommand++;
  357.             next;
  358.         }
  359.     }
  360. }
  361. $2 ~ /^1/ {
  362.     if(fReadCommand == 0)
  363.     {
  364.         modR = 0;
  365.         isData = 0;
  366.         isRegister = 0;
  367.         isLES_LDS = 0;
  368.         isGroupInstruction = 0;
  369.         isx83 = 0;
  370.         firstArg = 0;  
  371.         fReadCommand = 1;
  372.         secondArg = 0;
  373.         if($2 == "10")
  374.         {
  375.             Command[countCommand] = $1 " " "ADC ";
  376.             modR = 8;
  377.             firstArg = 0;
  378.             next;
  379.         }
  380.         if($2 == "11")
  381.         {
  382.             Command[countCommand] = $1 " " "ADC ";
  383.             modR = 16;
  384.             firstArg = 0;
  385.             next;
  386.         }
  387.         if($2 == "12")
  388.         {
  389.             Command[countCommand] = $1 " " "ADC ";
  390.             modR = 8;
  391.             firstArg = 1;
  392.             next;
  393.         }
  394.         if($2 == "13")
  395.         {
  396.             Command[countCommand] = $1 " " "ADC ";
  397.             modR = 16;
  398.             firstArg = 1;
  399.             next;
  400.         }
  401.         if($2 == "14")
  402.         {
  403.             Command[countCommand] = $1 " " "ADC AL, ";
  404.             modR = 8;
  405.             firstArg = 2;
  406.             next;
  407.         }
  408.         if($2 == "15")
  409.         {
  410.             Command[countCommand] = $1 " " "ADC AX, ";
  411.             modR = 16;
  412.             firstArg = 2;
  413.             next;
  414.         }
  415.         if($2 == "16")
  416.         {
  417.             Command[countCommand] = $1 " " "PUSH SS";
  418.             fReadCommand = 0;
  419.             countCommand++;
  420.             next;
  421.         }
  422.         if($2 == "17")
  423.         {
  424.             Command[countCommand] = $1 " " "POP SS";
  425.             fReadCommand = 0;
  426.             countCommand++;
  427.             next;
  428.         }
  429.         if($2 == "18")
  430.         {
  431.             Command[countCommand] = $1 " " "SBB ";
  432.             modR = 8;
  433.             firstArg = 0;
  434.             next;
  435.         }
  436.         if($2 == "19")
  437.         {
  438.             Command[countCommand] = $1 " " "SBB ";
  439.             modR = 16;
  440.             firstArg = 0;
  441.             next;
  442.         }
  443.         if($2 == "1a")
  444.         {
  445.             Command[countCommand] = $1 " " "SBB ";
  446.             modR = 8;
  447.             firstArg = 1;
  448.             next;
  449.         }
  450.         if($2 == "1b")
  451.         {
  452.             Command[countCommand] = $1 " " "SBB ";
  453.             modR = 16;
  454.             firstArg = 0;
  455.             next;
  456.         }
  457.         if($2 == "1c")
  458.         {
  459.             Command[countCommand] = $1 " " "SBB AL, ";
  460.             modR = 8;
  461.             firstArg = 2;
  462.             next;
  463.         }
  464.         if($2 == "1d")
  465.         {
  466.             Command[countCommand] = $1 " " "SBB AX, ";
  467.             modR = 16;
  468.             firstArg = 2;
  469.             next;
  470.         }
  471.         if($2 == "1e")
  472.         {
  473.             Command[countCommand] = $1 " " "PUSH DS";
  474.             fReadCommand = 0;
  475.             countCommand++;
  476.             next;
  477.         }
  478.         if($2 == "1f")
  479.         {
  480.             Command[countCommand] = $1 " " "POP DS";
  481.             fReadCommand = 0;
  482.             countCommand++;
  483.             next;
  484.         }
  485.     }
  486. }
  487. $2 ~ /^2/ {
  488.     if(fReadCommand == 0)
  489.     {
  490.         modR = 0;
  491.         isData = 0;
  492.         isRegister = 0;
  493.         isLES_LDS = 0;
  494.         isGroupInstruction = 0;
  495.         isx83 = 0;
  496.         firstArg = 0;
  497.         fReadCommand = 1;
  498.         secondArg = 0;
  499.         if($2 == "20")
  500.         {
  501.             Command[countCommand] = $1 " " "AND ";
  502.             modR = 8;
  503.             firstArg = 0;
  504.             next;
  505.         }
  506.         if($2 == "21")
  507.         {
  508.             Command[countCommand] = $1 " " "AND ";
  509.             modR = 16;
  510.             firstArg = 0;
  511.             next;
  512.         }
  513.         if($2 == "22")
  514.         {
  515.             Command[countCommand] = $1 " " "AND ";
  516.             modR = 8;
  517.             firstArg = 1;
  518.             next;
  519.         }
  520.         if($2 == "23")
  521.         {
  522.             Command[countCommand] = $1 " " "AND ";
  523.             modR = 16;
  524.             firstArg = 1;
  525.             next;
  526.         }
  527.         if($2 == "24")
  528.         {
  529.             Command[countCommand] = $1 " " "AND AL, ";
  530.             modR = 8;
  531.             firstArg = 2;
  532.             next;
  533.         }
  534.         if($2 == "25")
  535.         {
  536.             Command[countCommand] = $1 " " "AND AX, ";
  537.             modR = 16;
  538.             firstArg = 2;
  539.             next;
  540.         }
  541.         if($2 == "26")
  542.         {
  543.             Command[countCommand] = $1 " " "ES:";
  544.             fReadCommand = 0;
  545.             countCommand++;
  546.             next;
  547.         }
  548.         if($2 == "27")
  549.         {
  550.             Command[countCommand] = $1 " " "DAA";
  551.             fReadCommand = 0;
  552.             countCommand++;
  553.             next;
  554.         }
  555.         if($2 == "28")
  556.         {
  557.             Command[countCommand] = $1 " " "SUB ";
  558.             modR = 8;
  559.             firstArg = 0;
  560.             next;
  561.         }
  562.         if($2 == "29")
  563.         {
  564.             Command[countCommand] = $1 " " "SUB ";
  565.             modR = 16;
  566.             firstArg = 0;
  567.             next;
  568.         }
  569.         if($2 == "2a")
  570.         {
  571.             Command[countCommand] = $1 " " "SUB ";
  572.             modR = 8;
  573.             firstArg = 1;
  574.             next;
  575.         }
  576.         if($2 == "2b")
  577.         {
  578.             Command[countCommand] = $1 " " "SUB ";
  579.             modR = 16;
  580.             firstArg = 0;
  581.             next;
  582.         }
  583.         if($2 == "2c")
  584.         {
  585.             Command[countCommand] = $1 " " "SUB AL, ";
  586.             modR = 8;
  587.             firstArg = 2;
  588.             next;
  589.         }
  590.         if($2 == "2d")
  591.         {
  592.             Command[countCommand] = $1 " " "SUB AX, ";
  593.             modR = 16;
  594.             firstArg = 2;
  595.             next;
  596.         }
  597.         if($2 == "2e")
  598.         {
  599.             Command[countCommand] = $1 " " "CS:";
  600.             fReadCommand = 0;
  601.             countCommand++;
  602.             next;
  603.         }
  604.         if($2 == "2f")
  605.         {
  606.             Command[countCommand] = $1 " " "DAS";
  607.             fReadCommand = 0;
  608.             countCommand++;
  609.             next;
  610.         }
  611.     }
  612. }
  613. $2 ~ /^3/ {
  614.     if(fReadCommand == 0)
  615.     {
  616.         modR = 0;
  617.         isData = 0;
  618.         isRegister = 0;
  619.         isLES_LDS = 0;
  620.         isGroupInstruction = 0;
  621.         isx83 = 0;
  622.         firstArg = 0;
  623.         fReadCommand = 1;
  624.         secondArg = 0;
  625.         if($2 == "30")
  626.         {
  627.             Command[countCommand] = $1 " " "XOR ";
  628.             modR = 8;
  629.             firstArg = 0;
  630.             next;
  631.         }
  632.         if($2 == "31")
  633.         {
  634.             Command[countCommand] = $1 " " "XOR ";
  635.             modR = 16;
  636.             firstArg = 0;
  637.             next;
  638.         }
  639.         if($2 == "32")
  640.         {
  641.             Command[countCommand] = $1 " " "XOR ";
  642.             modR = 8;
  643.             firstArg = 1;
  644.             next;
  645.         }
  646.         if($2 == "33")
  647.         {
  648.             Command[countCommand] = $1 " " "XOR ";
  649.             modR = 16;
  650.             firstArg = 1;
  651.             next;
  652.         }
  653.         if($2 == "34")
  654.         {
  655.             Command[countCommand] = $1 " " "XOR AL, ";
  656.             modR = 8;
  657.             firstArg = 2;
  658.             next;
  659.         }
  660.         if($2 == "35")
  661.         {
  662.             Command[countCommand] = $1 " " "XOR AX, ";
  663.             modR = 16;
  664.             firstArg = 2;
  665.             next;
  666.         }
  667.         if($2 == "36")
  668.         {
  669.             Command[countCommand] = $1 " " "SS:";
  670.             fReadCommand = 0;
  671.             countCommand++;
  672.             next;
  673.         }
  674.         if($2 == "37")
  675.         {
  676.             Command[countCommand] = $1 " " "AAA";
  677.             fReadCommand = 0;
  678.             countCommand++;
  679.             next;
  680.         }
  681.         if($2 == "38")
  682.         {
  683.             Command[countCommand] = $1 " " "CMP ";
  684.             modR = 8;
  685.             firstArg = 0;
  686.             next;
  687.         }
  688.         if($2 == "39")
  689.         {
  690.             Command[countCommand] = $1 " " "CMP ";
  691.             modR = 16;
  692.             firstArg = 0;
  693.             next;
  694.         }
  695.         if($2 == "3a")
  696.         {
  697.             Command[countCommand] = $1 " " "CMP ";
  698.             modR = 8;
  699.             firstArg = 1;
  700.             next;
  701.         }
  702.         if($2 == "3b")
  703.         {
  704.             Command[countCommand] = $1 " " "CMP ";
  705.             modR = 16;
  706.             firstArg = 0;
  707.             next;
  708.         }
  709.         if($2 == "3c")
  710.         {
  711.             Command[countCommand] = $1 " " "CMP AL, ";
  712.             modR = 8;
  713.             firstArg = 2;
  714.             next;
  715.         }
  716.         if($2 == "3d")
  717.         {
  718.             Command[countCommand] = $1 " " "CMP AX, ";
  719.             modR = 16;
  720.             firstArg = 2;
  721.             next;
  722.         }
  723.         if($2 == "3e")
  724.         {
  725.             Command[countCommand] = $1 " " "DS:";
  726.             fReadCommand = 0;
  727.             countCommand++;
  728.             next;
  729.         }
  730.         if($2 == "3f")
  731.         {
  732.             Command[countCommand] = $1 " " "AAS";
  733.             fReadCommand = 0;
  734.             countCommand++;
  735.             next;
  736.         }
  737.     }
  738. }
  739. $2 ~ /^4/ {
  740.     if(fReadCommand == 0)
  741.     {
  742.         modR = 0;
  743.         isData = 0;
  744.         isRegister = 0;
  745.         isLES_LDS = 0;
  746.         isGroupInstruction = 0;
  747.         isx83 = 0;
  748.         firstArg = 0;
  749.         fReadCommand = 1;
  750.         secondArg = 0;
  751.         if($2 == "40")
  752.         {
  753.             Command[countCommand] = $1 " " "INC AX";
  754.             fReadCommand = 0;
  755.             countCommand++;
  756.             next;
  757.         }
  758.         if($2 == "41")
  759.         {
  760.             Command[countCommand] = $1 " " "INC CX";
  761.             fReadCommand = 0;
  762.             countCommand++;
  763.             next;
  764.         }
  765.         if($2 == "42")
  766.         {
  767.             Command[countCommand] = $1 " " "INC DX";
  768.             fReadCommand = 0;
  769.             countCommand++;
  770.             next;
  771.         }
  772.         if($2 == "43")
  773.         {
  774.             Command[countCommand] = $1 " " "INC BX";
  775.             fReadCommand = 0;
  776.             countCommand++;
  777.             next;
  778.         }
  779.         if($2 == "44")
  780.         {
  781.             Command[countCommand] = $1 " " "INC SP";
  782.             fReadCommand = 0;
  783.             countCommand++;
  784.             next;
  785.         }
  786.         if($2 == "45")
  787.         {
  788.             Command[countCommand] = $1 " " "INC BP";
  789.             fReadCommand = 0;
  790.             countCommand++;
  791.             next;
  792.         }
  793.         if($2 == "46")
  794.         {
  795.             Command[countCommand] = $1 " " "INC SI";
  796.             fReadCommand = 0;
  797.             countCommand++;
  798.             next;
  799.         }
  800.         if($2 == "47")
  801.         {
  802.             Command[countCommand] = $1 " " "INC DI";
  803.             fReadCommand = 0;
  804.             countCommand++;
  805.             next;
  806.         }
  807.         if($2 == "48")
  808.         {
  809.             Command[countCommand] = $1 " " "DEC AX";
  810.             fReadCommand = 0;
  811.             countCommand++;
  812.             next;
  813.         }
  814.         if($2 == "49")
  815.         {
  816.             Command[countCommand] = $1 " " "DEC CX";
  817.             fReadCommand = 0;
  818.             countCommand++;
  819.             next;
  820.         }
  821.         if($2 == "4a")
  822.         {
  823.             Command[countCommand] = $1 " " "DEC DX";
  824.             fReadCommand = 0;
  825.             countCommand++;
  826.             next;
  827.         }
  828.         if($2 == "4b")
  829.         {
  830.             Command[countCommand] = $1 " " "DEC BX";
  831.             fReadCommand = 0;
  832.             countCommand++;
  833.             next;
  834.         }
  835.         if($2 == "4c")
  836.         {
  837.             Command[countCommand] = $1 " " "DEC SP";
  838.             fReadCommand = 0;
  839.             countCommand++;
  840.             next;
  841.         }
  842.         if($2 == "4d")
  843.         {
  844.             Command[countCommand] = $1 " " "DEC BP";
  845.             fReadCommand = 0;
  846.             countCommand++;
  847.             next;
  848.         }
  849.         if($2 == "4e")
  850.         {
  851.             Command[countCommand] = $1 " " "DEC SI";
  852.             fReadCommand = 0;
  853.             countCommand++;
  854.             next;
  855.         }
  856.         if($2 == "4f")
  857.         {
  858.             Command[countCommand] = $1 " " "DEC DI";
  859.             fReadCommand = 0;
  860.             countCommand++;
  861.             next;
  862.         }
  863.     }
  864. }
  865. $2 ~ /^5/ {
  866.     if(fReadCommand == 0)
  867.     {
  868.         modR = 0;
  869.         isData = 0;
  870.         isRegister = 0;
  871.         isLES_LDS = 0;
  872.         isGroupInstruction = 0;
  873.         isx83 = 0;
  874.         firstArg = 0;
  875.         fReadCommand = 0;
  876.         secondArg = 0;
  877.         if($2 == "50")
  878.         {
  879.             Command[countCommand] = $1 " " "PUSH AX";
  880.             next;
  881.         }
  882.         if($2 == "51")
  883.         {
  884.             Command[countCommand] = $1 " " "PUSH CX";
  885.             next;
  886.         }
  887.         if($2 == "52")
  888.         {
  889.             Command[countCommand] = $1 " " "PUSH DX";
  890.             next;
  891.         }
  892.         if($2 == "53")
  893.         {
  894.             Command[countCommand] = $1 " " "PUSH BX";
  895.             next;
  896.         }
  897.         if($2 == "54")
  898.         {
  899.             Command[countCommand] = $1 " " "PUSH SP";
  900.             next;
  901.         }
  902.         if($2 == "55")
  903.         {
  904.             Command[countCommand] = $1 " " "PUSH BP";
  905.             next;
  906.         }
  907.         if($2 == "56")
  908.         {
  909.             Command[countCommand] = $1 " " "PUSH SI";
  910.             next;
  911.         }
  912.         if($2 == "57")
  913.         {
  914.             Command[countCommand] = $1 " " "PUSH DI";
  915.             next;
  916.         }
  917.         if($2 == "58")
  918.         {
  919.             Command[countCommand] = $1 " " "POP AX";
  920.             next;
  921.         }
  922.         if($2 == "59")
  923.         {
  924.             Command[countCommand] = $1 " " "POP CX";
  925.             next;
  926.         }
  927.         if($2 == "5a")
  928.         {
  929.             Command[countCommand] = $1 " " "POP DX";
  930.             next;
  931.         }
  932.         if($2 == "5b")
  933.         {
  934.             Command[countCommand] = $1 " " "POP BX";
  935.             next;
  936.         }
  937.         if($2 == "5c")
  938.         {
  939.             Command[countCommand] = $1 " " "POP SP";
  940.             next;
  941.         }
  942.         if($2 == "5d")
  943.         {
  944.             Command[countCommand] = $1 " " "POP BP";
  945.             next;
  946.         }
  947.         if($2 == "5e")
  948.         {
  949.             Command[countCommand] = $1 " " "POP SI";
  950.             next;
  951.         }
  952.         if($2 == "5f")
  953.         {
  954.             Command[countCommand] = $1 " " "POP DI";
  955.             next;
  956.         }
  957.         countCommand++;
  958.     }
  959. }
  960. $2 ~ /^7/ {
  961.     if(fReadCommand == 0)
  962.     {
  963.         isData = 0;
  964.         isRegister = 0;
  965.         isLES_LDS = 0;
  966.         isGroupInstruction = 0;
  967.         isx83 = 0;
  968.         fReadCommand = 1;
  969.         modR = 8;
  970.         firstArg = 2;
  971.         secondArg = 0;
  972.         if($2 == "70")
  973.         {
  974.             Command[countCommand] = $1 " " "JO ";
  975.             next;
  976.         }
  977.         if($2 == "71")
  978.         {
  979.             Command[countCommand] = $1 " " "JNO ";
  980.             next;
  981.         }
  982.         if($2 == "72")
  983.         {
  984.             Command[countCommand] = $1 " " "JB/JNAE ";
  985.             next;
  986.         }
  987.         if($2 == "73")
  988.         {
  989.             Command[countCommand] = $1 " " "JNB/JAE ";
  990.             next;
  991.         }
  992.         if($2 == "74")
  993.         {
  994.             Command[countCommand] = $1 " " "JE/JZ ";
  995.             next;
  996.         }
  997.         if($2 == "75")
  998.         {
  999.             Command[countCommand] = $1 " " "JNE/JNZ ";
  1000.             next;
  1001.         }
  1002.         if($2 == "76")
  1003.         {
  1004.             Command[countCommand] = $1 " " "JBE/JNA ";
  1005.             next;
  1006.         }
  1007.         if($2 == "77")
  1008.         {
  1009.             Command[countCommand] = $1 " " "JNBE/JA ";
  1010.             next;
  1011.         }
  1012.         if($2 == "78")
  1013.         {
  1014.             Command[countCommand] = $1 " " "JS ";
  1015.             next;
  1016.         }
  1017.         if($2 == "79")
  1018.         {
  1019.             Command[countCommand] = $1 " " "JNS ";
  1020.             next;
  1021.         }
  1022.         if($2 == "7a")
  1023.         {
  1024.             Command[countCommand] = $1 " " "JP/JPE ";
  1025.             next;
  1026.         }
  1027.         if($2 == "7b")
  1028.         {
  1029.             Command[countCommand] = $1 " " "JNP/JPO ";
  1030.             next;
  1031.         }
  1032.         if($2 == "7c")
  1033.         {
  1034.             Command[countCommand] = $1 " " "JL/JNGE ";
  1035.             next;
  1036.         }
  1037.         if($2 == "7d")
  1038.         {
  1039.             Command[countCommand] = $1 " " "JNL/JGE ";
  1040.             next;
  1041.         }
  1042.         if($2 == "7e")
  1043.         {
  1044.             Command[countCommand] = $1 " " "JLE/JNG ";
  1045.             next;
  1046.         }
  1047.         if($2 == "7f")
  1048.         {
  1049.             Command[countCommand] = $1 " " "JNLE/JG ";
  1050.             next;
  1051.         }
  1052.     }
  1053. }
  1054. $2 ~ /^8/ {
  1055.  
  1056.     if(fReadCommand == 0)
  1057.     {  
  1058.         modR = 0;
  1059.         isData = 0;
  1060.         isRegister = 0;
  1061.         isLES_LDS = 0;
  1062.         isGroupInstruction = 0;
  1063.         isx83 = 0;
  1064.         firstArg = 0;
  1065.         fReadCommand = 1;
  1066.         secondArg = 0;
  1067.         if($2 == "80")
  1068.         {
  1069.             Command[countCommand] = $1 " " "_ALU1 reg, addr";
  1070.             modR = 8;
  1071.             firstArg = 1;
  1072.             isGroupInstruction =1;
  1073.             secondArg = 1;
  1074.             next;
  1075.         }
  1076.         if($2 == "81")
  1077.         {
  1078.             Command[countCommand] = $1 " " "_ALU1 reg, addr";
  1079.             modR = 16;
  1080.             firstArg = 1;
  1081.             isGroupInstruction =1;
  1082.             secondArg = 1;
  1083.             next;
  1084.         }
  1085.         if($2 == "82")
  1086.         {
  1087.             Command[countCommand] = $1 " " "_ALU1 reg, addr";
  1088.             modR = 8;
  1089.             firstArg = 1;
  1090.             isGroupInstruction =1;
  1091.             secondArg = 1;
  1092.             next;
  1093.         }
  1094.         if($2 == "83")
  1095.         {
  1096.             Command[countCommand] = $1 " " "_ALU1 reg, addr";
  1097.             modR = 16;
  1098.             firstArg = 1;
  1099.             isGroupInstruction =1;
  1100.             secondArg = 1;
  1101.             isx83 = 1;
  1102.             next;
  1103.         }
  1104.         if($2 == "84")
  1105.         {
  1106.             Command[countCommand] = $1 " " "TEST ";
  1107.             modR = 8;
  1108.             firstArg = 0;
  1109.             next;
  1110.         }
  1111.         if($2 == "85")
  1112.         {
  1113.             Command[countCommand] = $1 " " "TEST ";
  1114.             modR = 16;
  1115.             firstArg = 0;
  1116.             next;
  1117.         }
  1118.         if($2 == "86")
  1119.         {
  1120.             Command[countCommand] = $1 " " "XCHG ";
  1121.             modR = 8;
  1122.             firstArg = 1;
  1123.             next;
  1124.         }
  1125.         if($2 == "87")
  1126.         {
  1127.             Command[countCommand] = $1 " " "XCHG ";
  1128.             modR = 16;
  1129.             firstArg = 1;
  1130.             next;
  1131.         }
  1132.         if($2 == "88")
  1133.         {
  1134.             Command[countCommand] = $1 " " "MOV ";
  1135.             modR = 8;
  1136.             firstArg = 0;
  1137.             next;
  1138.         }
  1139.         if($2 == "89")
  1140.         {
  1141.             Command[countCommand] = $1 " " "MOV ";
  1142.             modR = 16;
  1143.             firstArg = 0;
  1144.             next;
  1145.         }
  1146.         if($2 == "8a")
  1147.         {
  1148.             Command[countCommand] = $1 " " "MOV ";
  1149.             modR = 8;
  1150.             firstArg = 1;
  1151.             next;
  1152.         }
  1153.         if($2 == "8b")
  1154.         {
  1155.             Command[countCommand] = $1 " " "MOV ";
  1156.             modR = 16;
  1157.             firstArg = 1;
  1158.             next;
  1159.         }
  1160.         if($2 == "8c")
  1161.         {
  1162.             Command[countCommand] = $1 " " "_MOV reg, sr";
  1163.             modR = 16;
  1164.             firstArg = 1;
  1165.             isGroupInstruction = 1;
  1166.             secondArg = 0;
  1167.             next;
  1168.         }
  1169.         if($2 == "8d")
  1170.         {
  1171.             Command[countCommand] = $1 " " "LEA ";
  1172.             modR = 16;
  1173.             firstArg = 1;
  1174.             next;
  1175.         }
  1176.         if($2 == "8e")
  1177.         {
  1178.             Command[countCommand] = $1 " " "_MOV sr, reg";
  1179.             modR = 16;
  1180.             firstArg = 1;
  1181.             isGroupInstruction = 1;
  1182.             secondArg = 0;
  1183.             next;
  1184.         }
  1185.         if($2 == "8f")
  1186.         {
  1187.             Command[countCommand] = $1 " " "_POP reg";
  1188.             modR = 16;
  1189.             firstArg = 1;
  1190.             isGroupInstruction = 1;
  1191.             secondArg = 0;
  1192.             next;
  1193.         }
  1194.     }
  1195. }
  1196. $2 ~ /^9/ {
  1197.  
  1198.     if(fReadCommand == 0)
  1199.     {
  1200.         modR = 0;
  1201.         isData = 0;
  1202.         isRegister = 0;
  1203.         isLES_LDS = 0;
  1204.         isGroupInstruction = 0;
  1205.         isx83 = 0;
  1206.         firstArg = 0;  
  1207.         fReadCommand = 0;
  1208.         secondArg = 0;
  1209.         if($2 == "90")
  1210.         {
  1211.             Command[countCommand] = $1 " " "NOP";
  1212.             next;
  1213.         }
  1214.         if($2 == "91")
  1215.         {
  1216.             Command[countCommand] = $1 " " "XCHG AX,CX";
  1217.             next;
  1218.         }
  1219.         if($2 == "92")
  1220.         {
  1221.             Command[countCommand] = $1 " " "XCHG AX,DX";
  1222.             next;
  1223.         }
  1224.         if($2 == "93")
  1225.         {
  1226.             Command[countCommand] = $1 " " "XCHG AX,BX";
  1227.             next;
  1228.         }
  1229.         if($2 == "94")
  1230.         {
  1231.             Command[countCommand] = $1 " " "XCHG AX,SP";
  1232.             next;
  1233.         }
  1234.         if($2 == "95")
  1235.         {
  1236.             Command[countCommand] = $1 " " "XCHG AX,BP";
  1237.             next;
  1238.         }
  1239.         if($2 == "96")
  1240.         {
  1241.             Command[countCommand] = $1 " " "XCHG AX,SI";
  1242.             next;
  1243.         }
  1244.         if($2 == "97")
  1245.         {
  1246.             Command[countCommand] = $1 " " "XCHG AX,DI";
  1247.             next;
  1248.         }
  1249.         if($2 == "98")
  1250.         {
  1251.             Command[countCommand] = $1 " " "CBW";
  1252.             next;
  1253.         }
  1254.         if($2 == "99")
  1255.         {
  1256.             Command[countCommand] = $1 " " "CWD";
  1257.             next;
  1258.         }
  1259.         if($2 == "9a")
  1260.         {
  1261.             Command[countCommand] = $1 " " "CALL seg:";
  1262.             modR = 16;
  1263.             countCommand--;
  1264.             fReadCommand = 1;
  1265.             next;
  1266.         }
  1267.         if($2 == "9b")
  1268.         {
  1269.             Command[countCommand] = $1 " " "WAIT";
  1270.             next;
  1271.         }
  1272.         if($2 == "9c")
  1273.         {
  1274.             Command[countCommand] = $1 " " "PUSHF";
  1275.             next;
  1276.         }
  1277.         if($2 == "9d")
  1278.         {
  1279.             Command[countCommand] = $1 " " "POPF";
  1280.             next;
  1281.         }
  1282.         if($2 == "9e")
  1283.         {
  1284.             Command[countCommand] = $1 " " "SAHF";
  1285.             next;
  1286.         }
  1287.         if($2 == "9f")
  1288.         {
  1289.             Command[countCommand] = $1 " " "LAHF";
  1290.             next;
  1291.         }
  1292.         countCommand++;
  1293.     }
  1294. }
  1295. $2 ~ /^a/ {
  1296.  
  1297.     if(fReadCommand == 0)
  1298.     {
  1299.    
  1300.         modR = 0;
  1301.         isData = 0;
  1302.         isRegister = 0;
  1303.         isLES_LDS = 0;
  1304.         isGroupInstruction = 0;
  1305.         isx83 = 0;
  1306.         firstArg = 0;
  1307.         if($2 == "a0")
  1308.         {
  1309.             Command[countCommand] = $1 " " "MOV AL,[addr]";
  1310.             modR = 16;
  1311.             firstArg = 2;
  1312.             secondArg = 1;
  1313.             fReadCommand = 1;
  1314.             next;
  1315.         }
  1316.         if($2 == "a1")
  1317.         {
  1318.             Command[countCommand] = $1 " " "MOV AX,[addr]";
  1319.             modR = 16;
  1320.             firstArg = 2;
  1321.             secondArg = 1;
  1322.             fReadCommand = 1;
  1323.             next;
  1324.         }
  1325.         if($2 == "a2")
  1326.         {
  1327.             Command[countCommand] = $1 " " "MOV [addr],AL";
  1328.             modR = 16;
  1329.             firstArg = 3;
  1330.             secondArg = 0;
  1331.             fReadCommand = 1;
  1332.             next;
  1333.         }
  1334.         if($2 == "a3")
  1335.         {
  1336.             Command[countCommand] = $1 " " "MOV [addr],AX";
  1337.             modR = 16;
  1338.             firstArg = 3;
  1339.             secondArg = 0;
  1340.             fReadCommand = 1;
  1341.             next;
  1342.         }
  1343.         if($2 == "a4")
  1344.         {
  1345.             Command[countCommand] = $1 " " "MOVSB";
  1346.             fReadCommand = 1;
  1347.             countCommand++;
  1348.             next;
  1349.         }
  1350.         if($2 == "a5")
  1351.         {
  1352.             Command[countCommand] = $1 " " "MOVSW";
  1353.             fReadCommand = 1;
  1354.             countCommand++;
  1355.             next;
  1356.         }
  1357.         if($2 == "a6")
  1358.         {
  1359.             Command[countCommand] = $1 " " "CMPSB";
  1360.             fReadCommand = 1;
  1361.             countCommand++;
  1362.             next;
  1363.         }
  1364.         if($2 == "a7")
  1365.         {
  1366.             Command[countCommand] = $1 " " "CMPSW";
  1367.             fReadCommand = 1;
  1368.             countCommand++;
  1369.             next;
  1370.         }
  1371.         if($2 == "a8")
  1372.         {
  1373.             Command[countCommand] = $1 " " "TEST AL, ";
  1374.             modR = 8;
  1375.             firstArg = 2;
  1376.             secondArg = 0;
  1377.             next;
  1378.         }
  1379.         if($2 == "a9")
  1380.         {
  1381.             Command[countCommand] = $1 " " "TEST AX, ";
  1382.             modR = 16;
  1383.             firstArg = 2;
  1384.             secondArg = 0;
  1385.             next;
  1386.         }
  1387.         if($2 == "aa")
  1388.         {
  1389.             Command[countCommand] = $1 " " "STOSB";
  1390.             fReadCommand = 1;
  1391.             countCommand++;
  1392.             secondArg = 0;
  1393.             next;
  1394.         }
  1395.         if($2 == "ab")
  1396.         {
  1397.             Command[countCommand] = $1 " " "STOSW";
  1398.             fReadCommand = 1;
  1399.             countCommand++;
  1400.             secondArg = 0;
  1401.             next;
  1402.         }
  1403.         if($2 == "ac")
  1404.         {
  1405.             Command[countCommand] = $1 " " "LODSW";
  1406.             fReadCommand = 1;
  1407.             countCommand++;
  1408.             secondArg = 0;
  1409.             next;
  1410.         }
  1411.         if($2 == "ad")
  1412.         {
  1413.             Command[countCommand] = $1 " " "SCASW";
  1414.             fReadCommand = 1;
  1415.             countCommand++;
  1416.             secondArg = 0;
  1417.             next;
  1418.         }
  1419.         if($2 == "ae")
  1420.         {
  1421.             Command[countCommand] = $1 " " "CMPSW";
  1422.             fReadCommand = 1;
  1423.             countCommand++;
  1424.             secondArg = 0;
  1425.             next;
  1426.         }
  1427.         if($2 == "af")
  1428.         {
  1429.             Command[countCommand] = $1 " " "CMPSW";
  1430.             fReadCommand = 1;
  1431.             countCommand++;
  1432.             secondArg = 0;
  1433.             next;
  1434.         }
  1435.     }
  1436. }
  1437. $2 ~ /^b/ {
  1438.  
  1439.     if(fReadCommand == 0)
  1440.     {
  1441.         modR = 0;
  1442.         isData = 0;
  1443.         isRegister = 0;
  1444.         isLES_LDS = 0;
  1445.         isx83 = 0;
  1446.         fReadCommand = 1;
  1447.         firstArg = 2;
  1448.         secondArg = 0;
  1449.         isGroupInstruction = 0;
  1450.         if($2 == "b0")
  1451.         {
  1452.             Command[countCommand] = $1 " " "MOV AL, ";
  1453.             modR = 8;
  1454.             next;
  1455.         }
  1456.         if($2 == "b1")
  1457.         {
  1458.             Command[countCommand] = $1 " " "MOV CL, ";
  1459.             modR = 8;
  1460.             next;
  1461.         }
  1462.         if($2 == "b2")
  1463.         {
  1464.             Command[countCommand] = $1 " " "MOV DL, ";
  1465.             modR = 8;
  1466.             next;
  1467.         }
  1468.         if($2 == "b3")
  1469.         {
  1470.             Command[countCommand] = $1 " " "MOV BL, ";
  1471.             modR = 8;
  1472.             next;
  1473.         }
  1474.         if($2 == "b4")
  1475.         {
  1476.             Command[countCommand] = $1 " " "MOV AH, ";
  1477.             modR = 8;
  1478.             next;
  1479.         }
  1480.         if($2 == "b5")
  1481.         {
  1482.             Command[countCommand] = $1 " " "MOV CH, ";
  1483.             modR = 8;
  1484.             next;
  1485.         }
  1486.         if($2 == "b6")
  1487.         {
  1488.             Command[countCommand] = $1 " " "MOV DH, ";
  1489.             modR = 8;
  1490.             next;
  1491.         }
  1492.         if($2 == "b7")
  1493.         {
  1494.             Command[countCommand] = $1 " " "MOV BH, ";
  1495.             modR = 8;
  1496.             next;
  1497.         }
  1498.         if($2 == "b8")
  1499.         {
  1500.             Command[countCommand] = $1 " " "MOV AX, ";
  1501.             modR = 16;
  1502.             next;
  1503.         }
  1504.         if($2 == "b9")
  1505.         {
  1506.             Command[countCommand] = $1 " " "MOV CX, ";
  1507.             modR = 16;
  1508.             next;
  1509.         }
  1510.         if($2 == "ba")
  1511.         {
  1512.             Command[countCommand] = $1 " " "MOV DX, ";
  1513.             modR = 16;
  1514.             next;
  1515.         }
  1516.         if($2 == "bb")
  1517.         {
  1518.             Command[countCommand] = $1 " " "MOV BX, ";
  1519.             modR = 16;
  1520.             next;
  1521.         }
  1522.         if($2 == "bc")
  1523.         {
  1524.             Command[countCommand] = $1 " " "MOV SP, ";
  1525.             modR = 16;
  1526.             next;
  1527.         }
  1528.         if($2 == "bd")
  1529.         {
  1530.             Command[countCommand] = $1 " " "MOV BP, ";
  1531.             modR = 16;
  1532.             next;
  1533.         }
  1534.         if($2 == "be")
  1535.         {
  1536.             Command[countCommand] = $1 " " "MOV SI, ";
  1537.             modR = 16;
  1538.             next;
  1539.         }
  1540.         if($2 == "bf")
  1541.         {
  1542.             Command[countCommand] = $1 " " "MOV DI, ";
  1543.             modR = 16;
  1544.             next;
  1545.         }
  1546.     }
  1547. }
  1548. $2 ~ /^c/ {
  1549.  
  1550.     if(fReadCommand == 0)
  1551.     {
  1552.         modR = 0;
  1553.         isData = 0;
  1554.         isRegister = 0;
  1555.         isLES_LDS = 0;
  1556.         isGroupInstruction = 0;
  1557.         isx83 = 0;
  1558.         firstArg = 0;
  1559.         secondArg = 0;
  1560.         if($2 == "c0")
  1561.         {
  1562.             next;
  1563.         }
  1564.         if($2 == "c1")
  1565.         {
  1566.             next;
  1567.         }
  1568.         if($2 == "c2")
  1569.         {
  1570.             Command[countCommand] = $1 " " "RET ";
  1571.             modR = 16;
  1572.             fReadCommand = 1;
  1573.             firstArg = 2;
  1574.             next;
  1575.         }
  1576.         if($2 == "c3")
  1577.         {
  1578.             Command[countCommand] = $1 " " "RET";
  1579.             countCommand++;
  1580.             fReadCommand = 0;
  1581.             fEndCode = 1;
  1582.             next;
  1583.         }
  1584.         if($2 == "c4")
  1585.         {
  1586.             Command[countCommand] = $1 " " "LES ";
  1587.             modR = 16;
  1588.             fReadCommand = 1;
  1589.             firstArg = 0;
  1590.             isLES_LDS = 1;
  1591.             next;
  1592.         }
  1593.         if($2 == "c5")
  1594.         {
  1595.             Command[countCommand] = $1 " " "LDS ";
  1596.             modR = 16;
  1597.             fReadCommand = 1;
  1598.             firstArg = 0;
  1599.             isLES_LDS = 1;
  1600.             next;
  1601.         }
  1602.         if($2 == "c6")
  1603.         {
  1604.             Command[countCommand] = $1 " " "_MOV reg, addr";
  1605.             modR = 8;
  1606.             firstArg = 1;
  1607.             isGroupInstruction =1;
  1608.             secondArg = 1;
  1609.             next;
  1610.         }
  1611.         if($2 == "c7")
  1612.         {
  1613.             Command[countCommand] = $1 " " "_MOV reg, addr";
  1614.             modR = 16;
  1615.             firstArg = 1;
  1616.             isGroupInstruction =1;
  1617.             secondArg = 1;
  1618.             next;
  1619.         }
  1620.         if($2 == "c8")
  1621.         {
  1622.         }
  1623.         if($2 == "c9")
  1624.         {
  1625.         }
  1626.         if($2 == "ca")
  1627.         {
  1628.             Command[countCommand] = $1 " " "RETF ";
  1629.             fReadCommand = 1;
  1630.             firstArg = 2;
  1631.             modR = 16;
  1632.             next;
  1633.         }
  1634.         if($2 == "cb")
  1635.         {
  1636.             Command[countCommand] = $1 " " "RETF ";
  1637.             fReadCommand = 1;
  1638.             firstArg = 2;
  1639.             modR = 16;
  1640.             next;
  1641.         }
  1642.         if($2 == "cc")
  1643.         {
  1644.             Command[countCommand] = $1 " " "INT 3";
  1645.             countCommand++;
  1646.             fReadCommand = 0;
  1647.             next;
  1648.         }
  1649.         if($2 == "cd")
  1650.         {
  1651.             Command[countCommand] = $1 " " "INT ";
  1652.             fReadCommand = 1;
  1653.             firstArg = 2;
  1654.             modR = 8;
  1655.             next;
  1656.         }
  1657.         if($2 == "ce")
  1658.         {
  1659.             Command[countCommand] = $1 " " "INTO";
  1660.             countCommand++;
  1661.             fReadCommand = 0;
  1662.             next;
  1663.         }
  1664.         if($2 == "cf")
  1665.         {
  1666.             Command[countCommand] = $1 " " "IRET";
  1667.             countCommand++;
  1668.             fReadCommand = 0;
  1669.             next;
  1670.         }
  1671.     }
  1672. }
  1673. $2 ~ /^d/ {
  1674.  
  1675.     if(fReadCommand == 0)
  1676.     {
  1677.         modR = 0;
  1678.         isData = 0;
  1679.         isRegister = 0;
  1680.         isLES_LDS = 0;
  1681.         isGroupInstruction = 0;
  1682.         isx83 = 0;
  1683.         firstArg = 0;
  1684.         secondArg = 0;
  1685.         if($2 == "d0")
  1686.         {
  1687.             Command[countCommand] = $1 " " "_ROT reg , 1";
  1688.             modR = 8;
  1689.             firstArg = 1;
  1690.             isGroupInstruction = 1;
  1691.             secondArg = -1;
  1692.             fReadCommand = 1;
  1693.             next;
  1694.         }
  1695.         if($2 == "d1")
  1696.         {
  1697.             Command[countCommand] = $1 " " "_ROT reg , 1";
  1698.             modR = 16;
  1699.             firstArg = 1;
  1700.             isGroupInstruction = 1;
  1701.             secondArg = -1;
  1702.             fReadCommand = 1;
  1703.             next;
  1704.         }
  1705.         if($2 == "d2")
  1706.         {
  1707.             Command[countCommand] = $1 " " "_ROT reg , CL";
  1708.             modR = 8;
  1709.             firstArg = 1;
  1710.             isGroupInstruction = 1;
  1711.             secondArg = -1;
  1712.             fReadCommand = 1;
  1713.             next;
  1714.         }
  1715.         if($2 == "d3")
  1716.         {
  1717.             Command[countCommand] = $1 " " "_ROT reg,1";
  1718.             modR = 16;
  1719.             firstArg = 1;
  1720.             isGroupInstruction = -1;
  1721.             secondArg = 0;
  1722.             fReadCommand = 1;
  1723.             next;
  1724.         }
  1725.         if($2 == "d4")
  1726.         {
  1727.             Command[countCommand] = $1 " " "AAM *";
  1728.             fReadCommand = 1;
  1729.             firstArg = 2;
  1730.             modR = 8;
  1731.             next;
  1732.         }
  1733.         if($2 == "d5")
  1734.         {
  1735.             Command[countCommand] = $1 " " "AAD *";
  1736.             fReadCommand = 1;
  1737.             firstArg = 2;
  1738.             modR = 8;
  1739.             next;
  1740.         }
  1741.         if($2 == "d6")
  1742.         {
  1743.             Command[countCommand] = $1 " " "*SALC";
  1744.             countCommand++;
  1745.             next;
  1746.         }
  1747.         if($2 == "d7")
  1748.         {
  1749.             Command[countCommand] = $1 " " "XLAT";
  1750.             countCommand++;
  1751.             next;
  1752.         }
  1753.         if($2 == "d8")
  1754.         {
  1755.             Command[countCommand] = $1 " " "ESC 0";
  1756.             countCommand++;
  1757.             next;
  1758.         }
  1759.         if($2 == "d9")
  1760.         {
  1761.             omand[countCommand] = $1 " " "ESC 1";
  1762.             countCommand++;
  1763.             next;
  1764.         }
  1765.         if($2 == "da")
  1766.         {
  1767.             Command[countCommand] = $1 " " "ESC 2";
  1768.             countCommand++;
  1769.             next;
  1770.         }
  1771.         if($2 == "db")
  1772.         {
  1773.             Command[countCommand] = $1 " " "ESC 3";
  1774.             countCommand++;
  1775.             next;
  1776.         }
  1777.         if($2 == "dc")
  1778.         {
  1779.             Command[countCommand] = $1 " " "ESC 4";
  1780.             countCommand++;
  1781.             next;
  1782.         }
  1783.         if($2 == "dd")
  1784.         {
  1785.             Command[countCommand] = $1 " " "ESC 5";
  1786.             countCommand++;
  1787.             next;
  1788.         }
  1789.         if($2 == "de")
  1790.         {
  1791.             Command[countCommand] = $1 " " "ESC 6";
  1792.             countCommand++;
  1793.             next;
  1794.         }
  1795.         if($2 == "df")
  1796.         {
  1797.             Command[countCommand] = $1 " " "ESC 7";
  1798.             countCommand++;
  1799.             next;
  1800.         }
  1801.     }
  1802. }
  1803. $2 ~ /^e/ {
  1804.  
  1805.     if(fReadCommand == 0)
  1806.     {
  1807.         modR = 0;
  1808.         isData = 0;
  1809.         isRegister = 0;
  1810.         isLES_LDS = 0;
  1811.         isGroupInstruction = 0;
  1812.         isx83 = 0;
  1813.         firstArg = 0;
  1814.         secondArg = 0;
  1815.         if($2 == "e0")
  1816.         {
  1817.             Command[countCommand] = $1 " " "LOOPNZ/NE ";
  1818.             fReadCommand = 1;
  1819.             firstArg = 2;
  1820.             modR = 8;
  1821.             next;
  1822.         }
  1823.         if($2 == "e1")
  1824.         {
  1825.             Command[countCommand] = $1 " " "LOOPZ/E ";
  1826.             fReadCommand = 1;
  1827.             firstArg = 2;
  1828.             modR = 8;
  1829.             next;
  1830.         }
  1831.         if($2 == "e2")
  1832.         {
  1833.             Command[countCommand] = $1 " " "LOOP ";
  1834.             fReadCommand = 1;
  1835.             firstArg = 2;
  1836.             modR = 8;
  1837.             next;
  1838.         }
  1839.         if($2 == "e3")
  1840.         {
  1841.             Command[countCommand] = $1 " " "JCXZ ";
  1842.             fReadCommand = 1;
  1843.             firstArg = 2;
  1844.             modR = 8;
  1845.             next;
  1846.         }
  1847.         if($2 == "e4")
  1848.         {
  1849.             Command[countCommand] = $1 " " "IN AL,[addr]";
  1850.             fReadCommand = 1;
  1851.             firstArg = 2;
  1852.             secondArg = 1;
  1853.             modR = 8;
  1854.             next;
  1855.         }
  1856.         if($2 == "e5")
  1857.         {
  1858.             Command[countCommand] = $1 " " "IN AX,[addr]";
  1859.             fReadCommand = 1;
  1860.             firstArg = 2;
  1861.             secondArg = 1;
  1862.             modR = 8;
  1863.             next;
  1864.         }
  1865.         if($2 == "e6")
  1866.         {
  1867.             Command[countCommand] = $1 " " "OUT [addr],AL";
  1868.             fReadCommand = 1;
  1869.             firstArg = 3;
  1870.             secondArg = 0;
  1871.             modR = 8;
  1872.             next;
  1873.         }
  1874.         if($2 == "e7")
  1875.         {
  1876.             Command[countCommand] = $1 " " "OUT [addr],AX";
  1877.             fReadCommand = 1;
  1878.             firstArg = 3;
  1879.             secondArg = 0;
  1880.             modR = 8;
  1881.             next;
  1882.         }
  1883.         if($2 == "e8")
  1884.         {
  1885.             Command[countCommand] = $1 " " "CALL ";
  1886.             fReadCommand = 1;
  1887.             firstArg = 2;
  1888.             secondArg = 0;
  1889.             modR = 16;
  1890.             next;
  1891.         }
  1892.         if($2 == "e9")
  1893.         {
  1894.             Command[countCommand] = $1 " " "JMP ";
  1895.             fReadCommand = 1;
  1896.             firstArg = 2;
  1897.             secondArg = 0;
  1898.             modR = 16;
  1899.             next;
  1900.         }
  1901.         if($2 == "ea")
  1902.         {
  1903.             Command[countCommand] = $1 " " "JMP seg: ";
  1904.             fReadCommand = 1;
  1905.             firstArg = 2;
  1906.             secondArg = 0;
  1907.             modR = 16;
  1908.             next;
  1909.         }
  1910.         if($2 == "eb")
  1911.         {
  1912.             Command[countCommand] = $1 " " "JMP ";
  1913.             fReadCommand = 1;
  1914.             firstArg = 2;
  1915.             secondArg = 0;
  1916.             modR = 8;
  1917.             next;
  1918.         }
  1919.         if($2 == "ec")
  1920.         {
  1921.             Command[countCommand] = $1 " " "IN AL,[DX]";
  1922.             countCommand++;
  1923.             fReadCommand = 0;
  1924.             next;
  1925.         }
  1926.         if($2 == "ed")
  1927.         {
  1928.             Command[countCommand] = $1 " " "N AX,[DX]";
  1929.             countCommand++;
  1930.             fReadCommand = 0;
  1931.             next;
  1932.         }
  1933.         if($2 == "ee")
  1934.         {
  1935.             Command[countCommand] = $1 " " "OUT [DX],AL";
  1936.             countCommand++;
  1937.             fReadCommand = 0;
  1938.             next;
  1939.         }
  1940.         if($2 == "ef")
  1941.         {
  1942.             Command[countCommand] = $1 " " "OUT [DX],AX";
  1943.             countCommand++;
  1944.             fReadCommand = 0;
  1945.             next;
  1946.         }
  1947.     }
  1948. }
  1949. $2 ~ /^f/ {
  1950.  
  1951.     if(fReadCommand == 0)
  1952.     {
  1953.         modR = 0;
  1954.         isData = 0;
  1955.         isRegister = 0;
  1956.         isLES_LDS = 0;
  1957.         isGroupInstruction = 0;
  1958.         isx83 = 0;
  1959.         firstArg = 0;
  1960.         secondArg = 0;
  1961.         fReadCommand = 1;
  1962.         if($2 == "f0")
  1963.         {
  1964.             Command[countCommand] = $1 " " "LOCK";
  1965.             countCommand++;
  1966.             fReadCommand = 0;
  1967.             next;
  1968.         }
  1969.         if($2 == "f1")
  1970.         {
  1971.         }
  1972.         if($2 == "f2")
  1973.         {
  1974.             Command[countCommand] = $1 " " "REPNE/REPNZ";
  1975.             countCommand++;
  1976.             fReadCommand = 0;
  1977.             next;
  1978.         }
  1979.         if($2 == "f3")
  1980.         {
  1981.             Command[countCommand] = $1 " " "REP/REPE/REPZ";
  1982.             countCommand++;
  1983.             fReadCommand = 0;
  1984.             next;
  1985.         }
  1986.         if($2 == "f4")
  1987.         {
  1988.             Command[countCommand] = $1 " " "HLT";
  1989.             CommandsEND = $1;
  1990.             countCommand++;
  1991.             fReadCommand = 0;
  1992.             fEndCode = 1;
  1993.             next;
  1994.         }
  1995.         if($2 == "f5")
  1996.         {
  1997.             Command[countCommand] = $1 " " "CMC";
  1998.             countCommand++;
  1999.             fReadCommand = 0;
  2000.             next;
  2001.         }
  2002.         if($2 == "f6")
  2003.         {
  2004.             Command[countCommand] = $1 " " "_ALU2 reg, addr";
  2005.             modR = 8;
  2006.             firstArg = 1;
  2007.             isGroupInstruction = 1;
  2008.             secondArg = 1;
  2009.             next;
  2010.         }
  2011.         if($2 == "f7")
  2012.         {
  2013.             Command[countCommand] = $1 " " "_ALU2 reg, addr";
  2014.             modR = 16;
  2015.             firstArg = 1;
  2016.             isGroupInstruction = 1;
  2017.             secondArg = 1;
  2018.             next;
  2019.         }
  2020.         if($2 == "f8")
  2021.         {
  2022.             Command[countCommand] = $1 " " "CLC";
  2023.             countCommand++;
  2024.             fReadCommand = 0;
  2025.             next;
  2026.         }
  2027.         if($2 == "f9")
  2028.         {
  2029.             Command[countCommand] = $1 " " "STC";
  2030.             countCommand++;
  2031.             fReadCommand = 0;
  2032.             next;
  2033.         }
  2034.         if($2 == "fa")
  2035.         {
  2036.             Command[countCommand] = $1 " " "CLI";
  2037.             countCommand++;
  2038.             fReadCommand = 0;
  2039.             next;
  2040.         }
  2041.         if($2 == "fb")
  2042.         {
  2043.             Command[countCommand] = $1 " " "STI";
  2044.             countCommand++;
  2045.             fReadCommand = 0;
  2046.             next;
  2047.         }
  2048.         if($2 == "fc")
  2049.         {
  2050.             Command[countCommand] = $1 " " "CLD";
  2051.             countCommand++;
  2052.             fReadCommand = 0;
  2053.             next;
  2054.         }
  2055.         if($2 == "fd")
  2056.         {
  2057.             Command[countCommand] = $1 " " "STD";
  2058.             countCommand++;
  2059.             fReadCommand = 0;
  2060.             next;
  2061.         }
  2062.         if($2 == "fe")
  2063.         {
  2064.             Command[countCommand] = $1 " " "_MISC reg";
  2065.             modR = 8;
  2066.             firstArg = 1;
  2067.             isGroupInstruction = 1;
  2068.             secondArg = -1;
  2069.             next;
  2070.         }
  2071.         if($2 == "ff")
  2072.         {
  2073.             Command[countCommand] = $1 " " "_MISC reg";
  2074.             modR = 16;
  2075.             firstArg = 1;
  2076.             isGroupInstruction = 1;
  2077.             secondArg = -1;
  2078.             next;
  2079.         }
  2080.     }
  2081. }
  2082. #вывод всех команд
  2083. END {
  2084.     for(i=0; i < countCommand; i=i+1)
  2085.         print(Command[i]);
  2086. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement