Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Дизассемблер арифметических команд под x86 / 25 сообщений из 25, страница 1 из 1
01.04.2016, 00:38
    #39205586
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Доброго времени суток!
Вот всё задание:
Задан двоичный код, представляющий программу процес¬сора 8088/86. Составить программу дизассемблирования этого двоичного кода. Результат дизассемблирования должен содержать следующую информацию:
- мнемонический код машинной команды (в формате отладчика типа АТ 86),
- устанавливаемые машинной командой флаги,
Исходный двоичный код должен быть введен в режиме ASCII (либо с помощью любого текстового редактора, либо с помощью блока ввода в составляемой программе) и сох¬ранен в виде текстового файла). Для дальнейшего дизас
семблирования исходного кода он должен быть преобразован
в битовый код, сохраняемый либо в ОЗУ либо в виде файла.
Ограничения:
В исходный двоичный код должны быть включены только арифметические команды.
Я накодил, невероятно коряво, но хотя бы работало.
Показал преподавателю(лучше бы не показывал). Теперь она хочет, чтобы все кодировки регистров, адресации памяти и опкоды считывались из файла, можно ли из файла считать в мапу и ключи и значения? Но это ещё пол беды, ещё она хочет, чтобы, в зависимости от опкода, вызывался метод его обрабатывающий. Было бы замечательно создать какой-нибудь Map<опкод,"что-то, что будет вызывать метод">, но ума не приложу, как это сделать и можно ли сделать вообще.
Заранее огромное спасибо за любую помощь.
Вот сам код(не весь).
Код: java
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.
    package spo_1;
     
    import java.util.Map;
    import java.util.Scanner;
    import java.util.TreeMap;
     
    public class SPO_1 {
     
        public static void main(String[] args) {
            Map<String, String> NewNames = new TreeMap<>();
            Map DirectAddr8 = new TreeMap();
            Map DirectAddr16 = new TreeMap();
            Map LinkedAddr = new TreeMap();
    //=====================================================
            DirectAddr8.put("000", "AL");
            DirectAddr8.put("001", "CL");
            DirectAddr8.put("010", "DL");
            DirectAddr8.put("011", "BL");
            DirectAddr8.put("100", "AH");
            DirectAddr8.put("101", "CH");
            DirectAddr8.put("110", "DH");
            DirectAddr8.put("111", "BH");
    //=====================================================        
            DirectAddr16.put("000", "AX");
            DirectAddr16.put("001", "CX");
            DirectAddr16.put("010", "DX");
            DirectAddr16.put("011", "BX");
            DirectAddr16.put("100", "SP");
            DirectAddr16.put("101", "BP");
            DirectAddr16.put("110", "SI");
            DirectAddr16.put("111", "DI");
     
    //=====================================================
            LinkedAddr.put("000", "[BX+SI+");
            LinkedAddr.put("001", "[BX+DI+");
            LinkedAddr.put("010", "[BP+SI+");
            LinkedAddr.put("011", "[BP+DI+");
            LinkedAddr.put("100", "[SI+");
            LinkedAddr.put("101", "[DI+");
            LinkedAddr.put("110", "[BP+");
            LinkedAddr.put("111", "[BX+");
    //=====================================================
     
    //--------------------------------------------------------------
            NewNames.put("00000100", "ADD ");//AX/AL,DATA
            NewNames.put("00000101", "ADD ");//----------
            NewNames.put("10000000000", "ADD ");//R/M,DATA 1
            NewNames.put("10000001000", "ADD ");//
            NewNames.put("10000010000", "ADD WORD PTR ");//-------
            NewNames.put("00000010", "ADD ");//REG,R/M
            NewNames.put("00000011", "ADD ");//----------
            NewNames.put("00000000", "ADD ");//R/M, REG
            NewNames.put("00000001", "ADD ");//----------
    //---------------------------------------------------------------
            NewNames.put("00010100", "ADC ");
            NewNames.put("00010101", "ADC ");
            NewNames.put("10000000010", "ADC ");//R/M,DATA 1
            NewNames.put("10000001010", "ADC ");//
            NewNames.put("10000010010", "ADC WORD PTR ");//-------
            NewNames.put("00010010", "ADC ");//REG,R/M
            NewNames.put("00010011", "ADC ");//----------
            NewNames.put("00010000", "ADC ");//R/M, REG
            NewNames.put("00010001", "ADC ");//----------
    //---------------------------------------------------------------
            NewNames.put("00101100", "SUB ");
            NewNames.put("00101101", "SUB ");
            NewNames.put("10000000101", "SUB ");//R/M,DATA 1
            NewNames.put("10000001101", "SUB ");//
            NewNames.put("10000010101", "SUB WORD PTR ");//-------
            NewNames.put("00101010", "SUB ");//REG,R/M
            NewNames.put("00101011", "SUB ");//----------
            NewNames.put("00101000", "SUB ");//R/M, REG
            NewNames.put("00101001", "SUB ");//----------
     
    //---------------------------------------------------------------
            NewNames.put("00011100", "SBB ");
            NewNames.put("00011101", "SBB ");
            NewNames.put("10000000011", "SBB ");//R/M,DATA 1
            NewNames.put("10000001011", "SBB ");//
            NewNames.put("10000010011", "SBB WORD PTR ");//-------
            NewNames.put("00011010", "SBB ");//REG,R/M
            NewNames.put("00011011", "SBB ");//----------
            NewNames.put("00011000", "SBB ");//R/M, REG
            NewNames.put("00011001", "SBB ");//----------
    //---------------------------------------------------------------
            NewNames.put("00111100", "CMP ");
            NewNames.put("00111101", "CMP ");
            NewNames.put("10000000111", "CMP ");//R/M,DATA 1
            NewNames.put("10000001111", "CMP ");//
            NewNames.put("10000010111", "CMP WORD PTR ");//-------
            NewNames.put("00111010", "CMP ");//REG,R/M
            NewNames.put("00111011", "CMP ");//----------
            NewNames.put("00111000", "CMP ");//R/M, REG
            NewNames.put("00111001", "CMP ");//----------
    //---------------------------------------------------------------
            NewNames.put("11110110110", "DIV ");//R/M
            NewNames.put("11110111110", "DIV ");//R/M
            NewNames.put("11110110111", "IDIV ");//R/M
            NewNames.put("11110111111", "IDIV ");//R/M
            NewNames.put("11110110011", "NEG ");//R/M
            NewNames.put("11110111011", "NEG ");//R/M
            NewNames.put("11110110100", "MUL ");//R/M
            NewNames.put("11110111100", "MUL ");//R/M
            NewNames.put("11110110110", "IMUL ");//R/M
            NewNames.put("11110111101", "IMUL ");//R/M
            NewNames.put("11111110000", "INC ");//R/M
            NewNames.put("11111111000", "INC ");//R/M
            NewNames.put("11111110001", "DEC ");//R/M
            NewNames.put("11111111001", "DEC ");//R/M
     
    //--------------------------------------------------------------
            NewNames.put("10011001", "CWD");
            NewNames.put("10011000", "CBW");
            NewNames.put("01000", "INC ");
            NewNames.put("01001", "DEC ");
     
    //--------------------------------------------------------------
        
            Scanner s1 = new Scanner(System.in);
            String S1;
            S1 = s1.nextLine();
            System.out.println(S1);
            String S10 = S1.substring(0, 5);//для inc и dec с кодом регистра в опкоде
            String S11 = S1.substring(0, 8);
            String S21 = S1.substring(0, 8);
            String md = null;
            String rm = null;
     
            if (!(S11.equals("10011001") || S11.equals("10011000") || S10.equals("01000") || S10.equals("01001"))) {
                md = S1.substring(9, 11);//mod
                rm = S1.substring(14, 17);
                S21 += S1.substring(11, 14);
            }
     
            //однобайтные команды-----------------------------------------------------//
            if (S11.equals("10011001") || S11.equals("10011000")) {
                System.out.println(NewNames.get(S11) + " | O,S,Z,A,P,C");
                return;
            }
            //inc и dec с кодом регистра в опкоде-----------------------------------//
            if (S10.equals("01000") || S10.equals("01001")) {
                System.out.println(NewNames.get(S10) + DirectAddr8.get(S1.substring(5, 8)) + " | O,S,Z,A,P,C");
                return;
            }
     
     //команды c непосредственным операндом------------------------------------//
            //---------------mod=null----------------//
            if (S11.equals("00000100") || S11.equals("00010100") || S11.equals("00101100") || S11.equals("00011100") || S11.equals("00111100")) {
                System.out.println(NewNames.get(S11) + DirectAddr8.get("000") + "," + Integer.toHexString(Integer.parseInt(S1.substring(9, 17), 2)) + " | O,S,Z,A,P,C");
                return;
            }
     
            if (S11.equals("00000101") || S11.equals("00010101") || S11.equals("00101101") || S11.equals("00011101") || S11.equals("00111101")) {
                System.out.println(NewNames.get(S11) + DirectAddr16.get("000") + "," + Integer.toHexString(Integer.parseInt(S1.substring(9, 17), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
                return;
            }
            //---------------mod=11----------------//
            if (md.equals("11")) {//проверка mod
                //команды c непосредственным операндом------------------------------------//
                if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111")) {
                    System.out.println(NewNames.get(S21) + DirectAddr8.get(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
                    return;
     
                }
     
                if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
                    System.out.println(NewNames.get(S21) + DirectAddr16.get(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
                    return;
                }
     
                if (S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
                    System.out.println(NewNames.get(S21) + DirectAddr16.get(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
                    return;
                }
                //-----------------команды reg,r/m-----------------------------------------------------//
                if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010") || S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
                    System.out.println(NewNames.get(S11) + DirectAddr8.get(S1.substring(11, 14)) + ", " + DirectAddr8.get(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                    return;
                }
                if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111011") || S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
                    System.out.println(NewNames.get(S11) + DirectAddr16.get(S1.substring(11, 14)) + ", " + DirectAddr16.get(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                    return;
                }
                //-----------------команды r/m-----------------------------------------------------//
                if (S21.equals("11110110110") || S21.equals("11110110111") || S21.equals("11110110011") || S21.equals("11110110100") || S21.equals("11110110101") || S21.equals("11111110000") || S21.equals("11111110001")) {
                    System.out.println(NewNames.get(S21) + DirectAddr8.get(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                    return;
                }
                if (S21.equals("11110111110") || S21.equals("11110111111") || S21.equals("11110111011") || S21.equals("11110111100") || S21.equals("11110111101") || S21.equals("11111111000") || S21.equals("11111111001")) {
                    System.out.println(NewNames.get(S21) + DirectAddr16.get(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                    return;
                }
            }
     
            //---------------mod=01----------------//
            if (md.equals("01")) {//проверка mod
                //команды c непосредственным операндом------------------------------------//
                if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111") || S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
                    System.out.println(NewNames.get(S21) + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
                    return;
                }
                if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
                    System.out.println(NewNames.get(S21) + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
                    return;
                }
                //-----------------команды reg,r/m-----------------------------------------------------//
                if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
                    System.out.println(NewNames.get(S11) + DirectAddr8.get(S1.substring(11, 14)) + ", " + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
                    return;
                }
                if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
                    System.out.println(NewNames.get(S11) + DirectAddr16.get(S1.substring(11, 14)) + ", " + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
                    return;
                }
                //-----------------команды r/m,reg-----------------------------------------------------//
                if (S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
                    System.out.println(NewNames.get(S11) + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + ", " + DirectAddr8.get(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
                    return;
                }
                if (S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
                    System.out.println(NewNames.get(S11) + LinkedAddr.get(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + ", " + DirectAddr16.get(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
                    return;
                }
                
            }
...
Рейтинг: 0 / 0
01.04.2016, 09:18
    #39205693
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
1) Правильно все она говорит. Справочники обычно кладут в файлы. Сегмент кода надо экономить.
2) Твой сорс - это идеальный строительный материал для рефакторинга. Тут даже не разбираясь
в предметной области можно уже начать делать эквивалентные преобразования и улучшения.
...
Рейтинг: 0 / 0
01.04.2016, 09:58
    #39205737
golovonometr
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mycodeurnghtmr,

Если тебе помогут, ты обещаешь улучшить свой код?) Держи)

Код: java
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.
package spo_1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SPO_1
{

  private final Properties newNames = new Properties();
  private final Properties directAddr8 = new Properties();
  private final Properties directAddr16 = new Properties();
  private final Properties linkedAddr = new Properties();

  public SPO_1()
  {
    initProps();
  }
  
  private void initProps()
  {
    //грузим настройки из файлов
    InputStreamReader propsReader = null;
    try {
      propsReader = new InputStreamReader(new FileInputStream("c:/test/newNames.txt"), "windows-1251"); // или "UTF-8"
      newNames.load(propsReader);
      propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr8.txt"), "windows-1251"); // или "UTF-8"
      directAddr8.load(propsReader);
      propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr16.txt"), "windows-1251"); // или "UTF-8"
      directAddr16.load(propsReader);
      propsReader = new InputStreamReader(new FileInputStream("c:/test/linkedAddr.txt"), "windows-1251"); // или "UTF-8"
      linkedAddr.load(propsReader);
      
/* эти данные запиши в файлы newNames.txt, directAddr8.txt, directAddr16.txt, linkedAddr.txt (наверно ты уже понял:)
    DirectAddr8.put("000", "AL");
    DirectAddr8.put("001", "CL");
    DirectAddr8.put("010", "DL");
    DirectAddr8.put("011", "BL");
    DirectAddr8.put("100", "AH");
    DirectAddr8.put("101", "CH");
    DirectAddr8.put("110", "DH");
    DirectAddr8.put("111", "BH");
    //=====================================================        
    DirectAddr16.put("000", "AX");
    DirectAddr16.put("001", "CX");
    DirectAddr16.put("010", "DX");
    DirectAddr16.put("011", "BX");
    DirectAddr16.put("100", "SP");
    DirectAddr16.put("101", "BP");
    DirectAddr16.put("110", "SI");
    DirectAddr16.put("111", "DI");

    //=====================================================
    LinkedAddr.put("000", "[BX+SI+");
    LinkedAddr.put("001", "[BX+DI+");
    LinkedAddr.put("010", "[BP+SI+");
    LinkedAddr.put("011", "[BP+DI+");
    LinkedAddr.put("100", "[SI+");
    LinkedAddr.put("101", "[DI+");
    LinkedAddr.put("110", "[BP+");
    LinkedAddr.put("111", "[BX+");
    //=====================================================

    //--------------------------------------------------------------
    NewNames.put("00000100", "ADD ");//AX/AL,DATA
    NewNames.put("00000101", "ADD ");//----------
    NewNames.put("10000000000", "ADD ");//R/M,DATA 1
    NewNames.put("10000001000", "ADD ");//
    NewNames.put("10000010000", "ADD WORD PTR ");//-------
    NewNames.put("00000010", "ADD ");//REG,R/M
    NewNames.put("00000011", "ADD ");//----------
    NewNames.put("00000000", "ADD ");//R/M, REG
    NewNames.put("00000001", "ADD ");//----------
    //---------------------------------------------------------------
    NewNames.put("00010100", "ADC ");
    NewNames.put("00010101", "ADC ");
    NewNames.put("10000000010", "ADC ");//R/M,DATA 1
    NewNames.put("10000001010", "ADC ");//
    NewNames.put("10000010010", "ADC WORD PTR ");//-------
    NewNames.put("00010010", "ADC ");//REG,R/M
    NewNames.put("00010011", "ADC ");//----------
    NewNames.put("00010000", "ADC ");//R/M, REG
    NewNames.put("00010001", "ADC ");//----------
    //---------------------------------------------------------------
    NewNames.put("00101100", "SUB ");
    NewNames.put("00101101", "SUB ");
    NewNames.put("10000000101", "SUB ");//R/M,DATA 1
    NewNames.put("10000001101", "SUB ");//
    NewNames.put("10000010101", "SUB WORD PTR ");//-------
    NewNames.put("00101010", "SUB ");//REG,R/M
    NewNames.put("00101011", "SUB ");//----------
    NewNames.put("00101000", "SUB ");//R/M, REG
    NewNames.put("00101001", "SUB ");//----------

    //---------------------------------------------------------------
    NewNames.put("00011100", "SBB ");
    NewNames.put("00011101", "SBB ");
    NewNames.put("10000000011", "SBB ");//R/M,DATA 1
    NewNames.put("10000001011", "SBB ");//
    NewNames.put("10000010011", "SBB WORD PTR ");//-------
    NewNames.put("00011010", "SBB ");//REG,R/M
    NewNames.put("00011011", "SBB ");//----------
    NewNames.put("00011000", "SBB ");//R/M, REG
    NewNames.put("00011001", "SBB ");//----------
    //---------------------------------------------------------------
    NewNames.put("00111100", "CMP ");
    NewNames.put("00111101", "CMP ");
    NewNames.put("10000000111", "CMP ");//R/M,DATA 1
    NewNames.put("10000001111", "CMP ");//
    NewNames.put("10000010111", "CMP WORD PTR ");//-------
    NewNames.put("00111010", "CMP ");//REG,R/M
    NewNames.put("00111011", "CMP ");//----------
    NewNames.put("00111000", "CMP ");//R/M, REG
    NewNames.put("00111001", "CMP ");//----------
    //---------------------------------------------------------------
    NewNames.put("11110110110", "DIV ");//R/M
    NewNames.put("11110111110", "DIV ");//R/M
    NewNames.put("11110110111", "IDIV ");//R/M
    NewNames.put("11110111111", "IDIV ");//R/M
    NewNames.put("11110110011", "NEG ");//R/M
    NewNames.put("11110111011", "NEG ");//R/M
    NewNames.put("11110110100", "MUL ");//R/M
    NewNames.put("11110111100", "MUL ");//R/M
    NewNames.put("11110110110", "IMUL ");//R/M
    NewNames.put("11110111101", "IMUL ");//R/M
    NewNames.put("11111110000", "INC ");//R/M
    NewNames.put("11111111000", "INC ");//R/M
    NewNames.put("11111110001", "DEC ");//R/M
    NewNames.put("11111111001", "DEC ");//R/M

    //--------------------------------------------------------------
    NewNames.put("10011001", "CWD");
    NewNames.put("10011000", "CBW");
    NewNames.put("01000", "INC ");
    NewNames.put("01001", "DEC ");
      
в формате:

# символ начала комментария в файле
000=AL
001=CL
# и т.д.
*/
      
    } catch (FileNotFoundException ex) {
      ex.printStackTrace(); // обрабатывай ошибки и выводи соответствующие сообщения в консоль
    } catch (UnsupportedEncodingException ex) {
      ex.printStackTrace();  // обрабатывай ошибки и выводи соответствующие сообщения в консоль
    } catch (IOException ex) {
      ex.printStackTrace();  // обрабатывай ошибки и выводи соответствующие сообщения в консоль
    } finally {
      try {
        propsReader.close();  // закрой реадер - не лишне
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
  
  public void run()
  {
    //--------------------------------------------------------------

    Scanner s1 = new Scanner(System.in);
    String S1;
    S1 = s1.nextLine();
    System.out.println(S1);
    String S10 = S1.substring(0, 5);//для inc и dec с кодом регистра в опкоде
    String S11 = S1.substring(0, 8);
    String S21 = S1.substring(0, 8);
    String md = null;
    String rm = null;
// вот здесь у тебя трэш, разбор строк и условия нужно улучшать
    if (!(S11.equals("10011001") || S11.equals("10011000") || S10.equals("01000") || S10.equals("01001"))) {
      md = S1.substring(9, 11);//mod
      rm = S1.substring(14, 17);
      S21 += S1.substring(11, 14);
    }

    //однобайтные команды-----------------------------------------------------//
    if (S11.equals("10011001") || S11.equals("10011000")) {
      System.out.println(newNames.getProperty(S11) + " | O,S,Z,A,P,C");
      return;
    }
    //inc и dec с кодом регистра в опкоде-----------------------------------//
    if (S10.equals("01000") || S10.equals("01001")) {
      System.out.println(newNames.getProperty(S10) + directAddr8.getProperty(S1.substring(5, 8)) + " | O,S,Z,A,P,C");
      return;
    }

    //команды c непосредственным операндом------------------------------------//
    //---------------mod=null----------------//
    if (S11.equals("00000100") || S11.equals("00010100") || S11.equals("00101100") || S11.equals("00011100") || S11.equals("00111100")) {
      System.out.println(newNames.getProperty(S11) + directAddr8.getProperty("000") + "," + Integer.toHexString(Integer.parseInt(S1.substring(9, 17), 2)) + " | O,S,Z,A,P,C");
      return;
    }

    if (S11.equals("00000101") || S11.equals("00010101") || S11.equals("00101101") || S11.equals("00011101") || S11.equals("00111101")) {
      System.out.println(newNames.getProperty(S11) + directAddr16.getProperty("000") + "," + Integer.toHexString(Integer.parseInt(S1.substring(9, 17), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
      return;
    }
    //---------------mod=11----------------//
    if (md.equals("11")) {//проверка mod
      //команды c непосредственным операндом------------------------------------//
      if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111")) {
        System.out.println(newNames.getProperty(S21) + directAddr8.getProperty(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
        return;

      }

      if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
        System.out.println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
        return;
      }

      if (S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
        System.out.println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
        return;
      }
      //-----------------команды reg,r/m-----------------------------------------------------//
      if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010") || S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
        System.out.println(newNames.getProperty(S11) + directAddr8.getProperty(S1.substring(11, 14)) + ", " + directAddr8.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
        return;
      }
      if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111011") || S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
        System.out.println(newNames.getProperty(S11) + directAddr16.getProperty(S1.substring(11, 14)) + ", " + directAddr16.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
        return;
      }
      //-----------------команды r/m-----------------------------------------------------//
      if (S21.equals("11110110110") || S21.equals("11110110111") || S21.equals("11110110011") || S21.equals("11110110100") || S21.equals("11110110101") || S21.equals("11111110000") || S21.equals("11111110001")) {
        System.out.println(newNames.getProperty(S21) + directAddr8.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
        return;
      }
      if (S21.equals("11110111110") || S21.equals("11110111111") || S21.equals("11110111011") || S21.equals("11110111100") || S21.equals("11110111101") || S21.equals("11111111000") || S21.equals("11111111001")) {
        System.out.println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
        return;
      }
    }

    //---------------mod=01----------------//
    if (md.equals("01")) {//проверка mod
      //команды c непосредственным операндом------------------------------------//
      if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111") || S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
        System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
        return;
      }
      if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
        System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(S1.substring(27, 35), 2)) + Integer.toHexString(Integer.parseInt(S1.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
        return;
      }
      //-----------------команды reg,r/m-----------------------------------------------------//
      if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
        System.out.println(newNames.getProperty(S11) + directAddr8.getProperty(S1.substring(11, 14)) + ", " + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
        return;
      }
      if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
        System.out.println(newNames.getProperty(S11) + directAddr16.getProperty(S1.substring(11, 14)) + ", " + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
        return;
      }
      //-----------------команды r/m,reg-----------------------------------------------------//
      if (S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
        System.out.println(newNames.getProperty(S11) + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + ", " + directAddr8.getProperty(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
        return;
      }
      if (S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
        System.out.println(newNames.getProperty(S11) + linkedAddr.getProperty(S1.substring(14, 17)) + Integer.toHexString(Integer.parseInt(S1.substring(18, 26), 2)) + "]" + ", " + directAddr16.getProperty(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
        return;
      }
    }
    
  }

  public static void main(String[] args)
  {
    new SPO_1().run();
  }
}
...
Рейтинг: 0 / 0
01.04.2016, 10:23
    #39205776
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Добавил функцию matchTo(). Возможно она позволит свернуть повторяющиеся проверки в if

Код: java
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.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.Scanner;

import static java.lang.Integer.parseInt;
import static java.lang.Integer.toHexString;

public class SPO_1 {

    private final Properties newNames = new Properties();
    private final Properties directAddr8 = new Properties();
    private final Properties directAddr16 = new Properties();
    private final Properties linkedAddr = new Properties();

    public SPO_1() {
        initProps();
    }

    public static void println(String s){
        System.out.println(s);
    }
    
    public static boolean matchTo(String buf,String pattern){
        for(int i=0;i<pattern.length();i++){
            if (pattern.charAt(i)=='*'){
                continue;
            } else if (buf.charAt(i)==pattern.charAt(i)){
                continue;
            } else {
                return false;
            }
        }
        return true;
    }
    
    private void initProps() {
        //грузим настройки из файлов
        InputStreamReader propsReader = null;
        try {
            propsReader = new InputStreamReader(new FileInputStream("c:/test/newNames.txt"), "windows-1251"); // или "UTF-8"
            newNames.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr8.txt"), "windows-1251"); // или "UTF-8"
            directAddr8.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr16.txt"), "windows-1251"); // или "UTF-8"
            directAddr16.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/linkedAddr.txt"), "windows-1251"); // или "UTF-8"
            linkedAddr.load(propsReader);

        } catch (IOException ex) {
            ex.printStackTrace(); // обрабатывай ошибки и выводи соответствующие сообщения в консоль
        } finally {
            try {
                propsReader.close();  // закрой реадер - не лишне
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    public void run() {
        //--------------------------------------------------------------

        Scanner s1 = new Scanner(System.in);
        String S1;
        S1 = s1.nextLine();
        println(S1);
        String S10 = S1.substring(0, 5);//для inc и dec с кодом регистра в опкоде
        String S11 = S1.substring(0, 8);
        String S21 = S1.substring(0, 8);
        String md = null;
        String rm = null;
        // вот здесь у тебя трэш, разбор строк и условия нужно улучшать
        // TODO: Refactor with 'matchTo()'
        if (!(S11.equals("10011001") || S11.equals("10011000") || S10.equals("01000") || S10.equals("01001"))) {
            md = S1.substring(9, 11);//mod
            rm = S1.substring(14, 17);
            S21 += S1.substring(11, 14);
        }

        //однобайтные команды-----------------------------------------------------//
        if (S11.equals("10011001") || S11.equals("10011000")) {
            println(newNames.getProperty(S11) + " | O,S,Z,A,P,C");
            return;
        }
        //inc и dec с кодом регистра в опкоде-----------------------------------//
        if (S10.equals("01000") || S10.equals("01001")) {
            println(newNames.getProperty(S10) + directAddr8.getProperty(S1.substring(5, 8)) + " | O,S,Z,A,P,C");
            return;
        }

        //команды c непосредственным операндом------------------------------------//
        //---------------mod=null----------------//
        if (S11.equals("00000100") || S11.equals("00010100") || S11.equals("00101100") || S11.equals("00011100") || S11.equals("00111100")) {
            println(newNames.getProperty(S11) + directAddr8.getProperty("000") + "," + toHexString(parseInt(S1.substring(9, 17), 2)) + " | O,S,Z,A,P,C");
            return;
        }
        
        if (S11.equals("00000101") || S11.equals("00010101") || S11.equals("00101101") || S11.equals("00011101") || S11.equals("00111101")) {
            println(newNames.getProperty(S11) + directAddr16.getProperty("000") + "," + toHexString(parseInt(S1.substring(9, 17), 2)) + toHexString(parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
            return;
        }
        //---------------mod=11----------------//
        if (md.equals("11")) {//проверка mod
            //команды c непосредственным операндом------------------------------------//
            if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111")) {
                println(newNames.getProperty(S21) + directAddr8.getProperty(S1.substring(14, 17)) + "," + toHexString(parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
                return;
            }

            if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
                println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + "," + toHexString(parseInt(S1.substring(18, 26), 2)) + toHexString(parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
                return;
            }

            if (S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
                println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + "," + toHexString(parseInt(S1.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
                return;
            }
            //-----------------команды reg,r/m-----------------------------------------------------//
            if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010") || S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
                println(newNames.getProperty(S11) + directAddr8.getProperty(S1.substring(11, 14)) + ", " + directAddr8.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                return;
            }
            if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111011") || S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
                println(newNames.getProperty(S11) + directAddr16.getProperty(S1.substring(11, 14)) + ", " + directAddr16.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                return;
            }
            //-----------------команды r/m-----------------------------------------------------//
            if (S21.equals("11110110110") || S21.equals("11110110111") || S21.equals("11110110011") || S21.equals("11110110100") || S21.equals("11110110101") || S21.equals("11111110000") || S21.equals("11111110001")) {
                println(newNames.getProperty(S21) + directAddr8.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                return;
            }
            if (S21.equals("11110111110") || S21.equals("11110111111") || S21.equals("11110111011") || S21.equals("11110111100") || S21.equals("11110111101") || S21.equals("11111111000") || S21.equals("11111111001")) {
                println(newNames.getProperty(S21) + directAddr16.getProperty(S1.substring(14, 17)) + " | O,S,Z,A,P,C");
                return;
            }
        }

        //---------------mod=01----------------//
        if (md.equals("01")) {//проверка mod
            //команды c непосредственным операндом------------------------------------//
            if (S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111") || S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111")) {
                println(newNames.getProperty(S21) + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "], " + toHexString(parseInt(S1.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
                return;
            }
            if (S21.equals("10000001000") || S21.equals("10000001010") || S21.equals("10000001101") || S21.equals("10000001011") || S21.equals("10000001111")) {
                println(newNames.getProperty(S21) + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "], " + toHexString(parseInt(S1.substring(27, 35), 2)) + toHexString(parseInt(S1.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
                return;
            }
            //-----------------команды reg,r/m-----------------------------------------------------//
            if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
                println(newNames.getProperty(S11) + directAddr8.getProperty(S1.substring(11, 14)) + ", " + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
                return;
            }
            if (S11.equals("00000010") || S11.equals("00010010") || S11.equals("00101010") || S11.equals("00011010") || S11.equals("00111010")) {
                println(newNames.getProperty(S11) + directAddr16.getProperty(S1.substring(11, 14)) + ", " + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
                return;
            }
            //-----------------команды r/m,reg-----------------------------------------------------//
            if (S11.equals("00000000") || S11.equals("00010000") || S11.equals("00101000") || S11.equals("00011000") || S11.equals("00111000")) {
                println(newNames.getProperty(S11) + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "]" + ", " + directAddr8.getProperty(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
                return;
            }
            if (S11.equals("00000001") || S11.equals("00010001") || S11.equals("00101001") || S11.equals("00011001") || S11.equals("00111001")) {
                println(newNames.getProperty(S11) + linkedAddr.getProperty(S1.substring(14, 17)) + toHexString(parseInt(S1.substring(18, 26), 2)) + "]" + ", " + directAddr16.getProperty(S1.substring(11, 14)) + " | O,S,Z,A,P,C");
                return;
            }
        }

    }

    public static void main(String[] args) {
        new SPO_1().run();
    }
}

...
Рейтинг: 0 / 0
01.04.2016, 14:47
    #39206091
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Как-то так

Код: java
1.
2.
3.
4.
5.
    if (!( matchTo(S11,"1001100*") || matchTo(S10,"0100*"))) {
            md = S1.substring(9, 11);//mod
            rm = S1.substring(14, 17);
            S21 += S1.substring(11, 14);
    }



или можно перевернуть по правилу Де-Моргана для читаемости.
...
Рейтинг: 0 / 0
01.04.2016, 14:54
    #39206107
lor2
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mayton,

код жесть. у меня глаза чуть не лопнули.
...
Рейтинг: 0 / 0
01.04.2016, 14:57
    #39206116
golovonometr
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
maytonКак-то так

Код: java
1.
2.
3.
4.
5.
    if (!( matchTo(S11,"1001100*") || matchTo(S10,"0100*"))) {
            md = S1.substring(9, 11);//mod
            rm = S1.substring(14, 17);
            S21 += S1.substring(11, 14);
    }



или можно перевернуть по правилу Де-Моргана для читаемости.

но если честно, тоже не оч, тогда уж лучше в числа перегнать и сравнивать, чем писать такое:

Код: java
1.
(S21.equals("10000000000") || S21.equals("10000000010") || S21.equals("10000000101") || S21.equals("10000000011") || S21.equals("10000000111") || S21.equals("10000010000") || S21.equals("10000010010") || S21.equals("10000010101") || S21.equals("10000010011") || S21.equals("10000010111"))
...
Рейтинг: 0 / 0
01.04.2016, 17:13
    #39206244
Сергей Арсеньев
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
maytonДобавил функцию matchTo().

А через intern не проще?
...
Рейтинг: 0 / 0
01.04.2016, 17:28
    #39206256
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Сергей АрсеньевmaytonДобавил функцию matchTo().

А через intern не проще?
Поясни.
...
Рейтинг: 0 / 0
01.04.2016, 17:32
    #39206258
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
golovonometrно если честно, тоже не оч, тогда уж лучше в числа перегнать и сравнивать, чем писать такое:

Я не против. Но автор выбрал в качестве базиса для своего алгоритма строки. И если
переходить к целым числам то надо кое-чего переписать на битовые операции.
Если честно мне лень. А для дизассемблирования (если я правильно понял) тут вопрос перформанса или
компактности вообще не стоит.
...
Рейтинг: 0 / 0
01.04.2016, 19:29
    #39206348
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mayton,

Так препод ещё хочет, чтобы все преобразования выполнялись над битовым кодом.
Я бы не проч не использовать тонны if, но пока не знаю, как можно адекватно сделать.
Вот самый оптимальный вариант, это сделать через ассоциативные массивы(если это возможно), но вместо значения что-то, что вызовет метод для определенного опкода.
Даже и близко не представляю, как это сделать и возможно ли. На яве последний раз кодил года полтора назад, всё остальное время работали только с ассемблерами под разные платформы, а тут вдруг раз...
Всем огромное спасибо за помощь!
...
Рейтинг: 0 / 0
01.04.2016, 19:35
    #39206353
вадя
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
авторВот самый оптимальный вариант, это сделать через ассоциативные массивы(если это возможно), но вместо значения что-то, что вызовет метод для определенного опкода.
сделай массив
код/имя метода
по имени метода через рефлексию вызвать метод
...
Рейтинг: 0 / 0
02.04.2016, 00:44
    #39206503
chabapok
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
1. Загоните ваш ascii в байты и работайте с байтами. Так проще и логичней.
2. Используйте оо-подход.
Сделайте интерфейс
ICategoryDetector{
int tryDisasembleIfMy(buf[], int i);
}

и к нему кучу реализаций. Каждая реализация смотрит в нужные биты, и если видит, что команда по buf[i] ее, то она дизасемблирует и печатает ее, и возвращает индекс следующей команды. А если нее ее, то возвращает -1.

и дальше циклически вызывать.

А еще можно дальше пойти, завести аннотациию MatchMask("***110***1*") и ставить ее над методом. А уже метод смотрит в остальные биты и в буфер и решает какие там регистры участвуют и какие параметры. Этот метод вызывается, если байты по текущему индексу удовлетворяют маске. Но это более сложный способ(и все равно не самый лучший), вы скорей всего не сможете сделать его движок
...
Рейтинг: 0 / 0
02.04.2016, 18:28
    #39206690
DoSOfRedRiver
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
вадя,

Ссылки на методы есть. Нафига рефлекшн?
...
Рейтинг: 0 / 0
02.04.2016, 18:36
    #39206692
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
DoSOfRedRiver,

А можно подробней про ссылки и как их использовать? :3
...
Рейтинг: 0 / 0
02.04.2016, 18:36
    #39206693
вадя
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
DoSOfRedRiverвадя,

Ссылки на методы есть. Нафига рефлекшн?
запуск метода по ссылке?
...
Рейтинг: 0 / 0
02.04.2016, 21:54
    #39206721
DoSOfRedRiver
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mycodeurnghtmr,

Даже не ссылки, а что-то такое http://stackoverflow.com/questions/4480334/how-to-call-a-method-stored-in-a-hashmap-java
...
Рейтинг: 0 / 0
02.04.2016, 22:43
    #39206732
вадя
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
DoSOfRedRivermycodeurnghtmr,

Даже не ссылки, а что-то такое http://stackoverflow.com/questions/4480334/how-to-call-a-method-stored-in-a-hashmap-java
интересно, а как с параметрами запускать?
рефлекция только более универсальна.
...
Рейтинг: 0 / 0
02.04.2016, 23:19
    #39206744
rema174
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
вадяDoSOfRedRivermycodeurnghtmr,

Даже не ссылки, а что-то такое http://stackoverflow.com/questions/4480334/how-to-call-a-method-stored-in-a-hashmap-java
интересно, а как с параметрами запускать?

так в runCommand(); передавай параметры
...
Рейтинг: 0 / 0
03.04.2016, 22:49
    #39207013
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Всё, что смог из себя выдавить. :3
Код: java
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.
package spo_1ref;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SPO_1ref {

    public String buf = null;
    private final Properties newNames = new Properties();
    private final Properties directAddr8 = new Properties();
    private final Properties directAddr16 = new Properties();
    private final Properties linkedAddr = new Properties();

    public SPO_1ref() {
        initProps();
    }

    private void initProps() {
        //грузим настройки из файлов
        InputStreamReader propsReader = null;
        try {
            propsReader = new InputStreamReader(new FileInputStream("c:/test/newNames.txt"), "windows-1251"); // или "UTF-8"
            newNames.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr8.txt"), "windows-1251"); // или "UTF-8"
            directAddr8.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/directAddr16.txt"), "windows-1251"); // или "UTF-8"
            directAddr16.load(propsReader);
            propsReader = new InputStreamReader(new FileInputStream("c:/test/linkedAddr.txt"), "windows-1251"); // или "UTF-8"
            linkedAddr.load(propsReader);

        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                propsReader.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    //---------------------методы обработки-----------------//
    public void one_b(String s) {//однобайтные
        System.out.println(newNames.getProperty(s) + " | O,S,Z,A,P,C");
    }

    public void one_b_() {//однобайтные с кодом регистра в опкоде

        String S = buf.substring(0, 5);
        System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(5, 8)) + " | O,S,Z,A,P,C");

    }

    public void one_b_op() {//с явным операндом
        Pattern p = Pattern.compile("^.*0$");
        String S = buf.substring(0, 8);
        Matcher m = p.matcher(S);
        boolean b = m.matches();
        if (b) {
            System.out.println(newNames.getProperty(S) + directAddr8.getProperty("000") + "," + Integer.toHexString(Integer.parseInt(buf.substring(9, 17), 2)) + " | O,S,Z,A,P,C");
        } else {
            System.out.println(newNames.getProperty(S) + directAddr16.getProperty("000") + "," + Integer.toHexString(Integer.parseInt(buf.substring(9, 17), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
        }
    }

    public void ext_op() { //с вторичным коп и явным операндом
        Pattern p = Pattern.compile("^.{7}0.*$");
        String S21 = buf.substring(0, 8);
        String md = buf.substring(9, 11);//mod 
        String rm = buf.substring(14, 17);//r/m
        S21 += buf.substring(11, 14);
        Matcher m = p.matcher(S21);
        boolean b = m.matches();

        if (b) {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S21) + directAddr8.getProperty(buf.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S21) + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
            }
        } else {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S21) + directAddr16.getProperty(buf.substring(14, 17)) + "," + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(36, 44), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(36, 44), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(45, 53), 2)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S21) + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + Integer.toHexString(Integer.parseInt(buf.substring(36, 44), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(45, 53), 2)) + " | O,S,Z,A,P,C");
            }
        }
    }

    public void reg_rm() {
        Pattern p = Pattern.compile("^.*0$");
        String S = buf.substring(0, 8);
        Matcher m = p.matcher(S);
        boolean b = m.matches();
        String md = buf.substring(9, 11);//mod 
        String rm = buf.substring(14, 17);//r/m
        if (b) {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(11, 14)) + ", " + directAddr8.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(11, 14)) + ", " + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(11, 14)) + ", " + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(11, 14)) + ", " + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "] " + " | O,S,Z,A,P,C");
            }
        } else {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S) + directAddr16.getProperty(buf.substring(11, 14)) + ", " + directAddr16.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S) + directAddr16.getProperty(buf.substring(11, 14)) + ", " + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S) + directAddr16.getProperty(buf.substring(11, 14)) + ", " + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S) + directAddr16.getProperty(buf.substring(11, 14)) + ", " + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "] " + " | O,S,Z,A,P,C");
            }
        }
    }

    public void rm_reg() {
        Pattern p = Pattern.compile("^.*0$");
        String S = buf.substring(0, 8);
        Matcher m = p.matcher(S);
        boolean b = m.matches();
        String md = buf.substring(9, 11);//mod 
        String rm = buf.substring(14, 17);//r/m
        if (b) {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S) + directAddr8.getProperty(buf.substring(11, 14)) + ", " + directAddr8.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "]" + ", " + directAddr8.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + ", " + directAddr8.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S) + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + directAddr8.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
        } else {
            if (md.equals("11")) {
                System.out.println(newNames.getProperty(S) + directAddr16.getProperty(buf.substring(11, 14)) + ", " + directAddr16.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("01")) {
                System.out.println(newNames.getProperty(S) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "]" + ", " + directAddr16.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("10")) {
                System.out.println(newNames.getProperty(S) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + ", " + directAddr16.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
            if (md.equals("00") && rm.equals("110")) {
                System.out.println(newNames.getProperty(S) + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "], " + directAddr16.getProperty(buf.substring(11, 14)) + " | O,S,Z,A,P,C");
            }
        }
    }

    public void r_m() {
        Pattern p = Pattern.compile("^.{7}0.*$");
        String S21 = buf.substring(0, 8);
        String md = buf.substring(9, 11);//mod 
        String rm = buf.substring(14, 17);//r/m
        S21 += buf.substring(11, 14);
        Matcher m = p.matcher(S21);
        boolean b = m.matches();

        if (md.equals("11")) {
            if (b) {
                System.out.println(newNames.getProperty(S21) + directAddr8.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            } else {
                System.out.println(newNames.getProperty(S21) + directAddr16.getProperty(buf.substring(14, 17)) + " | O,S,Z,A,P,C");
            }
        }
        if (md.equals("01")) {
            System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + "]" + " | O,S,Z,A,P,C");
        }
        if (md.equals("10")) {
            System.out.println(newNames.getProperty(S21) + linkedAddr.getProperty(buf.substring(14, 17)) + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + " | O,S,Z,A,P,C");
        }
        if (md.equals("00") && rm.equals("110")) {
            System.out.println(newNames.getProperty(S21) + "[" + Integer.toHexString(Integer.parseInt(buf.substring(18, 26), 2)) + Integer.toHexString(Integer.parseInt(buf.substring(27, 35), 2)) + "]" + " | O,S,Z,A,P,C");
        }

    }

    public void run() {

        Map<String, Runnable> NewNames = new TreeMap<>();
        //--------------------------add---------------------------------------------//
        NewNames.put("00000100", () -> one_b_op());//AX/AL,DATA
        NewNames.put("00000101", () -> one_b_op());//----------
        NewNames.put("10000000000", () -> ext_op());//R/M,DATA 1
        NewNames.put("10000001000", () -> ext_op());//
        NewNames.put("10000010000", () -> ext_op());//-------
        NewNames.put("00000010", () -> reg_rm());//REG,R/M
        NewNames.put("00000011", () -> reg_rm());//----------
        NewNames.put("00000000", () -> rm_reg());//R/M, REG
        NewNames.put("00000001", () -> rm_reg());//----------
//------------------------adc---------------------------------------
        NewNames.put("00010100", () -> one_b_op());
        NewNames.put("00010101", () -> one_b_op());
        NewNames.put("10000000010", () -> ext_op());//R/M,DATA 1
        NewNames.put("10000001010", () -> ext_op());//
        NewNames.put("10000010010", () -> ext_op());//-------
        NewNames.put("00010010", () -> reg_rm());//REG,R/M
        NewNames.put("00010011", () -> reg_rm());//----------
        NewNames.put("00010000", () -> rm_reg());//R/M, REG
        NewNames.put("00010001", () -> rm_reg());//----------
//---------------------------sub------------------------------------
        NewNames.put("00101100", () -> one_b_op());
        NewNames.put("00101101", () -> one_b_op());
        NewNames.put("10000000101", () -> ext_op());//R/M,DATA 1
        NewNames.put("10000001101", () -> ext_op());//
        NewNames.put("10000010101", () -> ext_op());//-------
        NewNames.put("00101010", () -> reg_rm());//REG,R/M
        NewNames.put("00101011", () -> reg_rm());//----------
        NewNames.put("00101000", () -> rm_reg());//R/M, REG
        NewNames.put("00101001", () -> rm_reg());//----------

//--------------------------sbb-------------------------------------
        NewNames.put("00011100", () -> one_b_op());
        NewNames.put("00011101", () -> one_b_op());
        NewNames.put("10000000011", () -> ext_op());//R/M,DATA 1
        NewNames.put("10000001011", () -> ext_op());//
        NewNames.put("10000010011", () -> ext_op());//-------
        NewNames.put("00011010", () -> reg_rm());//REG,R/M
        NewNames.put("00011011", () -> reg_rm());//----------
        NewNames.put("00011000", () -> rm_reg());//R/M, REG
        NewNames.put("00011001", () -> rm_reg());//----------
//-----------------------------cmp----------------------------------
        NewNames.put("00111100", () -> one_b_op());
        NewNames.put("00111101", () -> one_b_op());
        NewNames.put("10000000111", () -> ext_op());//R/M,DATA 1
        NewNames.put("10000001111", () -> ext_op());//
        NewNames.put("10000010111", () -> ext_op());//-------
        NewNames.put("00111010", () -> reg_rm());//REG,R/M
        NewNames.put("00111011", () -> reg_rm());//----------
        NewNames.put("00111000", () -> rm_reg());//R/M, REG
        NewNames.put("00111001", () -> rm_reg());//----------
//---------div-idiv-neg-mul-imul-inc-dec------------------------------------------------
        NewNames.put("11110110110", () -> r_m());//R/M
        NewNames.put("11110111110", () -> r_m());//R/M
        NewNames.put("11110110111", () -> r_m());//R/M
        NewNames.put("11110111111", () -> r_m());//R/M
        NewNames.put("11110110011", () -> r_m());//R/M
        NewNames.put("11110111011", () -> r_m());//R/M
        NewNames.put("11110110100", () -> r_m());//R/M
        NewNames.put("11110111100", () -> r_m());//R/M
        NewNames.put("11110110110", () -> r_m());//R/M
        NewNames.put("11110111101", () -> r_m());//R/M
        NewNames.put("11111110000", () -> r_m());//R/M
        NewNames.put("11111111000", () -> r_m());//R/M
        NewNames.put("11111110001", () -> r_m());//R/M
        NewNames.put("11111111001", () -> r_m());//R/M
//--------------------------------------------------------------

        NewNames.put("10011000", () -> one_b("10011000"));//cbw
        NewNames.put("10011001", () -> one_b("10011001"));//cwd
        NewNames.put("01000", () -> one_b_()); //inc
        NewNames.put("01001", () -> one_b_()); //dec
        //---------------------------------------------------------//

        ArrayList<String> s1 = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader("C:\\test\\code.txt"))) {

            String s;
            while ((s = br.readLine()) != null) {

                s1.add(s);
            }
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }

        //-------------------------------------------------------------
        //   String S = null;
        Pattern p = Pattern.compile("^1(111|000).*$");
        for (int i = 0; i < s1.size(); i++) {
            this.buf = s1.get(i);
            String S = buf.substring(0, 8);
            Matcher m = p.matcher(S);
            boolean b = m.matches();
            if (b) {
                S += buf.substring(11, 14);
            }
            System.out.println(S);
            NewNames.get(S).run();
        }
    }

    public static void main(String[] args) {
        new SPO_1ref().run();
    }
}
...
Рейтинг: 0 / 0
03.04.2016, 23:16
    #39207025
mayton
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Ты в одном месте ссылки на функции толкаешь что как-бе выдает опытного
кодера "восьмерки" а в другом - как глупый индус элементарный
рефакторинг не сделал. Просто замени System.out.println на println
и суб-стриговые операции черезе introduce temporary variable
например S1.substring(14, 17) => S1_14_17 и твой код визуально
просто схлопнется. Функции Integer.toHex через статик импорт тоже.

Ну нельзяж так ну йомайо.
...
Рейтинг: 0 / 0
04.04.2016, 00:15
    #39207036
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mayton,

я, кстати, даже не знал про это.
так что огромное спасибо. :3
всем спасибо.
замечательный форум.
...
Рейтинг: 0 / 0
04.04.2016, 18:38
    #39207820
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Пошел я значит опять к преподше...
В общем, теперь хочется ей, чтобы все операции дизассемблирования проводились строго над битами и никак иначе, ни байтов, ни строк в ASCII кодах.
Можно ли как-то переделать? Или придётся всё заново писать?
Ещё раз спасибо всем.
...
Рейтинг: 0 / 0
06.04.2016, 12:20
    #39209116
Сергей Арсеньев
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
mycodeurnghtmr,

На самом деле это даже еще проще. Определяешь маски, ну например
Код: java
1.
final static byte MASK_100 = (byte)0b00000100;


и далее
Код: java
1.
if ((S11 ^ MASK_100)==0)
...
Рейтинг: 0 / 0
06.04.2016, 13:19
    #39209202
mycodeurnghtmr
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Дизассемблер арифметических команд под x86
Сергей Арсеньев,

Да я через битсет сделал, будь он не ладен, надеюсь примет прогу и забуду как страшный сон. =3
Спасибо ещё раз всем.
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Дизассемблер арифметических команд под x86 / 25 сообщений из 25, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]