%macro scall 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro
section .data
msg db"Machine is in Protected mode",10
msglen equ $-msg
msg1 db"Machine is not in Protected mode"
msg1len equ $-msg1
msg2 db 10,"Contents of GDTR: "
msg2len equ $-msg2
msg3 db " : "
msg3len equ $-msg3
section .bss
msw resb 4
gdtr resb 6
result resb 6
section .text
global _start
_start:
smsw eax
bt eax,0
jc next
scall 1,1,msg1,msg1len
jmp exit
next:
scall 1,1,msg,msglen
mov esi,[gdtr]
sgdt [gdtr]
scall 1,1,msg2,msg2len
mov bx,word[gdtr+4] ;32 bits reserved for base
call conversion
mov bx,word[gdtr+2] ;16 bits reserved for limit
call conversion
scall 1,1,msg3,msg3len
mov bx,word[gdtr]
call conversion
exit:
scall 60,0,0,0
;Hex to Ascii code conversion method
conversion:
mov esi,result
mov cl,4
up:rol ax,4
mov dx,bx
and bx,0fh
cmp bl,09h
jbe skip
add bl,07h
skip:add bl, 30h ;for value betwwn 0 to 9
mov [esi],bl
inc esi
mov bx,dx
dec cl
jnz up ;jump not zero
scall 1,1,result,4
ret
To embed this project on your website, copy the following code and paste it into your website's HTML: