News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Return type has boolean c function with UASM & VS 2017

Started by KradMoonRa, January 19, 2018, 10:30:32 AM

Previous topic - Next topic

KradMoonRa

Hi,

  I'm using VS 2017 and UASM and props targets to compile in VS has c project.

  I have found that uasm asm it's awesome fast than the .cpp compiled, but i only started learn the asm hoods behind the scene about 2 weeks.

  Is this correct for return type for a boolean c function?


header file:


#ifdef __cplusplus
extern "C" {
#endif

extern bool uXm_has_SSE3();

#ifdef __cplusplus
}
#endif



asm file:


         option   casemap:none
   ifndef __X64__
         .686P
         .xmm
         .model   flat, c
   else
         .X64P
         .xmm
         option   win64:11
         option   stackbase:rsp
   endif
         option   frame:auto


   .code
         align 16
         public uXm_has_SSE3

_TEXT segment

uXm_has_SSE3 proc

   ifndef __X64__
         push         ebx
         mov         eax,         1
         cpuid
         test         ecx,         1                 ; SSE3 support by microprocessor
         .if !ZERO?
         mov         al,         1
         .else
         xor         al,         al
         .endif
         pop         ebx
   else
         push         rbx
         mov         eax,         1
         cpuid
         test         ecx,         1                 ; SSE3 support by microprocessor
         .if !ZERO?
         mov         al,         1
         .else
         xor         al,         al
         .endif
         pop         rbx
   endif ;__X64__

         ret

uXm_has_SSE3 endp
_TEXT ends
   end ;.code


Uasm v2.46.8 with build costumizations for VS 2107 & 2015.
The uasmlib

aw27

If sizeof(bool) is 1 then will be fine to return the result in AL.

Adamanteus

#2
Universality means, that need special macroses for return values from functions, and for it need also registers substitutes and constant values equ's  :eusa_boohoo:

habran

It wouldn't hurt if you use mov eax, 1, in that case it would work for both C and asm because In C bool is a char and in asm BOOL is a DWORD

.data?
bul    BOOL ?

   268:    mov bul, TRUE
00007FF77DEA17FA C7 05 A4 84 00 00 01 00 00 00 mov         dword ptr [bul (07FF77DEA9CA8h)],1
Cod-Father