-
Calling an interrupt
First, I was unable to use interrupts using inline ASM and now I can't do so even in pure assembly linked in C!
I have written a function in ASM (just for testing purpose for now) that will print its own string using DOS 21h interrupt. Here's the code first:
Code:
%ifdef OBJ_TYPE
segment .data public align=4 class=data use32
%else
segment .data
%endif
message db "Hello", 0
message2 db "World", "$"
;
; code is put in the _TEXT segment
;
%ifdef OBJ_TYPE
segment text public align=1 class=code use32
%else
segment .text
%endif
global _print
;////////////////////////////////////////////////////////////////////////////////////////
;Function to print a string directly to the video memory
;////////////////////////////////////////////////////////////////////////////////////////
_print:
push ebp ;Save the value of base pointer
mov ebp, esp ;Set ebp to point to the current offset in the stack
pusha
mov edx, message
mov ah, 9h
int 21h
exit:
popa
mov esp, ebp
pop ebp
ret
Now, I convert it to an object file and link to to my C file which is this:
PHP Code:
#include <stdio.h>
void print() __attribute__((cdecl));
int main()
{
printf("CHello");
print();
getch();
return 0;
}
It just crashes the program when I call print(). It actually crashes at the line which calls the DOS 21h interrupt (int 21h) from the assembly code. How would I go about fixing it? I moved to pure assembly because I couldn't get the interrupts to work in inline assembly and now it's not working even in this situation!:(
-
-
Windows 2000
Not sure if an Assembler creates an EXE which supports 16-bit code (DOS and BIOS calls) compared to a C++ created EXE file which doesn't support 16-bit code (or does it?). Somebody from another forum told me that DJPSS (or whatever the compiler name is) supports both 16-bit and 32-bit code in its EXE but I tried it with gcc and it didn't work.
[EDIT]
The above code doesn't work in, both, gcc and VC++.
[/EDIT]
-
I think Win2k doesn't support the 21h ints anymore - if it let's you int at all.
Which assembler do you use? MASM will create win32 code, it can't use interrupts. Neither can MSVC++ inline asm code.
NASM or an old TASM might work, but I'm not sure.
-
I'm using the latest version of NASM. I guess I'll have to do more research on what supports 16-bit and what doesn't.
Oh well, school started so I guess I won't have enough time...:(
-
Which complier are you using? I know that the MSVC++ won't let you (I tried. :( )
Could you use the STI command to enable them? I haven't played with this command so I am not certain of the consequences.
-
No, STI doesn't work.
I know that you can fire the interrupt 3 - int 3 is a legal instruction and is even executed.
Unfortunatly all it does is break to the debugger.
-
Well it was worth a try. :(