The MASM Forum Archive 2004 to 2012

Specialised Projects => Compiler Based Assembler => Pelle's C compiler and tools => Topic started by: Vortex on January 08, 2005, 10:49:16 AM

Title: Inline assembly with Pelle's C
Post by: Vortex on January 08, 2005, 10:49:16 AM
Hi friends,

Here is an example of using inline assembly with Pelle's C. The original source code of szUpper comes with Hutch's masm32 package.


#define WIN32_LEAN_AND_MEAN
#include <windows.h>

char *szUpper(char *text)
{
__asm{
mov eax, text
dec eax
@repeat:
add eax, 1
cmp BYTE PTR [eax], 0
je @end
cmp BYTE PTR [eax], "a"
jb @repeat
cmp BYTE PTR [eax], "z"
ja @repeat
sub BYTE PTR [eax], 32
jmp @repeat
@end:
}
return text;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,szUpper(msg),"Hello!",MB_OK);
return 0;
}
Title: Re: Inline assembly with Pelle's C
Post by: petezl on January 08, 2005, 11:00:38 AM
Hi Vortex,
Thanks for another interesting forum. ..
Having done some minimal in-line assembly with Digital Mars. I'm looking forward to having a bash with Pelle'sC.
I did a major re-organisation of my HD so will be a while before i get it all installed again. I also lost my password for Pelle's forum, will have to get back there soon to thank him for some links he gave me.
Peter.
Title: Re: Inline assembly with Pelle's C
Post by: Vortex on January 08, 2005, 11:16:19 AM
Hi Peter,

I hope you will recover successfully your system.

Glad to learn that you will rejoin Pelle's forum :U

Title: Re: Inline assembly with Pelle's C
Post by: Vortex on January 08, 2005, 10:37:27 PM
Here is another method, the C source code:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

extern char *szUpper(char *text);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,szUpper(msg),"Hello!",MB_OK);
return 0;
}


Pelle's C compiler, pocc.exe accepts asm source files based on a variant of NASM syntax:

[cpu 486]
[global _szUpper]
[section .text]
[function _szUpper]
_szUpper:
push ebp
mov ebp,esp
mov eax,[EBP+8]
dec eax
@restart:
add eax,1
cmp byte [eax],0
je near @end
cmp byte [eax],97
jb near @restart
cmp byte [eax],122
ja near @restart
sub byte [eax],32
jmp near @restart
@end:
mov eax,dword [ebp+8]
mov esp,ebp
pop ebp
ret

[attachment deleted by admin]
Title: Re: Inline assembly with Pelle's C
Post by: petezl on January 09, 2005, 01:13:33 AM
Vortex,
That code you posted shows the way to completing my original aim of creating an asm project for the PPC. A nice addition to Pelles soft. All I have to do now is learn a bit about NASM.
Peter.
Title: Re: Inline assembly with Pelle's C
Post by: Farabi on September 24, 2005, 03:14:58 AM
How to debuging it if I want to see the code generated?
Title: Re: Inline assembly with Pelle's C
Post by: GregL on September 24, 2005, 04:21:15 AM
Farabi,

If you don't already have Pelle's C, you need to get it. Open the project. Do a debug build. Start the debugger. Right click on the source code and select Show assembly.

Or, you could use OllyDbg (with no debug information).

Title: Re: Inline assembly with Pelle's C
Post by: PellesC on September 24, 2005, 03:04:39 PM
...or possibly add an "int 3" instruction somewhere, which will give the debugger a reason to break...

(int 3 = interrupt 3 -- trap to debugger = opcode 0xCC)

Pelle
Title: Re: Inline assembly with Pelle's C
Post by: Farabi on September 25, 2005, 04:16:35 AM
Quote from: Greg on September 24, 2005, 04:21:15 AM
Farabi,

If you don't already have Pelle's C, you need to get it. Open the project. Do a debug build. Start the debugger. Right click on the source code and select Show assembly.

Or, you could use OllyDbg (with no debug information).




I have it. But dont know how to start. But now I know how to use it after see a few example.
Title: Re: Inline assembly with Pelle's C
Post by: Vortex on September 25, 2005, 11:26:40 AM
Hi Onan,

Debugging is easy with PellesC, here is the debug version of my inline assembly example.

[attachment deleted by admin]
Title: Re: Inline assembly with Pelle's C
Post by: noman9607 on April 11, 2006, 07:00:36 PM
Vortex,
Thanks for the debug project, I just double clicked on the  project file and Pelle's ide came up then I clicked on debug and I was good to go in about 2 sec. One thing about the microsoft debugger I like when f8 or single stepping is that the register(s) that change state in that step are in red so you can catch something you are not specially looking for.
Title: Re: Inline assembly with Pelle's C
Post by: GregL on May 17, 2006, 09:58:59 PM
While trying out Pelles C 4.50, I updated Vortex's example posted above (Inline2.zip) to work with the new version. I had to rewrite the asm files, they now need to be in POASM format.



[attachment deleted by admin]
Title: Re: Inline assembly with Pelle's C
Post by: Vortex on May 18, 2006, 05:46:40 AM
Hi Greg,

Thanks for updating the example, nice work :U
Title: Re: Inline assembly with Pelle's C
Post by: OzzY on January 26, 2007, 01:14:30 AM
QuotePelle's C compiler, pocc.exe accepts asm source files based on a variant of NASM syntax
I didn't know that. So , why Pelle is writting PoASM?
Title: Re: Inline assembly with Pelle's C
Post by: Vortex on January 26, 2007, 05:43:08 PM
Hi Ozzy,

Pelle released Poasm towards the end of 2005. He coded it to support his software development package. Poasm didn't exist when I created this topic.