ECE 353 Introduction to Microprocessor Systems

Slides:



Advertisements
Similar presentations
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Advertisements

Computer Organization & Assembly Language
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
Microprocessor Programming II
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
11.1/36 Repeat: From Bits and Pieces Till Strings.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 5.
Types of Registers (8086 Microprocessor Based)
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 7.
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
Logical and Bit Operations Chapter 9 S. Dandamudi.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 5.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Microprocessor Systems Design I
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language Programming of 8085
16.317: Microprocessor System Design I
Homework Reading Labs PAL, pp
Introduction to 8086 Microprocessor
Practical Session 2.
Microprocessor Systems Design I
8086 Microprocessor.
Chapter instruction description and assembler directives from Microprocessors and Interfacing by Douglas Hall.
Today we are going to discuss about,
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INSTRUCTION SET.
Machine control instruction
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
# include < stdio.h > v oid main(void) { long NUM1[5]; long SUM; long N; NUM1[0] = 17; NUM1[1] = 3; NUM1[2] =  51; NUM1[3] = 242; NUM1[4] = 113; SUM =
Intel 8088 (8086) Microprocessor Structure
UNIT: 2 INSTRUCTION SET OF 8086.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Flags Register & Jump Instruction
Intel 8088 (8086) Microprocessor Structure
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
Chapter 8 Central Processing Unit
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
Shift & Rotate Instructions)
EECE.3170 Microprocessor Systems Design I
Microprocessor and Assembly Language
Assembly Language for Intel 8086 Jump Condition
CNET 315 Microprocessor & Assembly Language
Chapter 7 –Program Logic and Control
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Presentation transcript:

ECE 353 Introduction to Microprocessor Systems Week 5 Michael J. Schulte

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

80C188EB Processor Status Word (PSW) 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 80C188EB Processor Status Word (PSW) 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 -- OF DF IF TF SF ZF AF PF CF

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

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.

Logical Instructions Logical instructions operate bit-wise. NOT does not affect flags. Mnemonic Operands Function O S Z A P C NOT dst Logical complement - AND dst,src Logical AND  ? OR Logical OR XOR Logical exclusive OR TEST Non-destructive AND

Questions? What logical operations would be necessary to Check the state of a single bit? Check if multiple bits are 1? Check if certain bits have desired states? Set a bit or bits? Clear a bit or bits? Toggle a bit or bits?

Bit Manipulation Clearing bit(s) - AND Setting bit(s) - OR 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 Read-modify-write issues

Shift Instructions Arithmetic versus logical shifts Shift count source 1 CL Immediate byte (new to 80186 instruction set) Mnemonic Operands Function O S Z A P C SHL dst, cnt Shift logical left *  ? SAL Shift arithmetic left SHR Shift logical right SAR Shift arithmetic right

Rotate Instructions Rotate count sources same as shifts Using rotate instruction to swap nibbles Execution time dependent on count Mnemonic Operands Function O S Z A P C ROL dst, cnt Rotate left * -  ROR Rotate right RCL Rotate through carry left RCR Rotate through carry right

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

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

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 Mnemonic Operands Function O S Z A P C INC dst Increment  - DEC Decrement CMP dst, src Compare (dst – src, nondestructive)

Looping Can use the LOOP instructions CX is loop control variable O S Warning: modifying CX in the loop can be disastrous Mnemonic Operands Function O S Z A P C LOOP shrt_lbl DEC CX JNZ - LOOPE LOOPZ Loop while CX <> 0 and ZF = 1 (last operation was zero) LOOPNE LOOPNZ Loop while CX <> 0 and ZF = 0 (last operation was not zero)

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

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! Mnemonic Operands Function O S Z A P C SCAS dst_s Scan string (AL – ES:DI)  CMPS Compare string (DS:SI – ES:DI)

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

Stack Implementation Stack is a LIFO data structure. What uses the stack? Subroutine return addresses Passed parameters Temporary memory allocation Two basic stack operations PUSH POP Hardware stacks vs. memory stacks Hardware stack Memory stack pointer Stack pointer

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

Wrapping Up Homework #3 is due Friday, March 4, 2005. Exam #1 will be held on Wednesday, February 13th, 2005 from 7:15 to 8:45PM in room 1227 Engineering Hall. One 8.5x11 sheet with original, handwritten notes. Instruction set guide will be provided. For next time week read Ch. 8.3-8.5, 8.8, 9.

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 initial 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.

Mnemonic Jump if condition Flags for condition JA/JNBE Above / not below or equal (CF OR ZF) = 0 JAE/JNB Above or equal / not below CF = 0 JB/JNAE Below / not above or equal CF = 1 JBE/JNA Below or equal / not above (CF OR ZF) = 1 JC Carry JCXZ Jump if CX equal 0 CX = 0 (uses register) JE/JZ Equal / zero ZF = 1 JB/JLNE Below / not less nor equal ((SF XOR OF) OR ZF) = 0 JGE/JNL Greater or equal / not less (SF XOR OF) = 0 JL/JNGE Less / not greater nor equal (SF XOR OF) = 1 JNC No carry JNE/JNZ Not equal / not zero ZF = 0 JNO Not overflow OF = 0 JNP/JPO Not parity / parity odd PF = 0 JNS Not sign (positive) SF = 0 JO Overflow OF = 1 JP/JPE Parity / parity even PF = 1 JS Sign (negative) SF = 1

Read-Modify-Write Issues

PIC16F84 Hardware Stack