简体   繁体   中英

How to print strings using bios interrupts

I am working on an assigment on creating an operating system using some assembly functions and 16 bit C compiler. My task is to print strings on screen using 0x10 interrupt. Since interrupts can be called in assembly file, I have been provided with an assembly file which contains a function called interrupt which takes five arguments : the interrupt number, and the interrupt parameters passed in the AX , BX , CX , and DX . For example, to print 'Q' with the provided function, I need to write like this:

char al = 'Q'
char ah = 0xE
int ax = ah*256+al;
interrupt(0x10,ax,0,0,0);

OR, simply:

interrupt(0x10,0xE*256+'Q',0,0,0);

in a C program called kernel.c

My task is to write a function printString(char *chars) in C which takes a string and prints it on screen using the discussed assembly function.

I have done it this way:

void printString(char * chars){
int i = 0; 
int l = length(chars);
 for(; i < l; i++){
   interrupt(0x10,0xE*256+chars[i],0,0,0);
 }
}

but it prints the string multiple times instead of printing one time. when I try to print "Hello World", it's printed 11 times, because it contains 11 characters, same is the case with other strings.

I think you need to look for a null character to terminate the read. I've noticed the assembly file does some weird stuff with the character buffers too. I even had multiple characters print when I called the interrupt function directly from main().

Adding the line: while(1); keeps main() from returning. The boot loader executing multiple instances of main() is what causes the repeated output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM