NO

Author Topic: Pelles and asm  (Read 5959 times)

Supercim

  • Guest
Pelles and asm
« 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

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Pelles and asm
« Reply #1 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:
Code: [Select]

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
Code it... That's all...

Supercim

  • Guest
Pelles and asm
« Reply #2 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:

dare2

  • Guest
Pelles and asm
« Reply #3 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.

Supercim

  • Guest
Pelles and asm
« Reply #4 on: September 27, 2004, 11:40:24 AM »
Excuse me, but i'm newbie... Can you post a example of API call? thanks

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Pelles and asm
« Reply #5 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.

Code: [Select]

#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
/Pelle

Supercim

  • Guest
Pelles and asm
« Reply #6 on: September 27, 2004, 07:30:48 PM »
Thank you very much  :D