Last active
December 9, 2018 01:15
-
-
Save ljmccarthy/fe86df40e2ce82798421635eb76b9d49 to your computer and use it in GitHub Desktop.
Detect 32-bit processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format MZ | |
entry main:start | |
use16 | |
segment main | |
start: | |
call detect_i386 | |
mov dx, strings.error | |
jnc .print | |
mov dx, strings.ok | |
.print: | |
mov ax, strings | |
mov ds, ax | |
mov ah, 0x09 | |
int 0x21 | |
mov ax, 0x4c00 | |
int 0x21 | |
detect_i386: | |
pushf ; save FLAGS | |
; clear FLAGS register | |
xor cx, cx | |
push cx | |
popf | |
pushf | |
pop cx | |
; test if top 2 bits (NT, reserved) are set | |
test cx, 0xc000 | |
jnz .false | |
; set NT and IOPL flags | |
mov cx, 0x7000 | |
push cx | |
popf | |
pushf | |
pop cx | |
; test if NT and IOPL are still set | |
test ch, 0x70 | |
jz .false | |
popf | |
stc | |
ret | |
.false: | |
popf | |
clc | |
ret | |
segment strings | |
.ok: | |
db "OK!$" | |
.error: | |
db "This program requires a i386-class or newer 32-bit processor.$" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment