printting on the screen in 16-bit real mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Locked
cfny1234
Posts: 7
Joined: Fri Jun 21, 2013 3:46 am

printting on the screen in 16-bit real mode

Post by cfny1234 »

I've been printting some text on screen successfully by using BIOS int 0x10,
and now I'm following the tutorial (wiki.osdev.org/Babystep4) to print something on the screen in real mode by editing the video memory at (0xb8000), but it seems not working for me.
Here is my code:

Code: Select all

[org 0x7c00]

start:
	mov ax, 0xb800
	mov es, ax
	xor di, di
	mov al, 'X'
	mov ah, 0xf
	stosw    ; I've also tried mov [es:si], ax
	
	jmp $
	
times 510-($-$$) db 0
dw 0xaa55
there is nothing printted out on the screen. And then I tried to read the value in address (0xb8000), it always give me zeros, seems I cannot write to that address correctly....
can anyone help please?
thanks!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: printting on the screen in 16-bit real mode

Post by Combuster »

The code looks fine although es:si isn't the same as es:di. Some emulators are somewhat picky with instruction counts between video writes and rendering them.

Which emulator are you using?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
cfny1234
Posts: 7
Joined: Fri Jun 21, 2013 3:46 am

Re: printting on the screen in 16-bit real mode

Post by cfny1234 »

thanks for replies.
although es:si isn't the same as es:di
and thanks for correction. I think that is only a typing mistake.


I'm using nasm to build the code, and bochs for testing
Something wrong with bochs??

thanks!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: printting on the screen in 16-bit real mode

Post by Combuster »

Emulators have optimisations that are designed to not redraw the entire screen when individual pixels changes - that would be a waste of time. Rather, they typically have cases where updates are skipped even though they are necessary.

Two things:
- check if your version is the latest one
- if that's the case, try replacing the stosw with something like

Code: Select all

mov ecx, 0x100
cld
rep stosw
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: printting on the screen in 16-bit real mode

Post by iansjack »

If the code looks right but doesn't produce the expected results than an obvious possibility is that it isn't being run. Debuggers are great for checking that sort of error.

You could also always try a different emulator.
cfny1234
Posts: 7
Joined: Fri Jun 21, 2013 3:46 am

Re: printting on the screen in 16-bit real mode

Post by cfny1234 »

thanks for quick replies!
Two things:
- check if your version is the latest one
- if that's the case, try replacing the stosw with something like
Code:
mov ecx, 0x100
cld
rep stosw
1. Mine is the lastest version (2.6.2)
2. I've replaced stosw with the code you given, it still doesn't work for bochs

But then I tried VirtualBox instead, it worked magically
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: printting on the screen in 16-bit real mode

Post by AJ »

Hi,

Did you compile Bochs yourself? Has something gone wrong with the compilation? What BIOS/Video BIOS are you using?

There are loads of people using Bochs for this kind of basic code and it seems to be working, so the problem is likely to be something unusual about your setup [waits for the bug reports to start flooding in from others with the same issue....].

Cheers,
Adam
cfny1234
Posts: 7
Joined: Fri Jun 21, 2013 3:46 am

Re: printting on the screen in 16-bit real mode

Post by cfny1234 »

Oops! I've made a stupid mistake!
Actually the code WORKS on bochs, but it change the very first charator on the bochs screen (where "Plex86/Bochs VGABios (PCI) 0.7a..........." locate), which is completely ignored by me......
I just thought that is some bochs message and not part of my VM's screen LOL
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: printting on the screen in 16-bit real mode

Post by AJ »

Locked to prevent ensuing flamefest...
Locked