flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Check CPUID presence

Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 19 Dec 2018, 01:12
Hello, i have little question. To detect if CPUID if present, OsDev website recommend this code:

Code:
 pushfd                               ;Save EFLAGS
    pushfd                               ;Store EFLAGS
    xor dword [esp],0x00200000           ;Invert the ID bit in stored EFLAGS
    popfd                                ;Load stored EFLAGS (with ID bit inverted)
    pushfd                               ;Store EFLAGS again (ID bit may or may not be inverted)
    pop eax                              ;eax = modified EFLAGS (ID bit may or may not be inverted)
    xor eax,[esp]                        ;eax = whichever bits were changed
    popfd                                ;Restore original EFLAGS
    and eax,0x00200000                   ;eax = zero if ID bit can't be changed, else non-zero
    ret    


I understand all except AND instruction. Why use AND instruction set EAX to 0 when ID bit can't change ? If i understand good AND instruction, bit set to 1 only if all compared bits are value 1. But all eflag bits don't always have bits set to 1, no ?
Post 19 Dec 2018, 01:12
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 19 Dec 2018, 01:22
It is easier to understand in binary:
Code:
mov eax,10110011b
and eax,00100000b
; eax now is 00100000b
ret
    

Code:
mov eax,1111b
and eax,0010b
; eax now is 0010b
ret
    
Post 19 Dec 2018, 01:22
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 19 Dec 2018, 02:39
Oh yes ! It's very simple finally! Cool Why i don't have thinking that x)
Post 19 Dec 2018, 02:39
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.