OneCompiler

Assignment no:6

140

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