-
x86프로그래밍 언어/규격 2013. 5. 6. 17:57
the Von Neumann architecture
머신 스택
*
> 범용 레지스터
AMD64는 범용 레지스터를 16개로 늘렸다
%eax # accumulator
%ebx
%ecx # count
%edx # data
%esi
%edi
%ebp
base pointer
프레임 포인터
스택 프레임
%esp
stack pointer
> can only be accessed through special instructions
인스트럭션 포인터
프로그램 카운터(pc, program counter)
%eip
플래그 레지스터
status register
%eglags
상태 플래그
* 오퍼랜드
> 값(immediate mode)
$숫자
to load direct values into registers or memory locations
can only be a source operand
c.f. direct addressing mode
> 레지스터(register addressing mode)
%..
> memory address references
ADDRESS_OR_OFFSET(%BASE_OR_OFFSET,%INDEX,MULTIPLIER)
FINAL ADDRESS = ADDRESS_OR_OFFSET + %BASE_OR_OFFSET + MULTIPLIER * %INDEX
- direct addressing mode
ADDRESS_OR_OFFSET # the value at memory address ADDRESS_OR_OFFSET
c.f. immediate mode
- indexed addressing mode
ADDRESS_OR_OFFSET(,%INDEX,WORDSIZE)
You can use any general-purpose register as the index register
a constant multiplier of 1, 2, or 4(8)
- indirect addressing mode
(%BASE_OR_OFFSET)
c.f. (%eax,%edi,1) # indexed indirect addressing mode
- base pointer addressing mode
포인터
ADDRESS_OR_OFFSET(%BASE_OR_OFFSET)
구조체 멤버 액세스?
ADDRESS_OR_OFFSET(%ebp)
access to the current stack frame elements(parameters, local variables)
* 전송 명령
mov(l)
값을 복사(대입)
movsx
movzx
push(l)
pop(l)
lea(l)
enter
leave
cltd(cdq) // ax -> dx
sete // Equal(ZF=1)
*
cmp(l) // Equal(ZF=1)
c.f. sub
the result of the comparison is stored in the status register
test
c.f. and
* 비트 연산 명령
and(l)
or(l)
xor(l)
not(l)
sal(l)
sar(l)
shr(l)
* 산술 연산 명령
add(l)
add the source operand from/to/by the destination operand and and save the result in the destination operand
캐리 플래그(CF)
sub(l)
imul(l)
idiv(l)
the dividend be in %eax, and %edx be zero, and the quotient is then transferred to %eax and the remainder to %edx. However, the divisor can be any register or memory location
inc(l)
dec(l)
neg(l)
* 연산의 제어
flow control instructions
jmp
conditional jump
jnz
unconditional jump
ZF(Zero Flag)
je
jg
jge
jl
jle
call
cdecl
stdcall
fastcall(or register call)
ret