Microprocessors and Microcontrollers CPU & ALU EE3954. by Maarten Uijt de Haag, Tim Bambeck, Harsha Chenji CPU & ALU.1

Similar documents
Flow Charts & Assembly Language

Section 29. Instruction Set

PIC Programming in Assembly. (

10-bit Σ ADC from a PIC16F84

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

How To Program A Microcontroller With Memory On A Microchip Microcontroller

AN727. Credit Card Reader Using a PIC12C509 DATA ENCODING INTRODUCTION FIGURE 1: POSITION OF ISO TRACKS 1, 2 AND 3. Andrew M Errington

Embedded C Programming

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

c0003 A Simple PIC Application CHAPTER 3

PIC12F508/509/16F505 Data Sheet

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Using The PIC I/O Ports

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

MICROPROCESSOR AND MICROCOMPUTER BASICS

PIC16F84A. 18-pin Enhanced Flash/EEPROM 8-Bit Microcontroller. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

Microprocessor & Assembly Language

Introduction to Microcontrollers

Four-Channel Digital Voltmeter with Display and Keyboard. 8 x 220W RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RA0 RA1 RA2 RA3 PIC16C71

PIC16F8X. 18-pin Flash/EEPROM 8-Bit Microcontrollers. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

Chapter 13. PIC Family Microcontroller

(Refer Slide Time: 00:01:16 min)

Section 9. I/O Ports

PIC in Practice. A Project-Based Approach. D. W. Smith

Section 8. Interrupts

PIC16F526 Data Sheet. 14-Pin, 8-Bit Flash Microcontroller Microchip Technology Inc. Preliminary DS41326A

Central Processing Unit (CPU)

PIC16F84A Data Sheet. 18-pin Enhanced FLASH/EEPROM 8-bit Microcontroller Microchip Technology Inc. DS35007B

PIC16F5X Data Sheet. Flash-Based, 8-Bit CMOS Microcontroller Series Microchip Technology Inc. DS41213D

Quick Reference. B.5 12-Bit Core Instruction Set APPENDICES

An Introduction to MPLAB Integrated Development Environment

PIC10F200/202/204/206 Data Sheet

MACHINE ARCHITECTURE & LANGUAGE

SSPBUF. Shift Clock SSPSR. START bit, STOP bit, Acknowledge Generate

Analog-to-Digital Converters

Memory organization. Memory blocks: Program memory (flash-type) 16 kword (32 kbyte) (instruction 16 bit wide) Data RAM 1536 byte (1.

LSN 2 Computer Processors

I 2 C Master Mode Overview and Use of the PICmicro MSSP I 2 C Interface with a 24xx01x EEPROM

Chapter 5 Instructor's Manual

CHAPTER 4 MARIE: An Introduction to a Simple Computer

Section 14. Compare/Capture/PWM (CCP)

Section 28. In-Circuit Serial Programming (ICSP )

8051 MICROCONTROLLER COURSE

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Building A RISC Microcontroller in an FPGA

Chapter 2: Assembly Language Programming. The PIC18 Microcontroller. Han-Way Huang

Computer organization

AN880. Converting from 8051 to Microchip Assembler: A Quick Reference INTRODUCTION

İSTANBUL AYDIN UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877

AN857. Brushless DC Motor Control Made Easy INTRODUCTION S 001 B. Anatomy of a BLDC SIMPLIFIED BLDC MOTOR DIAGRAMS

EE25M Introduction to microprocessors. Solutions & study tips. original author: Feisal Mohammed updated: 4th March 2002 CLR

PART B QUESTIONS AND ANSWERS UNIT I

ET-BASE AVR ATmega64/128

AN857. Brushless DC Motor Control Made Easy INTRODUCTION S 001 B. Anatomy of a BLDC SIMPLIFIED BLDC MOTOR DIAGRAMS. Microchip Technology Inc.

Summary of the MARIE Assembly Language

Simple Alarm System WIRELESS AND REMOTE CONTROLLED PERSONAL APPLIANCE CODE WORD ORGANIZATION TRANSMISSION FORMAT

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

EXERCISE 3: String Variables and ASCII Code

ARM Cortex-M3 Assembly Language

Programming Logic controllers

Keil C51 Cross Compiler

PIC12F519 Data Sheet. 8-Pin, 8-Bit Flash Microcontrollers

CHAPTER 6: Computer System Organisation 1. The Computer System's Primary Functions

AN585. A Real-Time Operating System for PICmicro Microcontrollers INTRODUCTION. Why do I Need a Real-Time Kernel? What is Multitasking Anyway?

Lecture N -1- PHYS Microcontrollers

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

8051 hardware summary

Introduction to MPLAB IDE

Microprocessor and Microcontroller Architecture

PIC16CR7X Data Sheet. 28/40-Pin, 8-Bit CMOS ROM Microcontrollers Microchip Technology Inc. DS21993A

8-Bit CMOS Microcontrollers with A/D Converter

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

PIC16F627A/628A/648A Data Sheet

AN657. Decoding Infrared Remote Controls Using a PIC16C5X Microcontroller INTRODUCTION HARDWARE DESCRIPTION THE THREE LAYERS OF AN INFRARED SIGNAL

Chapter 2 Logic Gates and Introduction to Computer Architecture

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

PIC12F510/16F506 Data Sheet

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

PIC16F62X. FLASH-Based 8-Bit CMOS Microcontrollers. Devices included in this data sheet: Special Microcontroller Features: High Performance RISC CPU:

EMBEDDED SYSTEM BASICS AND APPLICATION

Microcontrollers A Brief History of Microprocessors

Byte code Interpreter for 8051 Microcontroller

First Steps. with. Embedded Systems. Byte Craft Limited. ox40; gs&0x20) table(); 02A4 A 02A6 B 02A9 C

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

PIC12F629/675 Data Sheet

Programmable State-Variable Filter Design For a Feedback Systems Web-Based Laboratory

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

CPU Organization and Assembly Language

Chapter 01: Introduction. Lesson 02 Evolution of Computers Part 2 First generation Computers

PIC16F627A/628A/648A Data Sheet

Microcontrollers Figure 26-1 Objectives Key Words and Terms 26.1 OVERVIEW OF THE MICROCONTROLLER microcontroller

CSE 141L Computer Architecture Lab Fall Lecture 2

M68HC05. Microcontrollers MC68HC705J1A MC68HRC705J1A MC68HSC705J1A MC68HSR705J1A. Technical Data

EC 362 Problem Set #2

Transcription:

Microprocessors and Microcontrollers CPU & ALU EE3954 by Maarten Uijt de Haag, Tim Bambeck, Harsha Chenji CPU & ALU.1

So far Oscillator (Section 2) To generate the device clock which is necessary for the device to execute instructions and for the peripherals to perform their functions Architecture (Section 4) CPU & ALU.2

Program Bus EPROM Program Memory Up to k x 14 14 13 Program Counter -Level Stack (13-bit) RAM File Registers Up to 36 x Data Bus PORTA RA0 RA1 RA2 RA3 RA4 RA5 PORTB OSC1/CLKIN OSC2/CLKOUT Instruction Register Instruction Decode & Control Timing Generation Internal RC Clock 7 Power-Up Timer Oscillator Startup Timer Power-On Reset Watchdog Timer Brown-out Reset Address MUX FSR Register STATUS Register 3 MUX ALU W Register PORTC RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RC0 RC1 RC2 RC3 RC4 RC5 RC6 RC7 CPU & ALU.3

Now CPU & ALU (Reference Manual - Section 5) Instruction Set Instruction Format Arithmetic and Logic Unit (ALU) STATUS Central Processing Unit (CPU) Assembly Language Programming using MPLAB CPU & ALU.4

Instruction Set Instruction Set: the language you use to talk to a specific computer or a set of instructions used to tell a computer what functions/procedures to perform Instruction Set Architecture: what kind of instructions does the instruction set consist of. CPU & ALU.5

Instruction Set PICMicro Microcontrollers Byte-oriented File Register* Operations Program Bus EPROM Program Memory Up to k x 14 14 13 Bit-oriented File Register Operations Program Counter -Level Stack (13-bit) RAM File Registers Up to 36 x Data Bus Literal and Control Operations PORTA RA0 RA1 RA2 RA3 RA4 RA5 Instruction Register * Part of data memory 7 Address MUX PORTB RB0 RB1 CPU & ALU.6

Instruction Set - Byte Oriented CPU & ALU.7

Instruction Set Bit Oriented CPU & ALU.

Instruction Set Literal and Control Operations CPU & ALU.9

Arithmetic and Logic Unit (ALU) Addition Subtraction Shift Logical Clear addwf, addlw, incf subwf, sublw, decf rlf, rrf andwf, xorwf, iorwf, andlw, xorlw, iorlw, comf clrf CPU & ALU.10

Arithmetic and Logic Unit (ALU) -bit literal -bit register value W Register Special function registers (SFRs) for example PORTS And d bit or from instruction ALU MUX General Purpose Registers (GPR) from RAM If d = 0 result goes to W. For literal instructionsliteral goes to W. If d =1 result goes to file register. CPU & ALU.11

Program Bus EPROM Program Memory Up to k x 14 14 13 Program Counter -Level Stack (13-bit) RAM File Registers Up to 36 x Data Bus PORTA RA0 RA1 RA2 RA3 RA4 RA5 PORTB OSC1/CLKIN OSC2/CLKOUT Instruction Register Instruction Decode & Control Timing Generation Internal RC Clock 7 Power-Up Timer Oscillator Startup Timer Power-On Reset Watchdog Timer Brown-out Reset Address MUX FSR Register STATUS Register 3 MUX ALU W Register PORTC RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RC0 RC1 RC2 RC3 RC4 RC5 RC6 RC7 CPU & ALU.12

Arithmetic and Logic Unit (ALU) addlw 22h -bit literal: 22h -bit register value addlw 22h means w ß (w) + 22h d bit or from instruction W Register ALU MUX Special function registers (SFRs) And General Purpose Registers (GPR) d = 0 or literal instructions d =1 CPU & ALU.13

Destination Bit f: address of register in RAM (Register File) d: destination bit addwf 0x23, 1 means 0x23 ß (0x23) + W 1 F (register) 0 - W addwf 0x23, 0 means W ß (0x23) + W CPU & ALU.14

Arithmetic and Logic Unit (ALU) addwf 22h,0 Data Memory: -bit register value addwf 22h,0 means w ß (w) + (22h) d bit or from instruction W Register ALU MUX Special function registers (SFRs) And General Purpose Registers (GPR) d = 0 or literal instructions d =1 CPU & ALU.15

STATUS Register (0x03 in all banks) Contains the arithmetic status of the ALU, the RESET and the bank select bits (to be discussed in Section 6) ALU-related CPU & ALU.16

STATUS Register ALU Related bits CPU & ALU.17

STATUS Register CPU & ALU.1

Suppose w contains 34h. addlw 52h STATUS Example -addition 34h + 52h =? 0011 0100 0101 0010 -------------- 0 1000 0110 Not equal to zero, thus Z=0 Carry equal to zero, thus C=0 Carry from bit 3 to bit 4 is 0, thus DC=0 CPU & ALU.19

STATUS Example - subtraction Suppose w contains 34h. = 0011 0100 binary sublw 52h (subtract w from literal) 52h - 34h = 52h + (twos complement of 34h) 1100 1011 = ones complement of 34h 1 = add 1 ---------- 1100 1100 = twos complement of 34h 0101 0010 = 52h (2d) 1100 1100 = - 34h (-52d) -------------- 1 0001 1110 1Eh (30d) Z = 0 C = 1 DC = 0 Or, in decimal: 2-52 = 30 CPU & ALU.20

Assembly Example Suppose we want to perform the operation: 34h + 52h = 6h movlw 34h ; you need to use the w register!! addlw 52h ; result (6h) is stored in w Now using a temporary register called TEMP: TEMP equ 20h ; entry in register file (location 20h) movlw 34h ; you need to use the w register!! movwf TEMP ; move the value to Register TEMP movlw 52h ; store 52h in w addwf TEMP,1 ; add w and TEMP, put the result at TEMP CPU & ALU.21

Instruction Set Suppose there is an LED connected to pin RD1 (PORTD bit 1) as follows: RD1 R (470) bsf 0h,1 or, PORTD equ 0h bsf PORTD,1 CPU & ALU.22

Arithmetic and Logic Unit (ALU) bsf TEMP,5 (TEMP equ 20h) -bit literal -bit register value bsf TEMP,5 means TEMP<5> ß 1 d bit or from instruction W Register ALU MUX Special function registers (SFRs) And General Purpose Registers (GPR) d = 0 or literal instructions d =1 CPU & ALU.23

Another Example Suppose there is an LED connected to pin RC2 (PORTC bit 2) and a switch connected to RB0 (PORTB bit 0) as follows: V DD (5VDC ) R= 4.7 KΩ RB0 RC2 R (470) Write a program that, if the switch is closed, turns on the LED, and, if the switch is open, turns it off. CPU & ALU.24

Example Step 1: Need to check if the switch (RB0) is open or closed: If it is open V =? +5 V or Logic 1 If it is closed V =? 0 V or Logic 0 Step 2: How to check for this with an instruction? Hint: we need to check bit 0 of PORTB! Step 3: How to turn on or off the LED? If LED must be on RC2 must be V =? If LED must be off RC2 must be V =? +5V or Logic 1 0V or Logic 0 Step 4: Write the program. CPU & ALU.25

Example FLOW-CHART* Main if ( switch closed ) { turn on LED } else { turn off LED } Switch closed? Yes Turn on LED No Turn off LED *See the flow-chart guide! CPU & ALU.26

Example Alternative Flowchart Main Main Switch closed? No Switch closed? Yes No Yes Turn on LED Turn on LED Turn off LED Turn off LED CPU & ALU.27

Example Label Fields Mnemonic Fields Argument Fields Comment Fields TST btfss PORTB,0 ; port B bit 0 is tested goto LED_ON ; switch is closed (RB0=0) goto LED_OFF ; switch is open (RB0=1) LED_OFF bcf PORTC,2 ; turn LED off goto TST ; return to bit testing statement LED_ON bsf PORTC,2 ; turn on LED goto TST ; return to bit testing statement First example of branching (if..then )! CPU & ALU.2

Example Can it get any smaller? TST btfss PORTB,0 ; port B bit 0 is tested goto LED_ON ; switch is closed (RB0=0) goto LED_OFF ; switch is open (RB0=1) LED_OFF bcf PORTC,2 ; turn LED off goto TST ; return to bit testing statement LED_ON bsf PORTC,2 ; turn on LED goto TST ; return to bit testing statement TST btfss PORTB,0 ; port B bit 0 is tested goto LED_ON ; switch is closed (RB0=0) LED_OFF bcf PORTC,2 ; turn LED off goto TST ; return to bit testing statement LED_ON bsf PORTC,2 ; turn on LED goto TST ; return to bit testing statement CPU & ALU.29

Instructions 14-bit in Program Memory Program Bus EPROM Program Memory Up to k x 14 14 13 Program Counter -Level Stack (13-bit) RAM File Registers Up to 36 x Data Bus PORTA RA0 RA1 RA2 RA3 RA4 RA5 PORTB Instruction Register 7 Address MUX RB0 RB1 RB2 CPU & ALU.30

Instruction Format Conversion to Machine Code CPU & ALU.31

Instruction Set CPU & ALU.32

Instruction Set CPU & ALU.33

Arithmetic and Logic Unit (ALU) addlw 22h Instruction in Program Memory 1 1 1 1 1 0 0 0 1 0 0 0 1 0 -bit literal: 22h -bit register value literal k 22h = 0010 0010 b W Register Special function registers (SFRs) addlw 22h means w ß (w) + 22h d bit or from instruction ALU MUX And General Purpose Registers (GPR) d = 0 or literal instructions d =1 CPU & ALU.34

Arithmetic and Logic Unit (ALU) bsf TEMP,5 (TEMP equ 20h) Instruction in Program Memory 0 1 0 1 1 0 1 0 1 0 0 0 0 0 -bit literal -bit register value bit b 5 = 101b register f 20h = 0100000b W Register Special function registers (SFRs) And d bit or from instruction ALU MUX General Purpose Registers (GPR) d = 0 or literal instructions d =1 CPU & ALU.35

Instruction Format Examples movlw 44h addwf TEMP,1 btfsc TEMP,6 sleep NOTE: TEMP equ 20h CPU & ALU.36

Central Processing Unit (CPU) Uses the Arithmetic and Logic Unit (ALU), Responsible for Fetch, Decode, and Execute, Control Unit and Datapath, Controls memory address bus, Controls memory data bus, Controls stack. CPU & ALU.37