Assembly Language 9 Inline assembly

Source: Internet
Author: User

C Language Inline compilation

void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;

Rewrite the following 2 lines of code with assembly statements
Ps[3]= ' B ';
printf (PS);
}

//equivalent notation 1:
Void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
//&P1 is the memory that holds the pointer P1, [P1] means the value of the P1 is taken.
//a bit around, here P1 is the pointer entity, not the value to understand for it
mov eax, DWORD ptr [P1]
//[eax] means to take the contents of EAX storage. Now EAX is the value of P1
mov byte ptr [eax+3],0x62
push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Add esp,4
}
}< Br>freelibrary (HMOD);
}
}


Equivalent notation 2:
void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
[ps+3] means to take the 3rd element, although the C language inside the array name is a pointer, the assembly can not be directly written as equivalent
mov byte ptr [ps+3],0x62
Push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Pop EBX//equivalent to esp+=4
}
}
FreeLibrary (HMOD);
}
}

Notation 3:
void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
MOV ecx,10
mov ebx, 0
Replace PS to BBBBBBBB
S:mov byte ptr [ps+ebx],0x62
Inc EBX
Loop s
Push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Pop ebx
}
}
FreeLibrary (HMOD);
}
}

Assembly Language 9 inline assembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.