Printing to the screen

Programming, for all ages and all languages.
Post Reply
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

Printing to the screen

Post by chezzestix »

In real mode I cant fit 0xb8000 in a register... how can I work around that? Up until now I have always hard coded the address but Im trying to automate the printing of strings which would make hard coding no longer an option.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Printing to the screen

Post by 01000101 »

you need to use a segment:offset pair to access 0xB8000.
You could put 0xB800 in 'es' and use 'bx' as the x/y offset register.

so, if you want to print a green 'L' in the upper left,

Code: Select all

mov ax, 0xB800 ; cant access 'es' directly
mov es, ax       ; segment
mov bx, 0x0000 ; offset
mov ah, 0xA0 ; color
mov al, 'L'      ; char
mov word [es:bx], ax ; write to vidmem
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

Re: Printing to the screen

Post by chezzestix »

Okay and just to make sure I know whats going on here is the code correct for what this paragraph is perscribing?
Before enabling the A20 with any of the methods described below it better to test whether the A20 address line is already enabled by the BIOS. This can be achieved by comparing, at boot time in real mode, the bootsector identifier (0xAA55) located at address 0000:7DFE with the value 1 MiB higher which is at address FFFF:7E0E. When the two values are different it means that the A20 is already enabled...

Code: Select all

mov ax,0xFFFF
mov es,ax
mov ax,0xAA55
cmp ax,[es:0x7DFE]
jne skipA20 ;A20 is enabled
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Printing to the screen

Post by bewing »

Not quite. The 0xFFFF segment points 16 bytes BELOW the 1M mark. So you have to add 16 to your offset. So you need the 0x7E0E offset.

Code: Select all

xor ax, ax
mov ds, ax
dec ax ; set ax to 0xffff
mov es,ax
mov ax,0xAA55
cmp ax,[es:0x7E0E]
jne skipA20 ;A20 is enabled
; but maybe the two values just happened to be equal
not ax
mov [es:0x7E0E], ax
cmp ax, [ds:0x7DFE]
jne skipA20 ;A20 is enabled
Post Reply