1 / 10

ECE 291

ECE 291. Lecture 5: x86 Instructions: Control Flow Constantine D. Polychronopoulos Professor, ECE Office: 463 CSRL. Spring 2000. Branch Instructions. Case Statements. CMP AX, BX JNE Case 2 <Do case 1> JMP Done Case 2: SUB AX, DX CMP AX, BX JNE Case 3

cecily
Télécharger la présentation

ECE 291

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. ECE 291 Lecture 5: x86 Instructions: Control Flow Constantine D. Polychronopoulos Professor, ECE Office: 463 CSRL Spring 2000 ECE 291 -- Spring 2000

  2. Branch Instructions ECE 291 -- Spring 2000

  3. Case Statements CMP AX, BX JNE Case 2 <Do case 1> JMP Done Case 2: SUB AX, DX CMP AX, BX JNE Case 3 <Do case 2> JMP Done . . . . . . Done: <Continue> ECE 291 -- Spring 2000

  4. Repeat/Until & While Looping -- LOOP instr. uses register CX to iterate -- CX is decremented and compared by the LOOP instr. -- Loop ends when CX=0 Example: MOV CX, Count loop_label: ... Loop Processing ... LOOP loop_label ECE 291 -- Spring 2000

  5. LOOP Instruction -LOOP uses CX register for successive decrements. It jumps back to loop if CX is not a zero - When CX becomes 0 control transfers to instruction immediately following the loop Example: ADDS PROC MOV CX, 100 MOV SI, offset block1 MOV DI, offset block2 Loop_label: LODSW ; get block1 data: AX=[SI]; SI=SI+2 ADD AX, ES:[DI] ; add block2 data STOSW ; store in block2: [DI]=AX; DI=DI+2 LOOP Loop_label ; repeat 100 times RET ADDS ENDP ECE 291 -- Spring 2000

  6. While Loop Example X86 Code: While_loop: MOV AX, J CMP AX, K JNGE Exit_loop DEC J INC K MOV AX, J IMUL AX, K MOV L, AX JMP While_loop Exit_loop: C-like Example: While (J>=K) do begin J:=J-1; K:=K+1; L=J*K; end; ECE 291 -- Spring 2000

  7. OPCODE MODE Displacement Data Immediate value Instruction Format & Semantics Instruction: Instruction fields: - OPCODE (1/2 bytes) - Mode (1 byte) - Data (1/2 bytes) - Displacement (1/2 bytes) Descriptor bit (D): - D=0: 16-bit instructions - D=1: 32-bit instructions ECE 291 -- Spring 2000

  8. Instruction Format & Semantics OPCODE: D - Direction of data transfers: - D = 0: data transfers from R/M field to Register - D = 0: data transfers TO the Register from R/M field in next byte W - Data size: - W=0: data size is a byte - W=1: data size is a word/double word | | | | | | D|W ECE 291 -- Spring 2000

  9. MOD Format 00 No displacement 01 8-bit sign-extended disp. 10 16-bit displacement 11 R/M is a register MOD REG R/M 2 3 3 MOD: Selecting Addressing Mode - MOD field: 1 byte that specifies the addressing mode + enables/disables displacement. - Only when MOD=11 R/M is a register specifier ECE 291 -- Spring 2000

  10. Code Function 000 DS: [BX+SI] 001 DS: [BX+DI] 010 SS: [BP+SI] 011 SS: [BP+DI] 100 DS: [SI] 101 DS: [DI] 110 SS: [BP] 111 DS: [BX] R/M Field: Selecting Addressing Mode -If MOD is 00, 01, 10, then R/M does not specify a register operand, but memory addressing mode: Examples: 1. If MOD=00 and R/M=101: addressing mode is [DI] 2. If MOD=01 and R/M=101 addressing mode is [DI +disp] 3. If MOD=10 and R/M=101 addressing mode is disp1[DI+disp2] ECE 291 -- Spring 2000

More Related