【发布时间】:2015-12-02 09:13:35
【问题描述】:
原始代码产生以下输出:处理器供应商 ID 是“GenuineIntel” 这是原始代码:
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
【问题讨论】:
-
output在哪里以及如何定义?您将第 9 行movl $output, %edi转换为mov edi, OFFSET output,但另一方面,您将第 16 行movl $output, %ecx转换为mov ecx, output。只有一个选择是正确的,但没有定义就无法确定哪一个。 -
nvm 我刚刚在英特尔代码的第 16 行添加了 OFFSET。
-
刚刚注意到我忽略了“输出”被定义为标签。但让我想知道的另一件事是:原始代码中的第 10 行在哪里?从 9 点直接到 11 点。有没有漏掉一行?
-
在这里与
mov ecx, OFFSET output合作。 -
原谅我的语义错误我已经被这个程序卡住了很长一段时间,所以我并没有真正注意我的编号,没有任何代码行丢失......