[Help]Using BIOS interrupt 10h using inline asm crashes

Posts 1–15 of 15 · Page 1 of 1
[Help]Using BIOS interrupt 10h using inline asm crashes
I tried making an alt. cls other than using

system("cls");

so i made this, but it crashes when it is supposed to clear the screen.

[php]
//lets make the asm section live dabid !!
#include <iostream>
using namespace std;

void clearScr()
{
__asm
{
MOV AH,6h
MOV AL,0
MOV BH,7
MOV CH,0
MOV CL,0
MOV DH,24
MOV DL,79
INT 10h
}
}

int main()
{
cout << "Press enter to clear the screen using a BIOS interrupt\n";
cin.get();

/*------------------------------------------------*/

clearScr(); //crashes D:

/*------------------------------------------------*/

return 0;
}[/php]
Could be totally wrong, but try making that a __declspec(naked) function
Quote Originally Posted by -Raz0r- View Post
Could be totally wrong, but try making that a __declspec(naked) function
Changing the function attribute to have no epilogue/prologue doesn't really change anything does it? Idk, I'm not too good at this.

Maybe you could try compiling in 16-bit?

I'm not really sure what it could be. |:
Neither, I just tried playing around but I can't get any int 0x10's to work o_O
I've only ever needed int 3 =D
Quote Originally Posted by -Raz0r- View Post
Neither, I just tried playing around but I can't get any int 0x10's to work o_O
I've only ever needed int 3 =D
I was able to use int 10 here: http://www.mpgh.net/forum/34-assembl...-assembly.html

But that was all done in assembly and assembling in 16bit wasn't a problem for me. |:

Idk what could be wrong with this. D:
daum /
Could i link a seperate .com and call it with C++?
Quote Originally Posted by Kallisti View Post
daum /
Could i link a seperate .com and call it with C++?
Why would you do that? If you want to create a COM file from C++ and assembly, compile them both in 16 bit and use a 16 bit linker to link them using the tiny model.
Quote Originally Posted by Void View Post
Why would you do that? If you want to create a COM file from C++ and assembly, compile them both in 16 bit and use a 16 bit linker to link them using the tiny model.
I mean make a COM from an ASM file

[php].i386
.model small
.stack
.data

.code
main proc
MOV AH,6h
MOV AL,0
MOV BH,7
MOV CH,0
MOV CL,0
MOV DH,24
MOV DL,79
INT 10h
main endp
end main[/php]

and call it from C++?
Wait isn't this being run in protected mode flat model? Doesn't protected mode have certain issues with certain interrupts. What I am saying could be irrelevant but I'm reading a book that mentioned something of that nature.

What assembler is that syntax for? Also what linker. MAYBE that could be messing with it?
Quote Originally Posted by hobosrock696 View Post
Wait isn't this being run in protected mode flat model? Doesn't protected mode have certain issues with certain interrupts. What I am saying could be irrelevant but I'm reading a book that mentioned something of that nature.

What assembler is that syntax for? Also what linker. MAYBE that could be messing with it?
Actually, I've used interrupt 10 in protected mode before. See here: http://www.mpgh.net/forum/34-assembl...-assembly.html

I eventually got it to work, but I didn't use inline assembly ( meaning I didn't use a C/C++ compiler ).
Ah... I miss BA. I don't program assembly so, and if I do it's 32 bit, so I have no idea what's going on.

I only think its curious that some of your numbers are in hex and the rest in decimal. That might be the problem but only a guess...
Quote Originally Posted by why06 View Post
Ah... I miss BA. I don't program assembly so, and if I do it's 32 bit, so I have no idea what's going on.

I only think its curious that some of your numbers are in hex and the rest in decimal. That might be the problem but only a guess...
I didn't notice that.

Patrick, if you want the assembler to assume those numbers as hex you have to use the suffix 'h' at the end. Otherwise it assumes them to be of base 10. If you want the assembler to see it as binary for any reason, use the 'b' suffix.
Hey void wait did you solve that last problem in the thread you linked by using the segmented model? I did a char by char program for dos with a certain char meaning next line and i thought i had to use segmented to gain control of the segment registers....

Also change your first two lines of asm to

mov ax, 600H

That will move 6 into ah and 0 into all in one swift move
also yea add the h at the end

MOV CH,0
MOV CL,0

change to

mov cx, 0h

and this
MOV DH,24
MOV DL,79

to

mov dx, 2479h

Thatl make for less and slightly faster code XD (as if it was slow before...)
Quote Originally Posted by hobosrock696 View Post
Hey void wait did you solve that last problem in the thread you linked by using the segmented model? I did a char by char program for dos with a certain char meaning next line and i thought i had to use segmented to gain control of the segment registers....

Also change your first two lines of asm to

mov ax, 600H

That will move 6 into ah and 0 into all in one swift move
also yea add the h at the end

MOV CH,0
MOV CL,0

change to

mov cx, 0h

and this
MOV DH,24
MOV DL,79

to

mov dx, 2479h

Thatl make for less and slightly faster code XD (as if it was slow before...)
Yeah, but my way is much easier to follow. I'm not a super pro at asm \:
Thats true but in that case comment your lines

The rule for assembly is MINIMUM 1 comment per line but good practice is a comment per line plus a comment per block of code.

Yeah and from what I have read that code should work perfectly... Please post back if you fix it. I would like to know whats wrong here. Personally I would write a function that doesn't use a call. If you want such a function I have written some code that does exactly that but you might have to modify it slightly to clear the screen I'd be happy to share as soon as I can get my assembly off of my dos machine which will be when I get my pc with a floppy drive running so I will have a way of transferring my code.
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us