Pelles C forum
Pelles C => General discussions => Topic started by: Supercim on September 26, 2004, 07:14:17 PM
-
Can I use asm in Pelles compiler? If possibile can I see a e example?? Excuse for my English but i'm Italian :P
-
Hi Supercim,
Welcome to the forum.
There are three methods to use asm with Pelle's C compiler:
i) inline assemby, code from the help file:
Examples:
__asm
{
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
}
Alternatively, you can put __asm in front of each assembly instruction:
__asm push ebp
__asm mov ebp, esp
__asm sub esp, __LOCAL_SIZE
ii)External asm modules coded with an assembler like Microsoft MASM
iii)asm source files which can be processed by pocc, the compiler. The syntax is similar to Nasm
-
well, but when i compile a example program
#include <stdio.h>
void main(void)
{
__asm
{
mov ah,02
mov dl,64
int 21h
}
}
my win xp crash!!!!
why??? :shock:
-
At a guess: int 21 is DOS, I don't think XP, 2K etc allow it. Need to use API calls instead.
-
Excuse me, but i'm newbie... Can you post a example of API call? thanks
-
Maybe something like this. You need to find documentation about Win32 API calls. This only demonstrates CreateFile (and GetLastError) calls.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int main(void)
{
char *filename = "filename.ext";
HANDLE hf;
__asm
{
push 0 ; hTemplateFile
push 0 ; dwFlagsAndAttributes
push OPEN_EXISTING ; dwCreationDisposition (OPEN_EXISTING == 3)
push 0 ; lpSecurityAttributes
push 0x00000001 ; dwShareMode (FILE_SHARE_READ == 0x00000001)
push 0x80000000 ; dwDesiredAccess (GENERIC_READ == 0x80000000)
lea eax,[filename]
push eax ; lpFileName
call CreateFileA ; (CreateFileA == CreateFile ANSI version, CreateFileW == CreateFile Unicode version)
mov [hf],eax
cmp eax,-1 ; INVALID_HANDLE_VALUE == -1
jne open_ok
call GetLastError
; ...
open_ok:
; ...
}
}
Pelle
-
Thank you very much :D