|
-
Sep 1st, 2002, 02:18 AM
#1
Thread Starter
PowerPoster
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!
-
Sep 3rd, 2002, 06:59 AM
#2
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 3rd, 2002, 07:02 AM
#3
Thread Starter
PowerPoster
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]
-
Sep 3rd, 2002, 11:14 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 3rd, 2002, 03:28 PM
#5
Thread Starter
PowerPoster
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...
-
Jul 15th, 2003, 03:20 PM
#6
Fanatic Member
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.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Jul 16th, 2003, 01:06 AM
#7
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 16th, 2003, 03:47 PM
#8
Fanatic Member
Well it was worth a try.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|