반응형
- power
#include <stdio.h>
int power2( int num, int power );
int main( void )
{
printf_s( "3 times 2 to the power of 5 is %d\n", \
power2( 3, 5) );
}
int power2( int num, int power )
{
__asm
{
mov eax, num ; Get first argument
mov ecx, power ; Get second argument
shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
}
// Return with result in EAX
}
docs.microsoft.com/ko-kr/cpp/assembler/inline/writing-functions-with-inline-assembly?view=vs-2019
- 레이블로 점프
void func( void )
{
goto C_Dest; /* Legal: correct case */
goto c_dest; /* Error: incorrect case */
goto A_Dest; /* Legal: correct case */
goto a_dest; /* Legal: incorrect case */
__asm
{
jmp C_Dest ; Legal: correct case
jmp c_dest ; Legal: incorrect case
jmp A_Dest ; Legal: correct case
jmp a_dest ; Legal: incorrect case
a_dest: ; __asm label
}
C_Dest: /* C label */
return;
}
int main()
{
}
docs.microsoft.com/ko-kr/cpp/assembler/inline/jumping-to-labels-in-inline-assembly?view=vs-2019
- C함수 호출
// InlineAssembler_Calling_C_Functions_in_Inline_Assembly.cpp
// processor: x86
#include <stdio.h>
char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
int main( void )
{
__asm
{
mov eax, offset world
push eax
mov eax, offset hello
push eax
mov eax, offset format
push eax
call printf
//clean up the stack so that main can exit cleanly
//use the unused register ebx to do the cleanup
pop ebx
pop ebx
pop ebx
}
}
docs.microsoft.com/ko-kr/cpp/assembler/inline/calling-c-functions-in-inline-assembly?view=vs-2019
'프로그래밍 일반 > 프로그래밍 기타' 카테고리의 다른 글
[어셈블리] OllyDbg 소개 (0) | 2020.09.13 |
---|---|
Visual Studio 2019에서 어셈블리 64bit 프로젝트 생성 (0) | 2020.09.13 |
CPU 레지스터 (0) | 2020.09.12 |