C++ Vs Assembly !!
Vahid Muhammady (vahidmy)
2022
https://vahidmy.blog.ir
====================
VC++ at Visual Studio 2022 :
MFC Library :
Sample of Code:
// asm = Assembly Language
C++:
while (Getmessage(&msg,nullptr,0,0))
// True Assembly by RosAsm and Fasm :
push 0
push 0
push nullptr
push &msg
call Getmessage
// False Assembly by C++ Compiler :
C++: 0
asm : xor r9d , r9d
C++: 0
asm : xor r9d , r9d
C++: nullptr
asm : xor edx, edx
C++: &msg =
asm : lea rdx , [msg]
C++ : GetMessage
asm: call [_ _ imp_GetMessage] ; what is imp ????
C ++ : while
asm : test eax , eax ; test = while
je _ _ $EncStackInitStart+0F2h ; je = jump if equal
=================================
VC++ : if (!TranslateAccelerator(msg.hwnd, hAcclTable , &msg )
asm : lea r8 , [msg]
C++: hAcclTable
asm : mov rdx , [ hAcclTable ]
C++: msg.hwnd
asm : mov rcx , [msg]
C++: TranslateAccelerator
asm : call [ - - imp_TranslateAccelerator]
C++: if (! ) // if (! ) = if not equal
asm : test eax , eax ; test = if
jne ????? ; jne = jump if not equal
C++ : TranslateMessage(msg)
// True Assembly by RosAsm and Fasm :
push msg
call TranslateMessage
// False Assembly by C++ Compiler :
lea rcx , [msg]
call [_ _imp_TranslateMessage] ; What is this _ _imp_ ????
C++: {
// True Assembly by RosAsm and Fasm :
push ebp
mov ebp , esp
C++: }
// True Assembly by RosAsm and Fasm :
pop ebp
mov esp , ebp
// if { is "begin" and } is "end" then
// the above law is False ;
// else if these are "proc" and "endproc" then
// the above low is True ;
// end if .
//
// Comment Writing at Pascal Mode !!!
// I like pascal and basic and Assembly very much !!!
// I Like C/C++ too !! . C/C++ are Portable versions of Assembly Language.
C++ : return (int) msg.wparam
asm : mov , eax [ebp+38h] ; [ebp+38h] = wParam
C++ : if (g_hThreadSound > 0 && g_hThreadSound != (HANDLE) -1)
asm :
cmp qword ptr [g_hThreadSound ] , 0
jbe AFXPlaySystemSound+0DBh
C++: && g_hThreadSound != (HANDLE) -1
asm :
cmp qword ptr [g_hThreadSound ] , (HANDLE) -1
je AFXPlaySystemSound+0DBh
C++ :
::SetThreadPriority(g_hThreadSound, THREAD_PRIORITY_BELOW_NORMAL);
asm :
mov edx , THREAD_PRIORITY_BELOW_NORMAL
mov rcx, qword ptr [g_hThreadSound ]
call qword ptr [__imp_SetThreadPriority ]
C++ : g_nSoundState = nSound;
asm :
mov eax,dword ptr [nSound] ; eax = nSound
mov dword ptr [g_nSoundState ],eax ; g_nSoundState = eax = nSound
C++: void _cdecl AFXSoundThreadProc(LPVOID)
{
asm:
mov qword ptr [rsp+8] , rcx
push rdi
sub rsp,30h
C++: const DWORD dwFlags = (SND_SYNC | SND_NODEFAULT | SND_ALIAS | SND_NOWAIT);
asm: mov dword ptr [dwFlags],12002h ; 12002h = SND_
C++: int nIdleCount = 0; // loop iterations since last sound played
asm: mov dword ptr [nIdleCount] , 0
C++: while (g_nSoundState != AFX_SOUND_TERMINATE)
asm: cmp dword ptr [g_nSoundState ], AFX_SOUND_TERMINATE
je AFXSoundThreadProc+0C8h
C++: switch (g_nSoundState)
// False Assembly By C++ Compiler :
mov eax,dword ptr [g_nSoundState ]
mov dword ptr [rsp+28h],g_nSoundState
cmp dword ptr [g_nSoundState],0
je AFXSoundThreadProc+9Ah
cmp dword ptr [g_nSoundState],1
je AFXSoundThreadProc+48h
cmp dword ptr [g_nSoundState],2
je AFXSoundThreadProc+71h
jmp AFXSoundThreadProc+0A4h
C++: // case AFX_SOUND_MENU_COMMAND:
::PlaySound(_T("MenuCommand"), NULL, dwFlags);
// False Assembly By C++ Compiler :
mov r8d, dwFlags
xor edx, edx ; NULL
lea rcx, [string L"MenuCommand" ]
call qword ptr [__imp_PlaySoundW ]
// True Assembly by RosAsm and Fasm :
push dwFlags
push NULL
push "MenuCommand"
call PlaySound
C++: g_nSoundState = AFX_SOUND_IDLE;
asm : mov dword ptr [g_nSoundState ], AFX_SOUND_IDLE
C++: nIdleCount = 0;
asm : mov dword ptr [nIdleCount] , 0
C++: break;
asm: jmp AFXSoundThreadProc+0A4h
C++
//case AFX_SOUND_MENU_POPUP:
C++
::PlaySound(_T("MenuPopup"), NULL, dwFlags);
asm:
mov r8d, dwFlags
xor edx,edx ; NULL
mov rcx, [string L"MenuPopup" ]
call qword ptr [__imp_PlaySoundW ]
C++:
g_nSoundState = AFX_SOUND_IDLE;
asm:
mov dword ptr [g_nSoundState ], AFX_SOUND_IDLE
C++
nIdleCount = 0;
asm:
mov dword ptr [nIdleCount] , 0
C++: break;
asm: jmp AFXSoundThreadProc+0A4h
C++: //case AFX_SOUND_IDLE:
C++: nIdleCount++;
asm:
mov eax,dword ptr [nIdleCount] ; nIdleCount
inc eax ; nIdleCount+
mov dword ptr [nIdleCount],eax ; nIdleCount++
C++:
break;
}
asm :
???????
// We want to avoid waking up the CPU from an idle state--this wastes
// energy/battery, so kill the thread after a period of inactivity. An
// idle count of 2000 results in approximately 30 seconds of idle time.
C++:
if (nIdleCount == 2000)
asm:
cmp dword ptr [nIdleCount] , 2000
jne AFXSoundThreadProc+0B8h
C++:
{
g_nSoundState = AFX_SOUND_TERMINATE;
asm:
mov dword ptr [g_nSoundState ] , AFX_SOUND_TERMINATE
C++:
}
::Sleep(nThreadDelay);
asm:
mov ecx,5
call qword ptr [__imp_Sleep (nThreadDelay)]
C++:
}
asm:
jmp AFXSoundThreadProc+1Ah
C++:
::PlaySound(NULL, NULL, SND_PURGE);
asm:
mov r8d, SND_PURGE
xor edx,edx ; NULL
xor ecx,ecx ; NULL
call qword ptr [__imp_PlaySoundW ]
C++:
g_nSoundState = AFX_SOUND_NOT_STARTED;
asm:
mov dword ptr [g_nSoundState ], AFX_SOUND_NOT_STARTED
C++:
g_hThreadSound = NULL;
asm:
mov qword ptr [g_hThreadSound ],NULL
C++:
_endthread();
asm:
call _endthread (07FF7E95993C2h) ;
C++:
}
asm:
add rsp,30h
pop rdi
ret
C++ : hAcclTable
asm : mov rdx , [ hAcclTable ]
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
Q : What is True or False at the above code ????
A: I Do NOT know !!
But I Know that Assembly Language is forever .
Assembly Language ( 1947 _________ 2022-2023-2024-2025-......)
C++ is a Ugly and False version of The Assembly Programming Language !!
C is better than C++ . C is very similar to Assembly Language.
Hello Assembly !
Hello C !!
Hello C++ !!!!!!!!
Assembly is Freedom and Power and hack and reverse engine !!