Author Topic: C -> ASM  (Read 520 times)

six_L

  • Member
  • ***
  • Posts: 315
C -> ASM
« 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) ;
}

Code: [Select]
    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) ;
}
Say you, Say me, Say the codes together for ever.

jj2007

  • Member
  • *****
  • Posts: 13944
  • Assembly is fun ;-)
    • MasmBasic
Re: C -> ASM
« Reply #1 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$("...

Code: [Select]
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

morgot

  • Member
  • **
  • Posts: 143
Re: C -> ASM
« Reply #2 on: March 06, 2023, 09:33:23 AM »
Sorry for the bad English

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: C -> ASM
« Reply #3 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

mikeburr

  • Member
  • **
  • Posts: 189
Re: C -> ASM
« Reply #4 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

six_L

  • Member
  • ***
  • Posts: 315
Re: C -> ASM
« Reply #5 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.
Say you, Say me, Say the codes together for ever.