Speeding up ASM loop

Recommended Posts

Hey everyone Ive been making my own BootLoaders for a simple OS im creating and Im trying to loop a piece of code:
[BITS 16]
[ORG 0x7C00]

mov ah, 0Eh
mov bh, 0
mov bl, 07h
mov cx, 5             ;How Many Times To Loop

main:                 ;Start Main Loop
mov al, 'X'           ;Puts The Letter X Into al
int 10h               ;Present
loop main             ;Loop Back To Beginning

times 510 - (\$-$$) db 0 dw 0AA55h So as you can see from my code the loop loops 5 times and then stops. This is exactly what i want but it seems to be very slow at doing so. Any help on speeding up my simple loop would be great. Thanks. Share this post Link to post Share on other sites #1 "main" is not a good choice for a lable as it's too easily confused with the generic C program launch function, ie. int main(int argc, char *argv[]) #2 try "unrolling" the loop - that is, simply repeat the contents once for each loop - in this case 5 times mov al, 'X' ;Puts The Letter X Into al int 10h ;Present mov al, 'X' ;Puts The Letter X Into al int 10h ;Present mov al, 'X' ;Puts The Letter X Into al int 10h ;Present mov al, 'X' ;Puts The Letter X Into al int 10h ;Present mov al, 'X' ;Puts The Letter X Into al int 10h ;Present The slowness is more likely due to the interupt invocation rather than the loop. Share this post Link to post Share on other sites The BIOS interrupt routines are quite slow, if you need more speed you could look into I/O port programming. That will give you direct access to the hardware. It's been a long time since I've done any ASM, but basically you use the 'in' and 'out' instructions to address the hardware ports and write values to them sequentially. I found this pdf which contains a nice listing of all hardware ports to play with. Good luck. Share this post Link to post Share on other sites OK thanx for pointing out the main label thing lessBread ill change that. Also thanks for that link prototype ill check it out. thanks guys Share this post Link to post Share on other sites Well, it's been a long time since I did ASM programming however I do know that to write to the screen it starts at B800:0000 so [BITS 16] [ORG 0x7C00] mov bx, 0B800h ;This will be start of video location ;Note that graphics mode use A000:0000 ;When in graphics mode mov es, bx xor di, di ;You may need to swap around if you get a ;weird color with a strange character mov ah, 0Eh ;This should give Yellow on black mov al, 'X' ;Puts The Letter X Into al mov cx, 5 ;How Many repeats rep stosw ;Fill the memory at ES:DI times 510 - (-$$) db 0
dw 0AA55h

Try that and let me know how you get on :)

Share this post

Share on other sites
Thanks for that sniplet Adam that code does work but it still takes a while to run like my old code. Also does anyone now anywhere i can get tutorials about OS Development.

Share this post

Share on other sites
I have created a simple kernal in c and a piece of asm which starts my kernal. Ive compiled my asm file into an object file called ks.o and my c file into kernal.o and I now need a way of linking these to files into one called kernal.bin. Ive seen that people are using ld to link files but when i try using it I need a script. Does anyone know where i can get a script for ld to link my object files into one *.bin file. Thanks.

Share this post

Share on other sites
Quote:
 Original post by cNoobI have created a simple kernal in c and a piece of asm which starts my kernal. Ive compiled my asm file into an object file called ks.o and my c file into kernal.o and I now need a way of linking these to files into one called kernal.bin. Ive seen that people are using ld to link files but when i try using it I need a script. Does anyone know where i can get a script for ld to link my object files into one *.bin file. Thanks.

All I remember is that you link using ld only with an extension, can't remember which just read the man file (or help doc) to find what to add. You link using a format and make sure you can load them, some format has headers that you must read or skip. The easiest way would be to link to a "raw" format.

You could use a config file but its not necessary and if you decide to make one you should make it yourself or tweak one that you find in the build scripts you can find on other free and open source [simple] OS.

Share this post

Share on other sites
How do you mean it runs very slowly?

You should have those X's displayed immediately. Try setting CX to 2000 so the whole screen gets filled with X's. They should fill the screen in a blink of an eye.

Share this post

Share on other sites
Quote:
 Original post by cNoob... Also does anyone now anywhere i can get tutorials about OS Development.

Try this site: Bona Fide OS development

And this one too: OS-FAQ Wiki

Share this post

Share on other sites
Ok thanks for the help guys ive now relized that my loop was running slow because i am running my boot loader in bochs which is an emulator and is slower than the real bios. Ive tried my code on my tet PC and its all running as fast as i need it to. Thanks guys.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

• Forum Statistics

• Total Topics
628275
• Total Posts
2981740

• 10
• 11
• 17
• 10
• 9
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.20787951350212097, "perplexity": 3727.991707394557}, "config": {"markdown_headings": false, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-47/segments/1510934803848.60/warc/CC-MAIN-20171117170336-20171117190336-00076.warc.gz"}