OneCompiler

assignment -6

95

;This program first check the mode of processor (Real or Protected),then reads GDTR, IDTR, LDTR, TR,
MSW and displays the same.

section .data
introMsg dw "ALP to detect the operating mode of the microprocessor and display the contents of some
system registers"
introMsgLen equ introMsggdtrMsgdb10,10,"ContentsofGDTR:",10gdtrMsgLenequ- introMsg gdtrMsg db 10,10,"Contents of GDTR : ",10 gdtrMsgLen equ - gdtrMsg
ldtrMsg db 10,10,"Contents of LDTR : ",10
ldtrMsgLen equ ldtrMsgidtrMsgdb10,10,"ContentsofIDTR:",10idtrMsgLenequ- ldtrMsg idtrMsg db 10,10,"Contents of IDTR : ",10 idtrMsgLen equ - idtrMsg
trMsg db 10,10,"Contents of TR : ",10
trMsgLen equ $ - trMsg

mswMsg db 10,10,"Contents of MSW (CR0) register : ",10
mswMsgLen equ mswMsgprotectedMsgdb10,10,"TheMicroprocessorisintheprotectedmode"protectedMsgLenequ- mswMsg protectedMsg db 10,10,"The Microprocessor is in the protected mode" protectedMsgLen equ - protectedMsg
proMsg db 10,10,"The contents of the system registers are as follows : "
proMsgLen equ proMsgrealMsgdb10,10,"TheMicroprocessorisintherealmode"realMsgLenequ- proMsg realMsg db 10,10,"The Microprocessor is in the real mode" realMsgLen equ - realMsg
colon db &"" : "

colonLen equ $ - colon
section .bss
gdtr resd 1 ;to store 48-bit GDTR value-resd(32-bit) and resw(16-bit).
resw 1
ldtr resw 1 ;to store 16-bit LDTR
idtr resd 1 ;to store 48-bit LDTR value-resd(32-bit) and resw(16-bit).
resw 1
tr resw 1
msw resd 1
result resb 4
%macro write 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
write introMsg,introMsgLen
smsw eax ; This instruction is used to store the contents of the MSW register into the EAX register.
bt eax,0 ; copy the 0 th least significant bit from EAX to the carry flag.
jc protected_mode ;if CF is set ,processor is in protected mode

write realMsg,realMsgLen
jmp endOfProgram
protected_mode :
write protectedMsg , protectedMsgLen
write proMsg , proMsgLen
sgdt [gdtr] ; Stores the content of the global descriptor table register (GDTR) in the destination
operand gdtr
sldt [ldtr] ;store LDTR
str [tr]
smsw [msw]
write gdtrMsg,gdtrMsgLen
mov bx,[gdtr+4] ;move upper half of gdtr in bx reg.
call disp
mov bx,[gdtr+2]
call disp
write colon , colonLen
mov bx,[gdtr]
call disp
write ldtrMsg,ldtrMsgLen
mov bx,[ldtr]
call disp
write idtrMsg,idtrMsgLen
mov bx,[idtr+4]
call disp
mov bx,[idtr+2]
call disp
write colon , colonLen
mov bx,[idtr]
call disp
write trMsg,trMsgLen
mov bx,[tr]
call disp
write mswMsg,mswMsgLen
mov bx,[msw+2] ;upper half of CR0 or MSW
call disp
mov bx,[msw]
call disp