Arithmetic,logic Instruction and Programs

Similar documents
Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

The University of Texas at Arlington Lecture 7

ECE Test #1: Name

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Section 31. Instruction Set

Assembly Language Instructions

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution


PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

Instuction set

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

PIC 16F84A programming (II)

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Lecture (04) PIC16F84A (3)

Chapter 13. PIC Family Microcontroller

16.317: Microprocessor-Based Systems I Spring 2012

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

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

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

The University of Texas at Arlington Lecture 5

EEE111A/B Microprocessors

ALU and Arithmetic Operations

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

SOLUTIONS!! DO NOT DISTRIBUTE!!

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Flow Charts and Assembler Programs

16.317: Microprocessor-Based Systems I Summer 2012

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

16.317: Microprocessor Systems Design I Spring 2015

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

ECE Homework #3

16.317: Microprocessor-Based Systems I Fall 2012

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

16.317: Microprocessor Systems Design I Fall 2014

Week1. EEE305 Microcontroller Key Points

D:\PICstuff\PartCounter\PartCounter.asm

PIC Discussion. By Eng. Tamar Jomaa

Binary Outputs and Timing

Input/Output Ports and Interfacing

16.317: Microprocessor Systems Design I Fall 2015

Q1: Multiple choice / 20 Q2: Protected mode memory accesses. / 40 Q3: Reading PIC. / 40 assembly language TOTAL SCORE / 100

Hitchhiker s Guide to FlashForth on PIC18 Microcontrollers

Architecture. Harvard Architecture. PIC18 Review. Architecture, Instruction Set, and Assembly Language Programming

Math Utility Routines. Name Comments Program Memory Instruction Cycles Scratch RAM W Register

CONNECT TO THE PIC. A Simple Development Board

DERTS Design Requirements (1): Microcontroller Architecture & Programming

BINARY SYSTEM. Binary system is used in digital systems because it is:

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

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

PIC16C63A/65B/73B/74B

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

An Introduction & Guide to JALV2

Controller Provides Display of Monitored Process Deviation

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

Application Note - PIC Source Code v1.1.doc

MPASM and MPLINK PICmicro QUICK REFERENCE GUIDE

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

PART TWO LISTING 8 PROGRAM TK3TUT8 MOVF PORTA,W ANDLW B ADDWF COUNT,F MOVF COUNT,W MOVWF PORTB GOTO LOOP

Chapter 3: Further Microcontrollers

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Digital Fundamentals

Chapter 2 Number System

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

Inverted Pendulum Microprocessor and FPGA Manual Sheldon Logan July 3, 2006

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

EE 367 Introduction to Microprocessors Homework 6

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

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

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

PTK8756B 8 Bit Micro-controller Data Sheet

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

TUTORIAL Assembly Language programming (2)

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

Section 4. Architecture

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

ENE 334 Microprocessors

Number System. Introduction. Decimal Numbers

EECE.3170: Microprocessor Systems Design I Spring 2016

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

Principle and Interface Techniques of Microcontroller

MACHINE LEVEL REPRESENTATION OF DATA

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Transcription:

Arithmetic,logic Instruction and Programs 1 Define the range of numbers possible in PIC unsigned data Code addition and subtraction instructions for unsigned data Perform addition of BCD Code PIC unsigned data multiplication instructions and programs for division Code PIC Assembly language logic instructions Code PIC rotate instructions Arithmetic Instructions Signed Number Concepts and Arithmetic Operations Logic and Compare Instructions Rotate instruction and data serialization BCD and ASCII Conversion 2 1

Unsigned numbers are defined as data in which all the bits are used to represent data No bits are set aside for neg. or pos. sign Addition of unsigned numbers ADDLW k ADDWF filereg, d, a ADDWFC (adding two 16-bit numbers) What happens to flag register? 3 ADD 3CE7H and 3B8DH Store the sum in filereg locations 6 and 7, where location 6 should have the lower bye. 4 2

DAW, Decimal Adjust WREG Works only with WREG Add 6 to the lower or higher nibble if needed After execution, If the lower nibble is greater than 9, or if DC =1, add 0110 to the lower nibble. If the upper nibble is greater than 9, or if C = 1, add 0110 to the upper nibble. Doesn t require the use of arithmetic instructions prior the DAW execution 5 Subtracter circuit is cumbersome. (Why?) PIC performs the 2 s complement then uses adder circuit to the result. Take one Clock Cycle There are four sub instructions SUBLW k (k WREG) SUBWF f d ( destination = filereg WREG) Result may be negative (N=1 and C=1) The result is left in 2 s complement 6 3

MOVLW 0x23 SUBLW 0x3F Subtract 4C 6E MYREG EQU 0x2 MOVLW 0x4C MOVWFMYREG MOVLW0x6E SUBWF MYREG,W BNN NEXT NEGF WREG NEXT MOVWFMYREG 7 PIC supports byte-by-byte multiplication One of the operand must be in WREG After multiplication, the result is stored in PRODH and PRODL (16 bit) Example MOVLW 0x25 MULLW 0x65 8 4

There is no single instruction for the division of byte/byte numbers. You need to write a program Repeated subtraction The numerator is place in a filereg Denominator is subtracted from it repeatedly The quotient is the number of times we subtracted The reminder is in filereg upon completion 9 10 5

11 The MSB is set aside for the sign (0 or -) The rest, 7 bits, are used for the magnitude. To convert any 7-bit positive number to negative use the 2 s complement You have 128 negative numbers and 127 positive numbers 12 6

Widely used instructions ANDLW k ANDFW FileReg, d IORLW k IORFW FileReg, d XORLW k XORFW FileReg, d Effect only Z and N Flags 13 COMF FileReg,d Takes the 1 s complement of a file register Effect only Z and N Flags NEGF FileReg Takes the 2 s complement of a file register Effect all Flags Example MYREG EQU 0x10 MOVLW 0x85 MOVWF MYREG NEGF MYREG 14 7

These instructions take 1/2 cycle(s) 15 Write code to determine if data on PORTB contains the value 99H. If so, write letter Y to PORTC; otherwise, make PORTC= N CLRF TRISC MOVLW A'N MOVWF PORTC SETF TRISB MOVLW 0x99 CPFSEQ PORTB BRA OVER MOVLW A'Y MOVWF PORTC OVER. 16 8

Rotate filereg Right or Left (no Carry) RRNCF filered, d RLNCF filered, d affect the N and Z flag Rotate Right or Left through Carry flag RRCF filered, d RLCF filered, d affect the C, N and Z flag 17 Write a program to transfer value 41H serially via RB1. Put one High at the start and end Send LSB Solution RCNT EQU 0x20 MYREG EQU 0x21 BCF TRISB,1 MOVLW 0x41 MOVWF MYREG BCF STATUS,C MOVLW 0x8 MOVWF RCNT BSF PORTB,1 AGAIN RRCF MYREG,F BNC OVER BSF PORTB,1 BRA NEXT OVER BCF PORTB,1 NEXT DECF RCNT,F BNZ AGAIN BSF PORTB,1 18 9

Write a program to bring in a byte of data serially via pin RC7 and save it in file register location 0x21. The byte comes in with the LSB first. RCNT EQU 0x20 MYREG EQU 0x21 BSF TRISC,7 MOVLW 0x8 MOVWF RCNT AGAIN BTFSC PORTC,7 BSF STATUS,C BTFSS PORTC,7 BCF STATUS,C RRCF MYREG,F DECF RCNT F BNZ AGAIN 19 Swap the lower nibble and the higher nibble In the absence of a SWAPF instruction, how would you exchange the nibbles? How many rotate instruction do you need? 20 10

Assume that register WREG has packed BCD. Write a program to convert packed BCD to two ASCII numbers and place them in in file register locations 6 and 7. BCD_VAL EQU 0x29 L_ASC EQU 0x06 H_ASC EQU 0x07 MOVLW BCD_VAL ANDLW 0x0F IORLW 0x30 MOVWF L_ASC MOVLW BCD_VAL ANDLW 0xF0 SWAPF WREG W IORLW 0x30 MOVWF H_ASC 21 11