The MASM Forum

General => The Campus => Topic started by: six_L on March 06, 2023, 02:49:47 AM

Title: C -> ASM
Post by: six_L on March 06, 2023, 02:49:47 AM
Hello everyone!

How do the C codes translate into asm codes?

void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...)
{
     TCHAR   szBuffer [1024] ;
     va_list pArgList ;

     va_start (pArgList, szFormat) ;
     wvsprintf (szBuffer, szFormat, pArgList) ;
     va_end (pArgList) ;


     SendMessage (hwndEdit, EM_SETSEL, (WPARAM) -1, (LPARAM) -1) ;
     SendMessage (hwndEdit, EM_REPLACESEL, FALSE, (LPARAM) szBuffer) ;
     SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0) ;
}

    EditPrintf (hwndEdit,
                 TEXT ("System date and time successfully changed ")
                 TEXT ("from\r\n\t%s, %s.%03i to\r\n\t%s, %s.%03i."),
                 szDateOld, szTimeOld, pstOld->wMilliseconds,
                 szDateNew, szTimeNew, pstNew->wMilliseconds) ;
}
Title: Re: C -> ASM
Post by: jj2007 on March 06, 2023, 04:26:44 AM
Similar to this - just to give you a start. Go ahead and play yourself, it's not that difficult. Instead of TEXT ("..., use cfm$("...

EditPrintf proc hwndEdit, pFormat
Local szBuffer[BYTE]:1024
Local pArgList:DWORD, vaStart:DWORD

     ??? va_start (pArgList, szFormat) ;
     invoke wvsprintf, addr szBuffer, pFormat, addr pArgList
     ??? va_end (pArgList) ;

     invoke SendMessage, hwndEdit, EM_SETSEL, -1, -1
     invoke SendMessage, hwndEdit, EM_REPLACESEL, FALSE, addr szBuffer
     invoke SendMessage, hwndEdit, EM_SCROLLCARET, 0, 0
     ret
EditPrintf endp
Title: Re: C -> ASM
Post by: morgot on March 06, 2023, 09:33:23 AM
You can use https://godbolt.org/

https://ibb.co/D7kTpQW
Title: Re: C -> ASM
Post by: hutch-- on March 06, 2023, 10:16:18 AM
You used to be able to generate an ASM listing with the 32 bit versions of Visual C, they were a bit rough to understand but if you set the options to turn all optimisation off, you could then manually optimise it and often get it faster. If its a 32 bit version of VC, have a look at the command line options.
Title: Re: C -> ASM
Post by: mikeburr on March 08, 2023, 09:57:13 AM
if youve got a working exe chuck it in IDA [32 bit freeware] or Radare cutter [64 bit freeware] .. youll notice that the compilers such as Visual C put an awful lot of junk in largely revolving around the ability to recover your program in the event of failure .. further if youre running a 64 bit program theres a lot of "bodging" done by MS to try and ensure some sort of compatibility  with what are basically 32 bit functions ... Cutter really highlights what a mess it is sometimes .. std function calls are ok but anything non standard is fraught to say the least
regards
mikeb
Title: Re: C -> ASM
Post by: six_L on March 09, 2023, 12:38:28 PM
Hi,jj2007/morgot/hutch--/mikeburr

Thank you very much!
Special emphasis on the our member(morgot) from Ukraine. you are fine, we'r gratified.