Page 1 of 1
Speeding Up My ASM Loop
Posted: Wed Mar 15, 2006 12:00 am
by CoffeeAdict
Hey everyone im new here and i found alot of useful information so i decided to sign up and here goes my first post. I have just receantly started making my own BootLoaders in asm and testing the out in bochs and on an old system. Ive been following a tutorial and im making a loop which should loop as many times as cx holds. so heres my code:
Code: Select all
[BITS 16]
[ORG 0x7C00]
mov ah, 0Eh
mov bh, 0
mov bl, 07h
mov cx, 5
main:
mov al, 'X'
int 10h
loop main
times 510 - ($-$$) db 0
dw 0AA55h
As you can probably see my code should just display 5 'X's and it does but it takes a while to do so. Is there anyway i can speed up this loop. Thanks.
Re: Speeding Up My ASM Loop
Posted: Wed Mar 15, 2006 12:00 am
by Da_Maestro
Maybe by writing directly to video memory?
Code: Select all
[BITS 16]
[ORG 0x7C00]
mov al, 'X'
mov es, 0xB800
xor di, di
mov cx, 5
rep stosb
times 510 - ($-$$) db 0
dw 0xAA55
Re: Speeding Up My ASM Loop
Posted: Thu Mar 16, 2006 12:00 am
by smiddy
CoffeeAdict wrote:As you can probably see my code should just display 5 'X's and it does but it takes a while to do so. Is there anyway i can speed up this loop. Thanks.
What do you mean by slow? It would be helpful to know the particular setup that it is slow within and the specific timing you're considering slow. Slow as in it takes 1 second per iteration to display an X. Yes, that would be pretty slow, but is it running on an 8086 at 4.86 MHz? Are you using Bochs for this and what speed specifically is it displaying at? The open endedness of your question makes it difficult to understand which particular permutation of a setup you are calling slow. The code by it self seems good and ASM by itself is fast, though BIOS adds a certain amount of overhead if you intend on using it. BIOS does things like checks the refresh rate and doesn't display the X until it can safely and smoothly, with out retrace problems. Writting directly to video memory is a faster solution but you run the risk of added retrace issues that may be hard on one's eyes.
BTW, the code Da Maestro won't work entirely since video memory has two bytes per character and his solution only takes into account one for the character alone and not its attributes, so you may also want to look up the make up of video memory for text modes.
Re: Speeding Up My ASM Loop
Posted: Thu Mar 16, 2006 12:00 am
by CoffeeAdict
Im sorry I didnt explain my setup. By slowness i mean when i run my BootLoader in bochs it takes roughly about 1-2 seconds then all 5 'X's are displayed at the same time. Is it running slow because im using a BIOS emulator or would it run slow if i put it on a floppy and ran it once i reboot my computer.
Re: Speeding Up My ASM Loop
Posted: Thu Mar 16, 2006 12:00 am
by smiddy
CoffeeAdict wrote:Im sorry I didnt explain my setup. By slowness i mean when i run my BootLoader in bochs it takes roughly about 1-2 seconds then all 5 'X's are displayed at the same time. Is it running slow because im using a BIOS emulator or would it run slow if i put it on a floppy and ran it once i reboot my computer.
That is a great question! Yes Bochs has some quircks and needs to be tweeked in order for it to run to your liking. If you download BOS 0.04 and use it under Bochs it boots fast and runs really fast. On the otherhand, all of my own stuff seems to be very slow too. On a real computer however everything blazes along... I beleive part of it is timing of how code gets run too...
Both of the other examples of emulators run slowly too, Virtual PC and VMWare. But they are different in where they are slow.
Check the timing settings for Bochs and check it again. This may take a few times of fine tuning for it to work under your system setup.
Re: Speeding Up My ASM Loop
Posted: Thu Mar 16, 2006 12:00 am
by Da_Maestro
Check your VGA refresh setting and your CPU Mips setting