1. University of Energy and Natural Resources, Sunyani Institute of Distance Learning Dept. of Comp. & Elect. Eng. CENG 365 – Microprocessor DR. NANA.

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Introduction to C Programming
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Instruction Set Architecture & Design
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Railway Foundation Electronic, Electrical and Processor Engineering.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Introduction to C Programming
Railway Foundation Electronic, Electrical and Processor Engineering.
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Machine Instruction Characteristics
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Introduction to Computer Programming using Fortran 77.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
CHAPTER NINE.
The Little man computer
Chapter 10 Programming Fundamentals with JavaScript
Basic Computer Organization and Design
PROGRAMMING THE BASIC COMPUTER
Addressing Modes in Microprocessors
Control Unit Lecture 6.
Assembly Language Programming of 8085
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Assembly Language Ms. V.Anitha AP/CSE SCT
Chap 7. Register Transfers and Datapaths
HTP Programme: Assembler
Revision Lecture
The Selection Structure
Introduction of microprocessor
Chapter 3 Machine Language and Assembly Language.
Chapter 3 Machine Language and Assembly Language.
PIC – ch. 2b Md. Atiqur Rahman Ahad.
PIC18 CH. 4.
BASIC COMPUTER ORGANIZATION AND DESIGN
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 10 Programming Fundamentals with JavaScript
Introduction to C++ Programming
Chap. 6 Programming the Basic Computer
EECE.3170 Microprocessor Systems Design I
A Simple Two-Pass Assembler
EECE.3170 Microprocessor Systems Design I
Chapter 2: Introduction to C++.
Assemblers CSCI/CMPE 3334 David Egle.
ECE 352 Digital System Fundamentals
Instructions in Machine Language
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Chapter 6 Programming the basic computer
Presentation transcript:

1

University of Energy and Natural Resources, Sunyani Institute of Distance Learning Dept. of Comp. & Elect. Eng. CENG 365 – Microprocessor DR. NANA DIAWUO (PHD) TWENEBOAH-KODUAH S. 2

Chapter 3 – logic gates and assembly language 3

Multilevel machines Level 0: The digital logic level Operations at the digital logic level are performed by circuits called logic gates. Each gate has one or more digital inputs (signals representing 0 or 1) and computes as output some simple function of these inputs, such as AND, OR, Exclusive OR, etc. The digital logic level is concerned with electrical current and lack of current. Each instruction that the computer executes sets the lines that control the processor, either by allowing power to run through a line, or by preventing power from running through a line. Each instruction has a different configuration for which lines get power and which ones don't. Level 1: Microprogram Level The Intel chips have all used a microprogram to interpret machine language instructions into hardware instructions. In this case, the microprogram contains actual hardware instructions, and each machine language instruction is executed by calling a subroutine in the microprogram. Level 2: The machine language This is an abstract representation of which lines get power and which ones don't. It is a simple abstraction: a one represents power, and a zero represents no power. We can write a machine instruction, such as , and the processor will set and clear the appropriate lines to perform the indicated operation. 4 Or Hardware level

Multilevel machines Level 3: The operating system This is just a collection of machine language subroutines. Subroutine is a collection of computer codes that performs a certain in a program. Level 4: Assembly Language Level This level has a one-to-one correspondence with the machine language. Instead of using ones and zeros to indicate an instruction, symbolic names are used. So the machine language instruction can be written as ADD CX,DX. The change from assembly language to machine language is done by translation 5

Multilevel machines Level 4: Assembly Language Level This level has a one-to-one correspondence with the machine language. Instead of using ones and zeros to indicate an instruction, symbolic names are used. So the machine language instruction can be written as ADD CX,DX. The change from assembly language to machine language is done by translation Level 5: High Level Language This would be a language like C++, where one statement would be translated into several machine language instructions. For instance if (A > B) C = 1; would translate into these instructions (represented in assembler instead of machine) mov ax,A cmp ax,B jle next mov C,1 next: 6

Changing from one level to another Two things can happen when an instruction from one level is changed to a lower level 1.There is a change from a more readable format to a less readable format. For example, changing assembly to machine. 2.One instruction is changed into several instructions at the new level. For example, changing C++ to machine. Imagine how many hardware instructions are executed for one instruction in an application program. There are two ways major steps to go through when changing from a higher level to a lower level. a.Translation b.Interpretation Translation Each high instruction is translated into the low level and the new low instructions are saved. After all the high instructions have been changed to the low level, then all the new low instructions are executed. Interpretation Each high instruction is translated and executed in the low level before continuing with the next high instruction. The new low level instructions are not saved. 7 What is a virtual machine?

PIC18 Assembly language Structure A program written in assembly language consists of a sequence of statements that tell the computer to perform the desired operations Consist of three directives ◦Assembler directives ◦Assembly language instruction ◦And comments Source code fields ◦Label ◦Mnemonic ◦Operand (s) and Comment 8

Code structure 9 Could be: colon (:), space, tab, or the end of line

Order Instruction Labels must start in column 1. Mnemonics may start in column 2 or beyond. Operands follow the mnemonic. Comments may follow the operands, mnemonics, or labels and can start in any column. The maximum column width is 256 characters. Spaces or a colons are used to separate the label and the mnemonic and use space(s) to separate the mnemonic and the operand(s). Multiple operands must be separated by commas. 10

Label Fields A label must start in column 1. It may be followed by a colon (:), space, tab, or the end of line. Labels must begin with an alphabetic character or an underscore (_) May contain alphanumeric characters, the underscore, and the question mark. Example The following instructions contain valid labels: (a)loop addwf 0x20,F,A (b)_again addlw 0x03 (c)c?gtm andlw 0x7F (d)may2June bsf 0x07, 0x05,A 11

Label Fields Example The following instructions contain valid labels: (a)loop addwf 0x20,F,A (b)_again addlw0x03 (c)c?gtm andlw0x7F (d)may2June bsf 0x07, 0x05,A The following instructions contain invalid labels: (e)isbig btfsc 0x15,0x07,B ;label starts at column 2 (f)3or5 clrf 0x16,A ;label starts with a digit (g)three-four cpfs 0xl4,A ;label contains illegal character 12

Mnemonic Field This field can be either an assembly instruction mnemonic or an assembler directive and must begin in column 2 or greater. If there is a label on the same line, instructions must be separated from that label by a colon or by one or more spaces or tabs. Examples of mnemonic field: (a)false equ 0 ;equ is an assembler directive (b)goto start ;goto is the mnemonic (c)loop: incf 0x20,W,A ;incf is the mnemonic 13

Operand Field If an operand field is present, it follows the mnemonic field. The operand field may contain operands for instructions or arguments for assembler directives. Operands must be separated from mnemonics by one or more spaces or tabs. Multiple operands are separated by commas. The following examples include operand fields: (a)cpfseq 0x20,A ; “0x20” is the operand (b)true equ 1 ; “1” is the operand (c)movff 0x30, 0x65 ; “0x30” and “0x65” are operands 14

Comment Field The comment field is optional and is added for documentation purpose. It starts with a semicolon “ ; “. All characters following the semicolon are ignored through the end of the line. The two types of comments are illustrated in the following examples. (a)decf 0x20,F,A ; decrement the loop count (b); the whole line is comment 15

Assembler directives Assembler directives look just like instructions in an assembly language program. Most assembler directives tell the assembler to do something other than creating the machine code for an instruction. Assembler directives provide the assembly language programmer with a means to instruct the assembler how to process subsequent assembly language instructions. Directives also provide a way to define program constants and reserve space for dynamic variables. 16

Types of assembler directives Control directives These set flow control of instruction in the code i.e. decision makers Example: if else endif The if directive begins a conditionally assembled code block. If evaluate to true, the code immediately following if will assemble. Otherwise, subsequent code is skipped until else directive or an endif directive is encountered. endif marks the end of condition block 17

Example if version == 100 ;check current version movlw 0x0a movwf io_1, A else movlw 0x1a movwf io_2, A endif 18

Control directives 19

Macro directives There are situations in which the same sequence of instructions need to be included in several places. This sequence of instructions may operate on different parameters. These instruction can be put in macro and call at anytime with writing additional codes Syntax macro [, …, ] endm 20

Other macro directives 21 Object file and Listing directives may also be important

Arithmetic operation using PIC18 Addition Write a program that adds the three numbers stored in data registers at 0x20, 0x30, and 0x40 and places the sum in data register at 0x50. Solution: The algorithm for adding three numbers is as follows: Step 1: Load the number stored at 0x20 into the WREG register. Step 2: Add the number stored at 0x30 and the number in the WREG register and leave the sum in the WREG register. Step 3: Add the number stored at 0x40 and the number in the WREG register and leave the sum in the WREG register. Step 4: Store the contents of the WREG register in the memory location at 0x50. The program that implements this algorithm is as follows: 22

Arithmetic operation using PIC18 Addition The program that implements this algorithm is as follows: 23

Arithmetic operation using PIC18 Subtraction Write a program to subtract 5 from memory locations 0x10 to 0x13. Solution: The algorithm for this problem is as follows: Step 1: Place 5 in the WREG register. Step 2: Subtract WREG from the memory location 0x10 and leave the difference in the memory location 0x10. Step 3: Subtract WREG from the memory location 0x11 and leave the difference in the memory location 0x11. Step 4: Subtract WREG from the memory location 0x12 and leave the difference in the memory location 0x12. Step 5: Subtract WREG from the memory location 0x13 and leave the difference in the memory location 0x13. The assembly program that implements this algorithm is as follows: 24

Arithmetic operation using PIC18 Subtraction The assembly program that implements this algorithm is as follows: 25

Arithmetic operation using PIC18 Subtraction – Example Write a program that substract the number stored at 0x20 …. 0x23 from the number stored at 0x10 …. 0x13 and leaves the difference at 0x30 … 0x33 Solution The program implementation is: 26

Arithmetic operation using PIC18 Subtraction – Example Write a program that substracte the number stored at 0x20 …. 0x23 from the number stored at 0x10 …. 0x13 and leaves the difference at 0x30 … 0x33 Solution The program implementation is: 27

Arithmetic operation using PIC18 28

Arithmetic operation using PIC18 Multiplication – Example Write an instruction sequence to multiply two 8-bit numbers stored in data memory locations 0x10 and 0x11, respectively, and place the product in data memory location 0x20 and 0x21 29

PIC18 Loop and logic instructions The PIC MCU provide group of instruction that perform logical operations such as AND, OR, exclusive-OR and complementing 8-bit number. Loops can be use to create a time delay by repeating instructions 30 Logical operations are useful for looking for array elements with certain properties (e.g., divisible by power of 2) and manipulating I/O pin values (e.g., set certain pins to high, clear a few pins, toggle a few signals, and so on).

PIC18 Loop and logic instructions Example: Write an instruction sequence to perform the following task ◦Set bits 7, 6, and 0 of the PORTA register to high ◦Clear bits 4, 2, and 1 of the PORTB register to low ◦Toggle bits 7, 5,3, and 1 of the PORTC register 31

PIC18xxx Basic instructions description MnemonicDescriptionExample ADDLWAdd Literal and W ADDLW 0x15 ADDWFAdd W and fADDWF FSR, 0 ANDLWAnd Literal with WANDLW 0x5F ANDWFAnd W with fANDWF FSR, 1 BCFBit Clear fBCF FLAG_REG, 7 BSFBit Set fBSF FLAG_REG, 7 BTFSCBit Test, Skip if ClearBTFSC FLAG, 4 BTFSSBit Test f, Skip if SetBTFSS FLAG, 4 CALLCall Subroutine CLRFClear fCLRF FLAG_REG CLRWClear WCLRW COMFComplement fCOMF REG1, 0 DECFDecrement fDECF INDF, 1 DECFSZDecrement f, Skip if 0 32