'NASM'에 해당되는 글 4건
- 2009/05/14 어셈블리어 메모리공간에 저장되는 과정
- 2009/05/12 Bit Operations
- 2009/05/12 push,pop
- 2009/05/11 어셈블리어
<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 |
shl ax, 1 ;shift 1 bit to left, ax = 8246H, CF = 1
shr ax, 1 ;shift 1 bit to right, ax = 4123H, CF = 0
shr ax, 1 ;shift 1 bit to right, ax = 2091H, CF = 1
mov ax, 0C123H
shl ax, 2 ;shift 2 bit to left, ax = 048CH, CF = 1
mov cl, 3
shr ax, cl ;shift 3 bit to right, ax = 0091H, CF = 1
'NASM' 카테고리의 다른 글
| 어셈블리어 메모리공간에 저장되는 과정 (0) | 2009/05/14 |
|---|---|
| Bit Operations (0) | 2009/05/12 |
| push,pop (0) | 2009/05/12 |
| 어셈블리어 (0) | 2009/05/11 |
<main.c>
extern void asm_main();
void test(int k, int j, int y)
{
printf("k:%d\n", k);
printf("j:%d\n", j);
printf("y:%d\n", y);
}
int main()
{
asm_main();
return 0;
}
<test.asm>
segment .text
extern _test
global _asm_main
_asm_main:
;entry code
push ebp ; 1. --esp 2. 값 push
mov ebp, esp
push 7
push 9
push 10
call _test
add esp, 12
;exit code
mov esp, ebp
pop ebp ; 1. 값 pop 2. ++esp
ret
'NASM' 카테고리의 다른 글
| 어셈블리어 메모리공간에 저장되는 과정 (0) | 2009/05/14 |
|---|---|
| Bit Operations (0) | 2009/05/12 |
| push,pop (0) | 2009/05/12 |
| 어셈블리어 (0) | 2009/05/11 |
/************* main.c *******************************/
char c = 0xff;
short s = 0xffff;
int i = 0xffffffff;
extern void inc_size(), dec_size();
main() {
/* type casting: increment size */
c = 10;
inc_size();
printf("c = %d\ts = %d\ti = %d\n", c, s, i);
c = -10;
inc_size();
printf("c = %d\ts = %d\ti = %d\n", c, s, i);
/* type casting: decrement size */
i = 100;
dec_size();
printf("c = %d\ts = %d\ti = %d\n", c, s, i);
i = -100;
dec_size();
printf("c = %d\ts = %d\ti = %d\n", c, s, i);
}
/******************************************************/
위 프로그램에서 사용되는 inc_size(), dec_size() 를 어셈블리
프로그램으로 작성하라.
inc_size() 함수는 8비트 전역변수인 c 를 16비트로 확장하여
전역변수 s 에 넣고, 또한 32비트로 확장하여 전역변수 i 에 넣는다.
dec_size() 함수는 32비트 전역변수인 i 를 16비트로 줄여서
전역변수 s 에 넣고, 또한 8비트로 줄여서 전역변수 c 에 넣는다.
위 프로그램이 정상적으로 실행될 경우 화면에 다음과 같은 내용이 출력된다.
$ main
c = 10 s = 10 i = 10
c = -10 s = -10 i = -10
c = 100 s = 100 i = 100
c = -100 s = -100 i = -100
<size.asm>
%include "asm_io.inc"
segment .data
extern _c
extern _s
extern _i
segment .bss
segment .text
global _inc_size
global _dec_size
_inc_size:
mov eax, 0
mov al, [_c]
cbw ;byte(8bit) -> word(16bit)
mov [_s], ax
mov ax, [_s]
cwde ;word(16bit) -> double word(32bit)
mov [_i], eax
ret
_dec_size:
mov eax, 0
mov eax, [_i]
mov [_s], ax
mov [_c], al
'NASM' 카테고리의 다른 글
| 어셈블리어 메모리공간에 저장되는 과정 (0) | 2009/05/14 |
|---|---|
| Bit Operations (0) | 2009/05/12 |
| push,pop (0) | 2009/05/12 |
| 어셈블리어 (0) | 2009/05/11 |



Prev
