%macro scall 4
mov rax, %1
mov rdi, %2
mov rsi, %3
mov rdx, %4
syscall
%endmacro
section .data
msg db "The processor is in protected mode",10
msglen equ $-msg
msg1 db "The processor is in real mode",10
msg1len equ $-msg1
msg3 db 10,"Contents of GDTR: "
msg3len equ $-msg3
msg4 db 10,"Contents of IDTR: "
msg4len equ $-msg4
msg5 db 10,"Contents of LDTR: "
msg5len equ $-msg5
msg6 db 10,"Contents of the task register: "
msg6len equ $-msg6
msg7 db 10,"Contents of MSW: "
msg7len equ $-msg7
msg8 db 10,"------Exiting from the program!!-------"
msg8len equ $-msg8
msg9 db " : "
msg9len equ $-msg9
cnt2 db 04H
newline db 10
section .bss
msw:
resd 1
resw 1
g:
resd 1
resw 1
value resb 4
idtr:
resd 1
resw 1
ldtr:
resw 1
resw 1
tr resw 1
section .text
global _start
_start:
smsw [msw]
mov eax, dword[msw]
bt eax,0
jc next
scall 1,1,msg1,msg1len
jmp EXIT
next:
scall 1,1,msg,msglen
;------gtdr contents---------
scall 1,1,msg3,msg3len
sgdt[g]
mov bx,word[g+4] ;BASE
call conversion
mov bx,word[g+2] ;LIMIT
call conversion
mov bx,word[g]
scall 1,1,msg9,msg9len
call conversion
scall 1,1,newline,1
;-------IDTR contents----------
scall 1,1,msg4,msg4len
sidt[idtr]
mov bx, word[idtr+4] ;BASE
call conversion
mov bx, word[idtr+2] ;LIMIT
call conversion
mov bx, word[idtr]
scall 1,1,msg9,msg9len
call conversion
scall 1,1,newline,1
;---------LDTR contents---------
scall 1,1,msg5,msg5len
sldt[ldtr]
mov bx,word[g]
call conversion
scall 1,1,newline,1
;-------MSW contents----------
scall 1,1,msg7,msg7len
mov bx, word[msw+2]
call conversion
mov bx, word[msw]
call conversion
scall 1,1,newline,1
;---------TR contents---------
scall 1,1,msg6,msg6len
mov bx,word[tr]
call conversion
scall 1,1,newline,1
EXIT:
scall 1,1,msg8,msg8len
scall 1,1,newline,1
mov rax,60
mov rdi,0
syscall
;----------HEX to ASCII conversion-------------
conversion:
mov rdi,value
mov byte[cnt2],4H
aup:
rol bx,04
mov cl,bl
and cl,0fH
cmp cl,09H
jbe ANEXT
add cl,30H
ANEXT:
add cl,30H
mov byte[rdi],cl
inc rdi
dec byte[cnt2]
JNZ aup
scall 1,1,value,4
ret

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: