1. 程式人生 > >at&t 位測試(test)

at&t 位測試(test)

TEST 指令最常見的用途是檢查EFLAGES暫存器的標誌位

.section .data
output_cpuid:
      .asciz "This processor supports the CPUIDinstruction\n"
output_nocpuid:
      .asciz "This processor does not support the CPUID  instructiuon\n "
.section .text
.globl _start
_start:
     nop
     pushfl          #使用pushl指令把EFLAGS 暫存器的值儲存在到堆疊頂部
     popl %eax       #使用popl指令把EFLAGS 值讀取到EAX暫存器
     movl %eax,%edx  
     xor $0x00200000,%eax   #xor異或,相同的0,不同的為1
     pushl %eax  #把新的EAX壓入到堆疊中
     popfl    #POPFL指令把它儲存在EFLAGES中
     pushfl   
     popl %eax
     xor %edx ,%eax
     test $0x00200000,%eax
     jnz cpuid    #非零則跳轉
     pushl $output_nocpuid 
     call printf 
     add $4,%esp
     pushl $0
     call exit
cpuid:
      pushl $output_cpuid 
      call printf
      add $4,%esp
      pushl $0
      call exit

執行結果: