<asm_main.asm>
segment .text
global _asm_main
_asm_main:
;entry code
push ebp
mov ebp, esp
mov esp, [ebp+8]
add esp, 40
pusha
mov eax, [ebp+4] ; -> push dword[ebp+4]
push eax
pushf
;exit code
mov esp, ebp
pop ebp
ret
<main.c>
extern int asm_main(struct Context*);
struct Context
{
int efl;
int eip;
int edi;
int esi;
int ebp;
int esp;
int ebx;
int edx;
int ecx;
int eax;
};
int main()
{
struct Context status;
memset(&status, 0, sizeof(struct Context));
asm_main(&status);
printf("eax=%x\n", status.eax);
printf("ecx=%x\n", status.ecx);
printf("edx=%x\n", status.edx);
printf("ebx=%x\n", status.ebx);
printf("esp=%x\n", status.esp);
printf("ebp=%x\n", status.ebp);
printf("esi=%x\n", status.esi);
printf("edi=%x\n", status.edi);
printf("eip=%x\n", status.eip);
printf("efl=%x\n", status.efl);
//printf("%esp=%x\n", &iesp);
return 0;
'NASM' 카테고리의 다른 글
| 어셈블리어 메모리공간에 저장되는 과정 (0) | 2009/05/14 |
|---|---|
| Bit Operations (0) | 2009/05/12 |
| push,pop (0) | 2009/05/12 |
| 어셈블리어 (0) | 2009/05/11 |



Prev
