1 / 20

16.317: Microprocessor System Design I

16.317: Microprocessor System Design I. Instructor: Dr. Michael Geiger Spring 2012 Lecture 12: Instruction sequence examples. Lecture outline. Announcements/reminders Graded HW 1 available HW 2 due today Lab 1 due 2/29 Amanda’s OH: M/W 2:30-5, Tuesday 5-7 in Ball 407 Exam 1: Friday, 2/24

ely
Download Presentation

16.317: Microprocessor System Design I

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. 16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 12: Instruction sequence examples

  2. Lecture outline • Announcements/reminders • Graded HW 1 available • HW 2 due today • Lab 1 due 2/29 • Amanda’s OH: M/W 2:30-5, Tuesday 5-7 in Ball 407 • Exam 1: Friday, 2/24 • Review lecture Wednesday, 2/22 • Will be allowed calculator, one 8.5”x11” sheet of notes • No class Monday, 2/20 • Lecture outline • Review: shift/rotate instructions • Today: more practice with sequences of instructions Microprocessors I: Lecture 12

  3. Review: shift instructions • Basic shift instructions • Move value by <amt> bits; add 0s to left or right • CF = last bit shifted out • SHL <src>, <amt>: Move <src> to left • SAL exactly the same • SHR <src>, <amt>: Move <src> to right • Arithmetic right shift • Move value right by <amt> bits • Copy sign bit to fill remaining bits • CF = last bit shifted out • SAR <src>, <amt> Microprocessors I: Lecture 12

  4. Review: rotate instructions • Rotate instructions: bits that are shifted out one side are shifted back in other side • ROL <src>, <amt> or ROR <src>, <amt> • CF = last bit rotated • Rotate through carry instructions • CF acts as “extra” bit that is part of value being rotated • RCL <src>, <amt> Microprocessors I: Lecture 12

  5. Rotate example • Given AL = 43H, CL = 04H, and CF = 0, show the state of AL after each instruction in the sequence below: • ROR AL, 2 • ROL AL, CL • RCR AL, 3 • RCL AL, 4 Microprocessors I: Lecture 12

  6. Solution • Initially, AL = 43H = 010000112 • ROR AL, 2 • AL = 01000011 rotated right by 2 = 11010000 = D0H • CF = last bit rotated in = 1 • ROL AL, CL • AL = 11010000 rotated left by 4 = 00001101 = 0DH • CF = last bit rotated in = 1 Microprocessors I: Lecture 12

  7. Solution (cont.) • RCR AL, 3 • (AL,CF) = 00001101 1 rotated right by 3 = 01100001 1 • CF = 1, AL = 011000012 = 61H • RCL AL, 4 • (CF,AL) = 1 01100001 rotated left by 4 = 0 00011011 • CF = 0, AL = 000110112 = 1BH Microprocessors I: Lecture 12

  8. Instruction sequence examples: initial state • EAX: 00000000H • EBX: 00000000H • ECX: 00000000H • EDX: 00000000H • ESI: 00000000H • EDI: 00000000H • EBP: 00000000H • ESP: 00000000H • DS: 1000H • SS: 0000H Microprocessors I: Lecture 12

  9. Sequence Example 1 • Show the results of the following sequence • LDS SI, [0100H] • LSS DI, [SI] • MOV SP, FFFEH • MOV BP, SP Microprocessors I: Lecture 12

  10. Sequence Example 1: solution • LDS SI, [0100H] • SI = word from DS:0100H = word from10100H = 0004H • DS = word from DS:0102H = word from 10102H = 1010H • LSS DI, [SI] • DI = word from DS:SI = word from 10104H = 0012H • SS = word from DS:SI+2 = word from 10106H = 4020H • MOV SP, FFFEH • MOV BP, SP • BP = SP = FFFEH Microprocessors I: Lecture 12

  11. Instruction sequence examples: state after sequence 1 • EAX: 00000000H • EBX: 00000000H • ECX: 00000000H • EDX: 00000000H • ESI: 00000004H • EDI: 00000012H • EBP: 0000FFFEH • ESP: 0000FFFEH • DS: 1010H • SS: 4020H Microprocessors I: Lecture 12

  12. Sequence Example 2 • Show the results of the following sequence • MOV CX, [SI+0004H] • MOV AX, [SI+000CH] • SHL AX, CL • ADD AX, [SI+000CH] • ADD AX, [SI+000CH] • MOV [DI], AX Microprocessors I: Lecture 12

  13. Sequence Example 2: solution • MOV CX, [SI+0004H] • CX = word at DS:SI+0004H = word at 10108H = 0002H • MOV AX, [SI+000CH] • AX = word at DS:SI+000CH = word at 10110H = 001EH • SHL AX, CL • AX = AX << (CL) = 001EH << 2 = 0078H Microprocessors I: Lecture 12

  14. Sequence Example 2: solution • ADD AX, [SI+000CH] • AX = AX + word at DS:SI+000CH = 0078H + 001EH = 0096H • ADD AX, [SI+000CH] • AX = AX + word at DS:SI+000CH = 0096H + 001EH = 00B4H • MOV [DI], AX • Word at DS:DI = AX • DS:DI = 10100H + 0012H = 10112H • Word at 10112H = 00B4H Microprocessors I: Lecture 12

  15. Instruction sequence examples: state after sequence 2 • EAX: 000000B4H • EBX: 00000000H • ECX: 00000002H • EDX: 00000000H • ESI: 00000004H • EDI: 00000012H • EBP: 0000FFFEH • ESP: 0000FFFEH • DS: 1010H • SS: 4020H Microprocessors I: Lecture 12

  16. Instruction sequence examples: state before sequence 3 • Some time later, assume: • EAX: 000000B4H • EBX: 00000000H • ECX: 00000002H • EDX: 00000000H • ESI: 00000004H • EDI: 00000012H • EBP: 0000FFF8H • ESP: 0000FFF4H • DS: 1010H • SS: 4020H • Memory from 10100-10116 unchanged Microprocessors I: Lecture 12

  17. Sequence Example 3 • Show the results of the following sequence • MOV SI,SS:[BP+0004H] • MOV DI,SS:[BP+0006H] • MOV AX,[SI] • XCHG [DI],AX • XCHG DI,SI • MOV [DI],AX Microprocessors I: Lecture 12

  18. Sequence Example 3: solution • MOV SI,SS:[BP+0004H] • Note: if BP is base register, SS is implied • SI = word at SS:BP+0004H = word at 501FCH = 000AH • MOV DI,SS:[BP+0006H] • DI = word at SS:BP+0006H = word at 501FEH = 000CH • MOV AX,[SI] • AX = word at DS:SI = word at 1010A = 1600H • XCHG [DI],AX • Swap contents of AX with word at DS:DI (address 1010C) • AX = 0317H, word at 1010C = 1600H • XCHG DI,SI • Swap DI and SI  DI = 000AH, SI = 000CH • MOV [DI],AX • Word at DS:DI = contents of AX • Word at 1010AH = 0317H Microprocessors I: Lecture 12

  19. Instruction sequence examples: state after sequence 3 • EAX: 00000317H • EBX: 00000000H • ECX: 00000002H • EDX: 00000000H • ESI: 0000000CH • EDI: 0000000AH • EBP: 0000FFF8H • ESP: 0000FFF4H • DS: 1010H • SS: 4020H Microprocessors I: Lecture 12

  20. Next time • Exam 1 Preview (on Wednesday) • Remember, no class Monday Microprocessors I: Lecture 12

More Related