2015-12-02 69 views
1

原代码产生以下输出:处理器供应商ID是“GenuineIntel” 赫雷什原来的代码:转换AT&T语法程序Intel语法

1.   .section .data 
2. output: 
3.   .ascii “The processor Vendor ID is ‘xxxxxxxxxxxx’\n” 
4.   .section .text 
5.   .globl _start 
6. _start: 
7.   movl $0, %eax 
8.   cpuid 
9.   movl $output, %edi 
11.  movl %ebx, 28(%edi) 
12.  movl %edx, 32(%edi) 
13.  movl %ecx, 36(%edi) 
14   movl $4, %eax 
15.  movl $1, %ebx 
16.  movl $output, %ecx 
17.  movl $42, %edx 
18.  int $0x80 
19.  movl $1, %eax 
20.  movl $0, %ebx 
21.  int $0x80 

我转化为英特尔执行,但不显示任何代码后在屏幕上输出组合:

1.  .intel_syntax noprefix 
2.   .section  .data 
3. output: 
4.   .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n" 
5.   .section .text 
6.   .globl _start 
7. _start: 
8.   mov  eax, 0 
9.   cpuid 
10.   mov  edi, OFFSET output 
11.   mov  [edi+28], ebx 
12.   mov  [edi+32], edx 
13.   mov  [edi+36], ecx 
14.   mov  eax, 4 
15.   mov  ebx, 1 
16.   mov  ecx, output 
17.   mov  edx, 42 
18.   int  0x80 
19.   mov  eax, 1 
20.   mov  ebx, 0 
21.   int  0x80 
+1

在哪里以及如何定义输出?您将第9行movl $ output,%edi转换为mov edi,OFFSET输出,但另一方面,您将第16行movl $ output,%ecx转换为mov ecx,output。只有一个选择是正确的,但没有定义,哪一个是不确定的。 – zx485

+0

nvm我刚添加OFFSET到第16行的intel代码。 – Yeezus

+0

只是注意到我忽略了'输出'被定义为一个标签。但另一件令我想知道的事情是:原始代码中的第10行在哪里?它从9直到11。是否缺少一条线? – zx485

回答

0

如果你没有在你的代码中的注释,您可以通过组装,然后拆卸中的其他语法做一个良好的开端。

如果有的话,它可能会或可能不会更容易/更不容易出错,然后移动评论。这样做可能不便于保存全局符号名称,但是一些反汇编程序可以使用符号表。

即使您决定手动执行该操作,也可以通过组装AT & T和NASM版本发现是否有任何错误。如果这些二进制文件反汇编成相同的代码,那么你很好。如果没有,你应该迅速找到他们不同的地方。