1 / 22

ECE 353 Introduction to Microprocessor Systems

ECE 353 Introduction to Microprocessor Systems. Michael G. Morrow, P.E. Week 5. Flags Register Bit manipulation Logical Instructions Shift/Rotate Instructions Branching Conditional Unconditional Looping Structured Programming Stack Allocation and Operation. Objectives. FLAGS Register.

velika
Download Presentation

ECE 353 Introduction to Microprocessor Systems

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 353Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 5

  2. Flags Register Bit manipulation Logical Instructions Shift/Rotate Instructions Branching Conditional Unconditional Looping Structured Programming Stack Allocation and Operation Objectives

  3. FLAGS Register • aka the Processor Status Word (PSW) • A ‘flag’ is generally a marker used to indicate or record some condition. • PSW contains 6 status flags … • AF, CF, OF, PF, SF, ZF • … and 3 control flags • DF, IF, TF

  4. PSW Status Flags • The status flags reflect the result of the previous logical or arithmetic operation. • AF – indicates a carry or borrow between the high and low nibbles of the accumulator, used for BCD. • CF – indicates a carry from, or a borrow to, the MSb of an arithmetic result • Can also modify directly with CLC / CMC / STC to use as a Boolean status bit. • OF – an arithmetic overflow has occurred • PF – set if the operation resulted in even parity • SF – set if the result is negative (i.e. MSb = 1) • ZF – set if the result is zero

  5. Control Flags • The control flags control certain aspects of the processor’s execution • DF – direction flag • Determines the direction of pointer modifications in string operations. If DF=0, then increment pointers, otherwise decrement. • IF – interrupt enable flag • If set, the processor can recognize maskable interrupts. • TF – trap flag • If set, the processor will execute in single-step mode.

  6. Logical Instructions • Logical instructions operate bit-wise. • NOT does not affect flags.

  7. Bit Manipulation • Clearing bit(s) - AND • Set desired bits to 0 in mask • All other bits in mask to 1 • Setting bit(s) - OR • Set desired bits to 1 in mask • All other bits in mask to 0 • Toggling bit(s) - XOR • Set desired bits to 1 in mask • All other bits in mask to 0 • Read-modify-write issues

  8. Shift Instructions • Arithmetic versus logical shifts • Shift count source • 1 • CL • Immediate byte (new to 80186 instruction set)

  9. Rotate Instructions • Rotate count sources • Using rotate instruction to swap nibbles • Execution time dependent on count

  10. Unconditional Jumps • Redirect program flow by loading a new IP (and possibly a new CS) value. • Syntax: jmp target • Label attributes • Target by direct addressing • Target by indirect addressing • Jump tables • Be sure index is bounds-checked! • FAR versus NEAR jump tables

  11. Conditional Jumps • Allow program flow to change in response to conditions. • Action is based on current state of flags. • Syntax: j<X> short-label • <X> is mnemonic for condition to test. • All conditional jumps are short. • Can use double jumps if target out of range. • Prior instruction must be used to set flags • Examples

  12. Looping • Can use backwards conditional jumps to create a loop that can be terminated - • By a condition • After a predetermined number of iterations • Or a combination of both

  13. Looping • Can use the LOOP instructions • CX is loop control variable • GPP: Don’t modify CX in loop

  14. Implementing Structured Programming Constructs • Structured programming basics • One entry point, one exit point per procedure (subroutine) • Based on three basic control structures • Repetition • Selection • If, If/Else, Switch/Case • Repetition • While • Do-While • Flowchart Basics

  15. Repeated String Instructions • String instructions become very useful when used with the REP prefix • REP, REPE/REPZ, REPNE/REPNZ • Pointer modification based on DF (CLD, STD). • CX is always loop variable for repeated string instructions • CMPS order of evaluation is reversed from CMP!

  16. Records • Provides a syntax for creating and accessing bit-encoded data structures. • Syntax • name RECORD field_name:exp[=init_val][,…] • Operations • MASK • Creates a mask for the bit-field identified • Shift • Using the bit-field name is interpreted as a right shift count to move that field to the LSB • WIDTH • Returns number of bits in a record or field

  17. Stack Implementation • Stack is a LIFO data structure. • Who uses the stack? • Subroutine return addresses • Passed parameters • Temporary memory allocation • Two basic operations • PUSH • POP • Hardware stacks vs. memory stacks • Stack pointer • A dedicated register to use exclusively to access the stack

  18. 80C188EB Stack Operation • Stack is defined by SS:SP • Allocating stack space • Stack operations • All stack operations are 16-bit transfers • PUSH / PUSHA / PUSHF • POP / POPA / POPF • CALL / RETURN • ENTER / LEAVE • Example

  19. Wrapping Up • Homework #3 due Friday, October 12th • Exam 1 will be held on Thursday, October 18, 2001 from 7:15 to 8:45 PM in 132 Noland

  20. Exercise Write a code fragment that implements the C function strchr, which finds a given character in an ASCIIZ string. strchr scans the string in the forward direction, looking for the specified character and finds the first occurrence of the character in the string. The null-terminator is considered to be part of the string. Assume the following conditions: AL - character to search for DS:DI - address of null-terminated string to search (string must not start at offset of zero!) If found, set AX = equal offset of first occurrence, otherwise set AX = 0.

  21. Read-Modify-Write Issues Remove bubbles for memory-mapped I/O.

More Related