NO

Author Topic: Inline  (Read 5811 times)

Jokaste

  • Guest
Inline
« on: October 31, 2017, 02:49:13 PM »
In WinNt.h I found this code:
Code: [Select]

__inline ULONGLONG NTAPI Int64ShrlMod32(ULONGLONG Value, DWORD ShiftCount) {
    __asm {
        mov ecx, ShiftCount
        mov eax, dword ptr[Value]
        mov edx, dword ptr[Value +4]
        shrd eax, edx, cl
        shr edx, cl
    }
}


When writing C code Mr Orinius does not accept __asm{...}! Why is there this code?

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Inline
« Reply #1 on: October 31, 2017, 08:09:28 PM »
Hi Jokaste,

Here is a quick example :

Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

__declspec(naked) char* UpperCase(char* szText) /* Turn off framing to get
a smaller sized function */
{
__asm{
mov eax,[esp+4] /* get the address of the string to be converted */
sub eax,1
__repeat:
add eax,1
movzx ecx,BYTE PTR [eax]
test ecx,ecx
je __end
cmp ecx,97 /* if ASCII(ecx) < 97 then ignore the charater */
jb __repeat
cmp ecx,122 /* if ASCII(ecx) > 122 then ignore the charater */
ja __repeat
sub BYTE PTR [eax],32 /* convert lowecase to uppercase */
jmp __repeat
__end:
mov eax,[esp+4]
ret 4 /* manual stack balance */
}
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,UpperCase(msg),"Hello!",MB_OK);
return 0;
}
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Inline
« Reply #2 on: November 01, 2017, 10:49:38 AM »
In WinNt.h I found this code:
Code: [Select]

__inline ULONGLONG NTAPI Int64ShrlMod32(ULONGLONG Value, DWORD ShiftCount) {
    __asm {
        mov ecx, ShiftCount
        mov eax, dword ptr[Value]
        mov edx, dword ptr[Value +4]
        shrd eax, edx, cl
        shr edx, cl
    }
}


When writing C code Mr Orinius does not accept __asm{...}! Why is there this code?

Large Integer Functions

it is for x86 / i386 only.
for x64 there is
Code: [Select]
#define Int64ShrlMod32(a,b)  (((unsigned __int64)(a)) >> (b))
May the source be with you