%macro scall 4
mov rax,%1 ; func num for o/p data
mov rdi,%2 ; file descriptor ID for monitor
mov rsi,%3 ; starting address of string
mov rdx,%4 ; number of bytes to be displayed
syscall ; inbulit func
%endmacro
section .data ;initialized variable declaration
msg1 db "Machine is in Protected Mode"
msg1len equ $-msg1
msg2 db "Machine is in Real Mode"
msg2len equ $-msg2
msg3 db "Contents of GDTR : "
msg3len equ $-msg3
msg4 db " : "
msg4len equ $-msg4
msg5 db "Contents of LDTR : "
msg5len equ $-msg5
msg6 db "Contents of IDTR: "
msg6len equ $-msg6
msg7 db "Contents of TR: "
msg7len equ $-msg7
msg8 db "Contents of MSW/CR0: "
msg8len equ $-msg8
newline db 10
section .bss ;uninitialized variable declaration
var resb 4
gdtr resq 1
cnt2 resw 1
value resb 4
idtr resb 6
ldtr resw 1
tr resb 2
msw resb 4
section .text
global _start
_start:
smsw eax
mov[msw], eax
bt eax,0 ;bt copies bit from register to carry flag (instead of and and cmp)
;and eax,01h
;cmp eax,01h
;je protected
jc protected
scall 1,1,msg2,msg2len
protected:
scall 1,1,msg1,msg1len
scall 1,1,newline,10
SGDT [gdtr] ;Stores the contents of the global descriptor table register (GDTR) in the destination operand. The destination operand specifies a 8-byte memory location. In ;64-bit mode, the operand size is fixed at 8+2 bytes.The instruction stores an 8-byte base ;and a 2-byte limit
SIDT [idtr]
SLDT [ldtr]
STR [tr]
;GDTR
mov bx, word[gdtr + 4]
scall 1,1,msg3,msg3len
call HtoA
mov bx, word[gdtr + 2]
call HtoA
mov bx, word[gdtr]
scall 1,1,msg4,msg4len
call HtoA
scall 1,1,newline,10
;LDTR
scall 1,1,msg5,msg5len
mov bx,[ldtr]
call HtoA
scall 1,1,newline,10
;IDTR
mov bx, word[idtr + 4]
scall 1,1,msg6,msg6len
call HtoA
mov bx, word[idtr + 2]
call HtoA
mov bx, word[idtr]
scall 1,1,msg4,msg4len
call HtoA
scall 1,1,newline,10
;TR
scall 1,1,msg7,msg7len
mov bx,[tr]
call HtoA
scall 1,1,newline,10
;MSW/CR0
scall 1,1,msg8,msg8len
mov bx,[msw + 2]
call HtoA
mov bx,[msw]
call HtoA
mov rax,60
mov rdi,0
syscall
;----Procedure-----
HtoA:
mov rdi,value
mov byte[cnt2],4H
aup:
rol bx,04
mov cl,bl
and cl,0FH
cmp cl,09H
jbe next ;carry 1 is generated if our digit is 0-9, for that we just need to add 30H
add cl,07H
next:
add cl,30H
mov byte[rdi],cl
inc rdi
dec byte[cnt2]
jnz aup
scall 1,1,value,4
ret
To embed this project on your website, copy the following code and paste it into your website's HTML: