Author Topic: Return type has boolean c function with UASM & VS 2017  (Read 539 times)

KradMoonRa

  • Regular Member
  • *
  • Posts: 24
Return type has boolean c function with UASM & VS 2017
« on: January 19, 2018, 10:30:32 AM »
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:
Code: [Select]

#ifdef __cplusplus
extern "C" {
#endif

extern bool uXm_has_SSE3();

#ifdef __cplusplus
}
#endif


asm file:
Code: [Select]

         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.
« Last Edit: January 20, 2018, 11:13:37 PM by KradMoonRa »

AW

  • Member
  • *****
  • Posts: 1394
  • Let's Make ASM Great Again!
Re: Return type has boolean c function with UASM & VS 2017
« Reply #1 on: January 19, 2018, 01:56:56 PM »
If sizeof(bool) is 1 then will be fine to return the result in AL.

Adamanteus

  • Member
  • **
  • Posts: 197
    • LLC "AMS"
Re: Return type has boolean c function with UASM & VS 2017
« Reply #2 on: January 20, 2018, 03:29:08 AM »
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:
« Last Edit: January 20, 2018, 10:07:24 AM by Adamanteus »

habran

  • Member
  • *****
  • Posts: 1170
    • uasm
Re: Return type has boolean c function with UASM & VS 2017
« Reply #3 on: January 20, 2018, 05:47:55 AM »
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
Code: [Select]
.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