Pelles C forum

Pelles C => General discussions => Topic started by: Supercim on September 26, 2004, 07:14:17 PM

Title: Pelles and asm
Post 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
Title: Pelles and asm
Post by: Vortex on September 26, 2004, 09:28:43 PM
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
Title: Pelles and asm
Post by: Supercim on September 27, 2004, 12:01:08 AM
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:
Title: Pelles and asm
Post by: dare2 on September 27, 2004, 12:33:36 AM
At a guess: int 21 is DOS, I don't think XP, 2K etc allow it. Need to use API calls instead.
Title: Pelles and asm
Post by: Supercim on September 27, 2004, 11:40:24 AM
Excuse me, but i'm newbie... Can you post a example of API call? thanks
Title: Pelles and asm
Post by: Pelle on September 27, 2004, 06:14:36 PM
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
Title: Pelles and asm
Post by: Supercim on September 27, 2004, 07:30:48 PM
Thank you very much  :D