Assignment 6
section .data
introMsg dw "ALP to detect the operating mode of the microprocessor and display
the contents of some system registers"
introMsgLen equ - gdtrMsg
ldtrMsg db 10,10,"Contents of LDTR : ",10
ldtrMsgLen equ - idtrMsg
trMsg db 10,10,"Contents of TR : ",10
trMsgLen equ - mswMsg
protectedMsg db 10,10,"The Microprocessor is in the protected mode"
protectedMsgLen equ - proMsg
realMsg db 10,10,"The Microprocessor is in the real mode"
realMsgLen equ - newline
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
resw 1
tr resw 1
msw resd 1
result resb 4
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
print introMsg,introMsgLen
smsw eax
bt eax,0 ; copy the 0th least significant bit from EAX to
;the carry flag.
jc protected_mode ;if CF is set ,processor is in protected mode
print realMsg,realMsgLen
jmp exit1
protected_mode :
print protectedMsg , protectedMsgLen
print proMsg , proMsgLen
sgdt [gdtr]
sldt [ldtr]
str [tr]
smsw [msw]
print gdtrMsg,gdtrMsgLen
mov bx,[gdtr+4] ;move upper half of gdtr in bx reg.
call disp
mov bx,[gdtr+2]
call disp
print colon , colonLen
mov bx,[gdtr]
call disp
print ldtrMsg,ldtrMsgLen
mov bx,[ldtr]
call disp
print idtrMsg,idtrMsgLen
mov bx,[idtr+4]
call disp
mov bx,[idtr+2]
call disp
print colon , colonLen
mov bx,[idtr]
call disp
print trMsg,trMsgLen
mov bx,[tr]
call disp
print mswMsg,mswMsgLen
mov bx,[msw+2] ;upper half of CR0 or MSW
call disp
mov bx,[msw]
call disp
exit1:
print newline, newlineLen
mov rax, 60
mov rdi, 0
syscall
disp: ;ASCII conversion function
mov rdi, result
mov cx,04
up1:
rol bl,04
mov dl,bl
and dl,0fh
cmp dl,09h
jg add_37 ;if greater than 39h skip add 37
add dl,30h
jmp skip1 ;else add 30
add_37:
add dl,37h
skip1:
mov [rdi],dl
inc rdi
dec cx
jnz up1
print result , 4
ret