最新学习代码优化,看了很多反编译的汇编代码,意识到自己的汇编水平比较烂,重新学习下汇
编编程。各位看官看我第一个例子就知道我学习用的书是《Professional Assembly Language》。 这本
书通俗易懂,我很喜欢。
代码完全来自 Richard Blum大牛的book,(不知道算不算侵犯版权,我估计他不会和我这个对他无限
仰望的菜鸟计较。)
返回不同的信息。当eax中的值为0的时候,cpuid指令获取的是 Vendor ID。这条指令执行完毕后:
值,cpuid不能识别这条指令,无法返回信息
存入eax,然后调用cpuid,则不能识别。
-
(gdb) info reg
-
eax 0xb 11
-
ecx 0x6c65746e 1818588270
-
edx 0x49656e69 1231384169
-
ebx 0x756e6547 1970169159
-
esp 0xbffff7e0 0xbffff7e0
-
ebp 0x0 0x0
-
esi 0x0 0
-
edi 0x0 0
-
eip 0x804807c 0x804807c <_start+8>
-
eflags 0x200212 [ AF IF ID ]
-
cs 0x73 115
-
ss 0x7b 123
-
ds 0x7b 123
-
es 0x7b 123
-
fs 0x0 0
- gs 0x0 0
- as -o cpuid.o cpuid.s
- ld -o cpuid cpuid.o
- root@libin:~/program/assembly# ./cpuid
- the processor vendor ID is 'GenuineIntel'
main来代替。
即可生成debug版本的可执行程序。
- as -gstabs -o cpuid.o cpuid.s
- ld -o cpuid cpuid.o
-
# cpuid.s extract the the processor vendor ID
-
.section .data
-
output:
-
.ascii "the processor vendor ID is 'xxxxxxxxxxxx'\n"
-
-
.section .text
-
.global _start
-
_start:
-
nop
-
movl $0,%eax
-
cpuid
-
movl $output, %edi
-
movl %ebx,28(%edi)
-
movl %edx,32(%edi)
-
movl %ecx,36(%edi)
-
movl $4,%eax
-
movl $1,%ebx
-
movl $output,%ecx
-
movl $42,%edx
-
int $0x80
-
mov $1,%eax
-
mov $0,%ebx
- int $0x80