Title: Pengantar Organisasi Komputer
1IKI10230Pengantar Organisasi KomputerKuliah no.
05.a Data Transfer Instructions
Sumber1. Paul Carter, PC Assembly Language2.
Hamacher. Computer Organization, ed-53. Materi
kuliah CS61C/2000 CS152/1997, UCB4. Intel
Architecture Software Developers Manual
17 Maret 2004 L. Yohanes Stefanus
(yohanes_at_cs.ui.ac.id)Bobby Nazief
(nazief_at_cs.ui.ac.id) bahan kuliah
http//www.cs.ui.ac.id/kuliah/POK/
2 3Set Instruksi Intel x86
- OP-CODE DEST,SRC DEST ? SRC OP DEST
- Hanya salah satu dari SRC atau DEST dapat berupa
memory-operand - ACC representasi untuk AL/AX/EAX
- Sebagian instruksi menyebabkan perubahan nilai
FLAGS, khususnya instruksi-instruksi Aritmatika
Logika
4- DATA TRANSFER INSTRUCTIONS
5Data Transfer Instructions
- General-purpose data movement
- Move
- Conditional Move
- Exchange
- Stack manipulation
- Type-conversion
6Data Transfer Instructions Summary (1/2)
- MOV Move
- CMOVE/CMOVZ Conditional move if equal/Conditional
move if zero - CMOVNE/CMOVNZ Conditional move if not
equal/Conditional move if not zero - CMOVA/CMOVNBE Conditional move if
above/Conditional move if not below or equal - CMOVAE/CMOVNB Conditional move if above or
equal/Conditional move if not below - CMOVB/CMOVNAE Conditional move if
below/Conditional move if not above or equal - CMOVBE/CMOVNA Conditional move if below or
equal/Conditional move if not above - CMOVG/CMOVNLE Conditional move if
greater/Conditional move if not less or equal - CMOVGE/CMOVNL Conditional move if greater or
equal/Conditional move if not less - CMOVL/CMOVNGE Conditional move if
less/Conditional move if not greater or equal - CMOVLE/CMOVNG Conditional move if less or
equal/Conditional move if not greater - CMOVC Conditional move if carry
- CMOVNC Conditional move if not carry
- CMOVO Conditional move if overflow
- CMOVNO Conditional move if not overflow
- CMOVS Conditional move if sign (negative)
- CMOVNS Conditional move if not sign
(non-negative) - CMOVP/CMOVPE Conditional move if
parity/Conditional move if parity even
7Data Transfer Instructions Summary (2/2)
- XCHG Exchange
- BSWAP Byte swap
- XADD Exchange and add
- CMPXCHG Compare and exchange
- CMPXCHG8B Compare and exchange 8 bytes
- PUSH Push onto stack
- POP Pop off of stack
- PUSHA/PUSHAD Push general-purpose registers onto
stack - POPA/POPAD Pop general-purpose registers from
stack - CWD/CDQ Convert word to doubleword/Convert
doubleword to quadword - CBW/CWDE Convert byte to word/Convert word to
doubleword in EAX register - MOVSX Move and sign extend
- MOVZX Move and zero extend
8Data Transfer Instructions Move
- MOV DEST,SRC DEST ? SRC
- cannot be used to load the CS register
- cannot be used to do memory-to-memory transfer
9Format Instruksi MOV (1/2)
- REG/MEM ? REG
- MOV r/m8,r8 Move r8 to r/m8
- MOV r/m16,r16 Move r16 to r/m16
- MOV r/m32,r32 Move r32 to r/m32
- REG ? REG/MEM
- MOV r8,r/m8 Move r/m8 to r8
- MOV r16,r/m16 Move r/m16 to r16
- MOV r32,r/m32 Move r/m32 to r32
- REG/MEM ? SEG-REG
- MOV r/m16,Sreg Move segment register to r/m16
- SEG-REG ? REG/MEM
- MOV Sreg,r/m16 Move r/m16 to segment register
10Format Instruksi MOV (2/2)
- AL/AX/EAX ? MEM
- MOV AL,moffs8 Move byte at (segoffset) to AL
- MOV AX,moffs16 Move word at (segoffset) to AX
- MOV EAX,moffs32 Move doubleword at (segoffset)
to EAX - MEM ? AL/AX/EAX
- MOV moffs8,AL Move AL to (segoffset)
- MOV moffs16,AX Move AX to (segoffset)
- MOV moffs32,EAX Move EAX to (segoffset)
- REG ? IMM
- MOV r8,imm8 Move imm8 to r8
- MOV r16,imm16 Move imm16 to r16
- MOV r32,imm32 Move imm32 to r32
- REG/MEM ? IMM
- MOV r/m8,imm8 Move imm8 to r/m8
- MOV r/m16,imm16 Move imm16 to r/m16
- MOV r/m32,imm32 Move imm32 to r/m32
11Data Transfer Instructions Conditional Move
12Format Instruksi CMOVcc
- CMOVA r16, r/m16 Move if above (CF0 and ZF0)
- CMOVA r32, r/m32 Move if above (CF0 and ZF0)
- CMOVAE r16, r/m16 Move if above or equal (CF0)
- CMOVAE r32, r/m32 Move if above or equal (CF0)
- CMOVB r16, r/m16 Move if below (CF1)
- CMOVB r32, r/m32 Move if below (CF1)
- CMOVBE r16, r/m16 Move if below or equal (CF1
or ZF1) - CMOVBE r32, r/m32 Move if below or equal (CF1
or ZF1) - CMOVC r16, r/m16 Move if carry (CF1)
- CMOVC r32, r/m32 Move if carry (CF1)
- CMOVE r16, r/m16 Move if equal (ZF1)
- CMOVE r32, r/m32 Move if equal (ZF1)
13Data Transfer Instructions Exchange
- XCHG DEST,SRC Exchange
- DEST ? SRC
- BSWAP R32 Byte swap
- R327..0 ? R3231..24
- R3215..8 ? R3223..16
- XADD DEST,SRC Exchange and add
- TEMP ? SRC DEST
- SRC ? DEST
- DEST ? TEMP
- CMPXCHG DEST,SRC Compare and exchange
- / accumulator AL, AX, or EAX, depending on
whether / - IF (accumulator DEST) ZF ? 1 DEST ?
SRC - ELSE ZF ? 0 accumulator ? DEST
- CMPXCHG8B DATA Compare exchange 8 bytes
- IF (EDXEAX DEST) ZF ? 1 DEST ?
ECXEBX - ELSE ZF ? 0 EDXEAX ? DEST
14Format Instruksi XCHG
- XCHG AX,r16 Exchange r16 with AX
- XCHG r16,AX Exchange AX with r16
- XCHG EAX, r32 Exchange r32 with EAX
- XCHG r32, EAX Exchange EAX with r32
- XCHG r/m8, r8 Exchange r8 with byte from r/m8
- XCHG r8, r/m8 Exchange byte from r/m8 with r8
- XCHG r/m16, r16 Exchange r16 with word from
r/m16 - XCHG r16, r/m16 Exchange word from r/m16 with
r16 - XCHG r/m32, r32 Exchange r32 with doubleword
from r/m32 - XCHG r32, r/m32 Exchange doubleword from r/m32
with r32
15Format Instruksi BSWAP XADD
- BSWAP r32 Reverses the byte order of a 32-bit
register. - XADD r/m8, r8 Exchange r8 and r/m8 load sum
into r/m8. - XADD r/m16, r16 Exchange r16 and r/m16 load sum
into r/m16. - XADD r/m32, r32 Exchange r32 and r/m32 load sum
into r/m32.
16Format Instruksi CMPXCHG CMPXCHG8B
- CMPXCHG r/m8,r8 Compare AL with r/m8. If
equal, ZF is set and r8 is loaded
into r/m8. Else, clear ZF and load
r/m8 into AL. - CMPXCHG r/m16,r16 Compare AX with r/m16. If
equal, ZF is set and r16 is loaded
into r/m16. Else, clear ZF and load r/m16
into AX - CMPXCHG r/m32,r32 Compare EAX with r/m32.
If equal, ZF is set and r32 is
loaded into r/m32. Else, clear ZF
and load r/m32 into EAX - CMPXCHG8B m64 Compare EDXEAX with m64.
If equal, set ZF and load ECXEBX into
m64. Else, clear ZF and load m64 into EDXEAX.
17Data Transfer Instructions Stack Manipulation
- PUSH SRC Push onto stack GP-regs,
SEG-regs, MEM, Immd. - ESP ? ESP 4/2
- ESP ? SRC
18Format Instruksi PUSH
- PUSH r/m16 Push r/m16
- PUSH WORD DATA
- PUSH r/m32 Push r/m32
- PUSH DWORD DATA
- PUSH r16 Push r16
- PUSH r32 Push r32
- PUSH imm8 Push imm8
- PUSH imm16 Push imm16
- PUSH imm32 Push imm32
- PUSH CS Push CS
- PUSH SS Push SS
- PUSH DS Push DS
- PUSH ES Push ES
- PUSH FS Push FS
- PUSH GS Push GS
19Data Transfer Instructions Stack Manipulation
- POP DEST Pop off of stack GP-regs,
SEG-regs (-CS), MEM - DEST ? ESP
- ESP ? ESP 4/2
20Format Instruksi POP
- POP r/m16 Pop top of stack into m16 increment
stack pointer - POP WORD DATA
- POP r/m32 Pop top of stack into m32 increment
stack pointer - POP DWORD DATA
- POP r16 Pop top of stack into r16 increment
stack pointer - POP r32 Pop top of stack into r32 increment
stack pointer - POP DS Pop top of stack into DS increment stack
pointer - POP ES Pop top of stack into ES increment stack
pointer - POP SS Pop top of stack into SS increment stack
pointer - POP FS Pop top of stack into FS increment stack
pointer - POP GS Pop top of stack into GS increment stack
pointer
21Data Transfer Instructions Stack Manipulation
- PUSHA/PUSHAD Push (16-/32-bit) GP-regs onto
stack - POPA/POPAD Pop (16-/32-bit) GP-regs from stack
22Data Transfer Instructions Type Conversion
- CBW Convert byte to word
- AX ? SignExtendAL
- CWD Convert word to doubleword
- DXAX ? SignExtendAX
- CWDE Convert word to doubleword
- EAX ? SignExtendAX
- CDQ Convert doubleword to quadword
- EDXEAX ? SignExtendEAX
- MOVSX DEST,SRC Move and sign extend
- DEST ? SignExtendSRC
- MOVZX DEST,SRC Move and zero extend
- DEST ? ZeroExtendSRC
23Format Instruksi MOVSX MOVZX
- MOVSX r16,r/m8 Move byte to word with
sign-extension - MOVSX r32,r/m8 Move byte to doubleword,
sign-extension - MOVSX r32,r/m16 Move word to doubleword,
sign-extension - MOVZX r16,r/m8 Move byte to word with
zero-extension - MOVZX r32,r/m8 Move byte to doubleword,
zero-extension - MOVZX r32,r/m16 Move word to doubleword,
zero-extension
24first.asm (1/3)
- include "asm_io.inc"
- segment .data
-
- These labels refer to strings used for output
-
- prompt1 db "Enter a number ", 0 don't
forget nul terminator - prompt2 db "Enter another number ", 0
- outmsg1 db "You entered ", 0
- outmsg2 db " and ", 0
- outmsg3 db ", the sum of these is ", 0
- segment .bss
-
- These labels refer to double words used to
store the inputs -
- input1 resd 100
- input2 resd 1
25first.asm (2/3)
- segment .text
- global _asm_main
- _asm_main
- enter 0,0 setup routine
- pusha
- mov eax, prompt1 print out
prompt - call print_string
- call read_int read
integer - mov input1, eax store into
input1 - mov eax, prompt2 print out
prompt - call print_string
- call read_int read
integer - mov input2, eax store into
input2 - ...
26first.asm (3/3)
- mov eax, input1 eax dword at
input1 - add eax, input2 eax dword at
input2 - mov ebx, eax ebx eax
- mov eax, outmsg1
- call print_string print out
first message - mov eax, input1
- call print_int print out
input1 - mov eax, outmsg2
- call print_string print out
second message - mov eax, input2
- call print_int print out
input2 - mov eax, outmsg3
- call print_string print out
third message - mov eax, ebx
- call print_int print out
sum (ebx) - call print_nl print
new-line - popa
- mov eax, 0 return back to C
27