1 / 26

Fredy A.Sihombing M.Kom

ini bahan kuliah untuk mata kuliah Arsitektur dan Organisasi Komputer,Fakultas Teknik Dan Ilmu Kompter 2012/2013

guest50788
Download Presentation

Fredy A.Sihombing M.Kom

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ArsitekturdanOrganisasiKomputer FakultasTeknik & IlmuKomputer 2012/2013 Sumber:1. Paul Carter, PC Assembly Language2. Hamacher. Computer Organization, ed-53. Materikuliah CS61C/2000 & CS152/1997, UCB4. Intel Architecture Software Developer’s Manual Disusun : FredyA.SihombingM.Kom

  2. KONVENSI

  3. Set Instruksi Intel x86 • OP-CODE DEST,SRC ; DEST  [SRC] OP [DEST] • Hanyasalahsatudari SRC atau DEST dapatberupa memory-operand • ACC: representasiuntuk AL/AX/EAX • Sebagianinstruksimenyebabkanperubahannilai FLAGS, khususnyainstruksi-instruksiAritmatika & Logika

  4. DATA TRANSFER INSTRUCTIONS

  5. Data Transfer Instructions • General-purpose data movement • Move • Conditional Move • Exchange • Stack manipulation • Type-conversion

  6. Data Transfer Instructions: • 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 belowor equal • CMOVAE/CMOVNB Conditional move if above or equal/Conditional move ifnot below • CMOVB/CMOVNAE Conditional move if below/Conditional move if not aboveor 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 • CMOVNP/CMOVPO Conditional move if not parity/Conditional move if parity odd

  7. Data Transfer Instructions: Summary • 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

  8. Data 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

  9. Format Instruksi MOV (1/2) REG/MEM  [REG] • MOV r/m8,r8Move r8 to r/m8 • MOV r/m16,r16Move r16 to r/m16 • MOV r/m32,r32Move r32 to r/m32 REG  [REG/MEM] • MOV r8,r/m8Move r/m8 to r8 • MOV r16,r/m16Move r/m16 to r16 • MOV r32,r/m32Move r/m32 to r32 REG/MEM  [SEG-REG] • MOV r/m16,SregMove segment register to r/m16 SEG-REG  [REG/MEM] • MOV Sreg,r/m16Move r/m16 to segment register

  10. Format Instruksi MOV (2/2) AL/AX/EAX  [MEM] • MOV AL,moffs8Move byte at (seg:offset) to AL • MOV AX,moffs16Move word at (seg:offset) to AX • MOV EAX,moffs32Move doubleword at (seg:offset) to EAX MEM  [AL/AX/EAX] • MOV moffs8,ALMove AL to (seg:offset) • MOV moffs16,AXMove AX to (seg:offset) • MOV moffs32,EAXMove EAX to (seg:offset) REG  IMM • MOV r8,imm8Move imm8 to r8 • MOV r16,imm16Move imm16 to r16 • MOV r32,imm32Move imm32 to r32 [REG/MEM]  IMM • MOV r/m8,imm8Move imm8 to r/m8 • MOV r/m16,imm16Move imm16 to r/m16 • MOV r/m32,imm32Move imm32 to r/m32

  11. Data Transfer Instructions: Conditional Move

  12. Format Instruksi CMOVcc • CMOVA r16, r/m16Move if above (CF=0 and ZF=0) • CMOVA r32, r/m32Move if above (CF=0 and ZF=0) • CMOVAE r16, r/m16Move if above or equal (CF=0) • CMOVAE r32, r/m32Move if above or equal (CF=0) • CMOVB r16, r/m16Move if below (CF=1) • CMOVB r32, r/m32Move if below (CF=1) • CMOVBE r16, r/m16Move if below or equal (CF=1 or ZF=1) • CMOVBE r32, r/m32Move if below or equal (CF=1 or ZF=1) • CMOVC r16, r/m16Move if carry (CF=1) • CMOVC r32, r/m32Move if carry (CF=1) • CMOVE r16, r/m16Move if equal (ZF=1) • CMOVE r32, r/m32Move if equal (ZF=1)

  13. Data Transfer Instructions: Exchange • XCHG DEST,SRC ;Exchange • [DEST] ↔ [SRC] • BSWAP R32 ;Byte swap • R32[7..0] ↔R32[31..24] • R32[15..8] ↔R32[23..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 ([EDX:EAX] ==[DEST]) { ZF ← 1; DEST ← [ECX:EBX] } ELSE { ZF ← 0; EDX:EAX ← [DEST] }

  14. Format Instruksi XCHG • XCHG AX,r16Exchange r16 with AX • XCHG r16,AXExchange AX with r16 • XCHG EAX, r32Exchange r32 with EAX • XCHG r32, EAXExchange EAX with r32 • XCHG r/m8, r8Exchange r8 with byte from r/m8 • XCHG r8, r/m8Exchange byte from r/m8 with r8 • XCHG r/m16, r16Exchange r16 with word from r/m16 • XCHG r16, r/m16Exchange word from r/m16 with r16 • XCHG r/m32, r32Exchange r32 with doubleword from r/m32 • XCHG r32, r/m32Exchange doubleword from r/m32 with r32

  15. Format Instruksi BSWAP & XADD • BSWAP r32Reverses the byte order of a 32-bit register. • XADD r/m8, r8Exchange r8 and r/m8; load sum into r/m8. • XADD r/m16, r16Exchange r16 and r/m16; load sum into r/m16. • XADD r/m32, r32Exchange r32 and r/m32; load sum into r/m32.

  16. Format Instruksi CMPXCHG & CMPXCHG8B • CMPXCHG r/m8,r8Compare AL with r/m8. If equal,ZF is set and r8 is loadedintor/m8. Else, clear ZF and load r/m8into AL. • CMPXCHG r/m16,r16Compare AX with r/m16. If equal,ZF is set and r16 isloaded intor/m16. Else, clear ZF and loadr/m16 into AX • CMPXCHG r/m32,r32Compare EAX with r/m32. Ifequal, ZF is set and r32 isloadedinto r/m32. Else, clear ZF andload r/m32 into EAX • CMPXCHG8B m64Compare EDX:EAX with m64. Ifequal, set ZF and loadECX:EBXinto m64. Else, clear ZF and loadm64 intoEDX:EAX.

  17. Data Transfer Instructions: Stack Manipulation • PUSH SRC ; Push onto stack ; GP-regs, SEG-regs, MEM, Immd. • ESP  [ESP] – 4/2 • [ESP]  [SRC]

  18. Format Instruksi PUSH • PUSH r/m16Push r/m16 • PUSH WORD [DATA] • PUSH r/m32Push r/m32 • PUSH DWORD [DATA] • PUSH r16Push r16 • PUSH r32Push r32 • PUSH imm8Push imm8 • PUSH imm16Push imm16 • PUSH imm32Push imm32 • PUSH CSPush CS • PUSH SSPush SS • PUSH DSPush DS • PUSH ESPush ES • PUSH FSPush FS • PUSH GSPush GS

  19. Data Transfer Instructions: Stack Manipulation • POP DEST ; Pop off of stack ; GP-regs, SEG-regs (-CS), MEM • DEST  [[ESP]] • ESP  [ESP] + 4/2

  20. Format Instruksi POP • POP r/m16Pop top of stack into m16; increment stack pointer • POP WORD [DATA] • POP r/m32Pop top of stack into m32; increment stack pointer • POP DWORD [DATA] • POP r16Pop top of stack into r16; increment stack pointer • POP r32Pop top of stack into r32; increment stack pointer • POP DSPop top of stack into DS; increment stack pointer • POP ESPop top of stack into ES; increment stack pointer • POP SSPop top of stack into SS; increment stack pointer • POP FSPop top of stack into FS; increment stack pointer • POP GSPop top of stack into GS; increment stack pointer

  21. Data Transfer Instructions: Stack Manipulation • PUSHA/PUSHAD ; Push (16-/32-bit) GP-regs onto stack • POPA/POPAD ; Pop (16-/32-bit) GP-regsfrom stack

  22. Data Transfer Instructions: Type Conversion • CBW ; Convert byte to word • AX ← SignExtend[AL] • CWD ; Convert word to doubleword • DX:AX ← SignExtend[AX] • CWDE ; Convert word to doubleword • EAX ← SignExtend[AX] • CDQ ; Convert doubleword to quadword • EDX:EAX ← SignExtend[EAX] • MOVSX DEST,SRC ; Move and sign extend • DEST ← SignExtend[SRC] • MOVZX DEST,SRC ; Move and zero extend • DEST ← ZeroExtend[SRC]

  23. Format Instruksi MOVSX & MOVZX • MOVSX r16,r/m8Move byte to word with sign-extension • MOVSX r32,r/m8Move byte to doubleword, sign-extension • MOVSX r32,r/m16Move word to doubleword, sign-extension • MOVZX r16,r/m8Move byte to word with zero-extension • MOVZX r32,r/m8Move byte to doubleword, zero-extension • MOVZX r32,r/m16Move word to doubleword, zero-extension

  24. first.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

  25. first.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 • ...

  26. first.asm (3/3) • moveax, [input1]; eax = dword at input1 • addeax, [input2]; eax += dword at input2 • movebx, 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 • moveax, 0; return back to C • leave • ret

More Related