Embedded Software 1. General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator)

Slides:



Advertisements
Similar presentations
The 8051 MicroController In this module, we will be discussing the MCS-51 family of microcontroller, in particular the 8051, which is the generic IC representative.
Advertisements

Processor Data Path and Control Diana Palsetia UPenn
Computer Science Education
Chapter 18 The 8051 Microcontroller
Chapter 4 The Von Neumann Model
Chapter 4 The Von Neumann Model
EE/CS-352: Embedded Microcontroller Systems The 8051 Assembly Language.
The 8051 Assembly Language Stack, Bit Addressing, Arithmetic
Week4. Program Branching  From what we have covered so far, our assembly programs execute one instruction after another in sequence  Programs that solve.
Week 8 Stack and Subroutines. Stack  The stack is a section of data memory (or RAM) that is reserved for storage of temporary data  The data may represent.
CSC 3210 Computer Organization and Programming
Introduction to Computer Systems
Suranaree University Of Technology มทส  2002 Anant Oonsivilai 2002/2/27 Microcomputers and Microprocessors Chapter Assembly Language Programming.
Chapter 3 INSTRUCTION SET SUMMARY
Chapter 3 โพรเซสเซอร์และการทำงาน The Processing Unit
Assembly Language.
Class Addressing modes
THUMB Instructions: Branching and Data Processing
Programming the 8051 Microcontroller Dr. Konstantinos Tatas
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
The 8051 Microcontroller and Embedded Systems
1 Chapter 3 Jump, Loop, and Call Instructions. 2 Sections 3.1 Loop and Jump Instructions 3.2 Call Instructions 3.3 Time Delay Generation and Calculation.
Msc. Ivan A. Escobar Broitman Microprocessors 1 1 The 8051 Instruction Set.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Microcontroller Intel 8051
MICROCONTROLLER INSTRUCTION SET
CoE3DJ4 Digital Systems Design Chapter 3: instruction set summary.
Prof. Cherrice TraverEE/CS-152: Microprocessors and Microcontrollers The 8051 Assembly Language.
CIT 673 Created by Suriyong1 MCS51 ASSEMBLY Language Resources
The 8051 Microcontroller and Embedded Systems
The 8051 Assembly Language Branching & Subroutines
8051 Micro controller. Architecture of 8051 Features of 8051.
The 8051 Microcontroller and Embedded Systems
Lecture Set 4 Programming the 8051.
The 8051 Assembly Language. Overview Data transfer instructions Addressing modes Data processing (arithmetic and logic) Program flow instructions.
JUMP, LOOP, AND CALL INSTRUCTIONS
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
8051 Micro Controller. Microcontroller versus general-purpose microprocessor.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
8 085Microprocessor Temp Reg (8) Accumulator (A reg) Flag flip flops(8) Instruction Register (8) Arithmetic Logic Unit ALU Instruction Decoder and Machine.
1 Contents: 3.1 Instruction format and Addressing Modes 3.2 Instruction Introduction Chapter 3 Instruction system.
Microprocessors I 8051 Addressing Modes CS Prof. Msc. Ivan A. Escobar
Seminar On 8085 microprocessor
CHAPTER ADDRESSING MODES.
Classification of Instruction Set of 8051
Assembly Language Programming of 8085
The 8051 Microcontroller and Embedded Systems
Lecture Set 5 The 8051 Instruction Set.
Subroutines and the Stack
ECE,JYOTHI ENGG COLLEGE
8051 Addressing Modes The way, using which the data source or destination addresses are specified in the instruction mnemonic for moving the data, is.
Data Processing Instructions
SCHOOL OF ELECTRONICS ENGINEERING Electronics and Communication
The 8051 Assembly Language Arithmetic & Logic Instructions
8051 Single Board Computer (SBC) Version 1.0
Branching Instructions
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
Subroutines and the Stack
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
Conditional Jumps and Time Delays
DMT 245 Introduction to Microcontroller
Introduction to Micro Controllers & Embedded System Design
First Design Key board R L S.
Conditional Jumps and Time Delays
8051 ASSEMBLY LANGUAGE PROGRAMMING
Subroutines and the Stack
Computer Operation 6/22/2019.
Presentation transcript:

Embedded Software 1

General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator) and B registers, 16-bit program counter (PC) 8-bit program status register (PSW) 8-bit stack pointer (SP) Memory Separate program and data memory Internal ROM used to store the program memory. Internal data memory consists of 256 bytes of internal RAM

8051 Program Memory Program memory is used to store the program code. This is the machine code that is obtained from the assembly language or C program. The machine code represents instructions and constants. When the 8051 is powered up, program execution always starts from the location 0X0000. After the RESET operation, the program counter (PC) contains 0000h, causing the first instruction to be read from the program location 0000h. The program memory addresses are 16-bits long. Therefore the 8051 can directly address 2 16 = 64k locations. Each program memory location stores a single byte. The CPU can only read from program memory.

8051 Data Memory Can read/write from/to data memory. Therefore the contents of data memory can change as the program executes. Data memory is used to temporary data used by a program. Also used to store the stack. The total size of the 8051s internal RAM is small 256 bytes in total ! Data memory map shows 256 locations Bottom 32 locations are used 224 locations available Addresses are shown in hex

Simplified Programming Model for 8051 Note that there are more important registers to add to this model!!! (See these later) The 8051 is an accumulator based CPU Operations on data are performed on data in A and result is placed in A E.g Add A,#23 Accumulator based machines are common for older 8-bit machines

Instruction Sets The instruction set is the set of instructions that the CPU can decode and execute. It defines the processor with each processor having it's own instruction set. The general groupings of instructions for any uP are Arithmetic/Logic Data Movement Transfer of Control Test/Compare Input/Output (only on some CPU's ) Others An instruction stored in memory is represented by a certain number of byte(s). Some CPUs have fixed length instructions, i.e. all the instructions in the instruction set are of equal size

Instruction Encoding The instruction contains what the operation is, the operands for the instruction if there are any. the destination for the result if there is one The part of the instruction that determines the instruction is called the opcode Examples are ADD JMP An operand may be an immediate value, memory address or a CPU register. The location for the result of an operation could be a memory address or a CPU register. For an 8 bit machine such as the 8051, an instruction can be represented by 1, 2 or 3 bytes depending on the instruction

Instruction Encoding Details for the 8051 (8 bit machine) are in notes The 8051 is an example of an accumulator based machine Accumulator machines have a special purpose register that normally serves as an operand and destination for an instruction E.g. ADD A,#27 Encoding h 1Bh 2 byte instruction

Instruction Encoding Multiples of bytes 8 bit opcode gives 2 8 =256 possible opcodes 255 actually used 139 are 1 byte instructions 92 are 2 byte instructions 24 are 3 byte instructions Most instructions are one byte, some two, a few three See back of notes for complete details on instructions Example of a 1 byte instruction is the following CLR C which is represented by machine code C3H or the equivalent bit pattern

Instruction Timing The microcontroller takes a minimum of 12 clock cycles (machine cycle) to execute an instruction Some instructions are slower to execute, taking 24 clock cycles There are no instructions with 36 clock cycles, but there are 2 instructions that take 48 clock cycles (or 4 machine cycles) MUL and DIV instructions See back of lab notes for instruction cycle times for all instructions Note that the instruction size does not directly imply how long the instruction cycle is!

8051 Instruction set ACALL addr11 DIV AB LJMP addr16RETI ADD A, DJNZ, MOV, RL A ADDC A, INC MOV DPTR,#data16RLC A AJMP addr11 INC DPTR MOV bit,bitRR A ANL JB bit,rel8 MOVC RRC A ANL C, JBC bit,rel8 MOVX, SETB bit CJNE,,rel8 JC rel8 MUL ABSJMP rel8 CLR A NOPSUBB A, CLR bit JNB bit,rel8 ORL, SWAP A CPL A JNC rel8 ORL C,bitXCH A, CPL bit JNZ rel8 POP directXCHD DA A JZ rel8 PUSH direct XRL, DEC LCALL addr16 RET How many instructions??

Lecture 2

Getting started with the instruction set A key requirement is the ability to move data Between registers Between memory and registers Between memory The MOV instruction can be used Different modes of addressing available

Introducing the MOV instruction The MOV instruction is of the form MOV, And has the effect of moving a byte from to the location. There are 15 variations!!! Example MOV A,#12 12

Aside: Representing hexadecimal values On paper, a hexadecimal value is represented in one of the following ways 0xA4 A4h However, for an assember, a hexadecimal value starting with the digit A to F must be preceded by 0x. This is so as to distinguish the number from an identifier. Therefore, the representation 0xA4 must be used with an assembler.

Introducing the MOV instruction and immediate values Example MOV A,#12 Here the destination is the A register and the source is an immediate value All immediate values are preceded by the hash symbol Using an immediate value means that the source byte is constant The value can be decimal or hex 12

Introducing the MOV instruction and register addressing Register addressing is another method for accessing data Example MOV R3,#32 MOV A,R3 Firstly the decimal value 32 is copied into R3, while the second instruction copies the value in R3 into A. Any one of the 8 registers R0- R7 can be used Use Rn to indicate any register when describing register addressing 32

Introducing the MOV instruction with register addressing and immediate values MOV R3,#32 MOV A,R3 Destination operand Uses register addressing R3 Source operand Uses immediate value 32 Destination operand A Source operand Uses register addressing R3

MOV R3,#32 MOV A,R3 Introducing the MOV instruction showing instruction encoding B EB Aside, what is the benefit of short instructions?

Introducing the MOV instruction and direct addressing To access data in lower RAM, direct addressing is used Example MOV 0x20,A Here, the destination is hex address 20 and the source value, which is in A, is copied into RAM Direct addressing can only be used to access the lower 128 bytes and NOT the upper 128 bytes 15

Note the difference between immediate values and direct addressing: Be careful!!! It is important to understand the difference between an immediate value and direct addressing MOV A,#0x64 MOV A,0x64 Here, the value 64h is stored in A Here, the value at address 64h is stored in A. Find out in lab the machine code for both of these?

Introducing the MOV instruction and indirect addressing To access data ìn any one of the 256 RAM locations, indirect addressing can be used Example Indirect addressing can be specified using when discussing indirect addressing, it is common to refer where i could be 1 or 0. How does it work?? Read on!!! 20h 13

Introducing the MOV instruction and indirect addressing Example The contents of R0 are interpreted as an address in RAM. If R0 contains the value 20h, then the above instruction will copy the value in A into address 20h in RAM. In effect, it is now possible to indirectly access a memory location Have you seen this idea before, C programmers? 20h 13

Summary of addressing modes Immediate value #data8 e.g. MOV A,#56h Regsister addressing Ri e.g. MOV R6,R3 Direct Addressing direct e.g. MOV R6,4Eh Indirect e.g. Good news for us this semester The first 3 are the addressing modes that will be mostly used and that indirect addressing will be rarely used

Full details for MOV instructions MOV A,source MOV A,#data MOV dest,source MOV dest,#data Where dest and source can be any of Rn, direct

Appendix

8051 Block diagram

Instruction encoding Another example is ADDC A,R1 This instruction adds the contents of A and the contents of R1 using the carry and stores the result in A The machine code is 39H. In general for this instruction, it will be encoded as follows bits 3 bits Rn

Exercises 1.Draw a block diagram of the What is the purpose of the program memory on the 8051? 3.At what address does the 8051 start executing code from upon powerup? 4.How many memory locations in the 8051 program memory? 5.What register contains the address of the next program instruction? a)How many bits in this register?

Exercises 6. Can program memory be written to during program execution? 7. What is the purpose of the 8051 data memory? 8. What size is the data memory? 9. Draw a simplified programming model for the 8051, making sure to label all registers. 10. What does it mean to say that a processor is an accumulator based machine 11. What is an instruction set? 12. List the general groupings of instructions that make up an instruction set?

Exercises 13.What information does an instruction contain? 14.On the 8051, what size are the instructions? 15.What is machine code for the following instruction and how many clock cycles does it take? ADD A,R5 16.Do we need to remember the machine code for each instruction? 17.How many 8051 instructions are there? 18.What is the purpose of the MOV instruction?

Exercises 19. What is an immediate value? 20. How is it represented? 21. What instruction is used to move the immediate decimal value 12 into the accumulator? 22. What is register addressing? 23. Move the value in register R4 into the accumulator. What is the resulting machine code? 24. What is direct addressing? Give an example.

Exercises 24. What is indirect addressing? Give an example 25. Write out the code to move the decimal values 0,1,15 and 8 into the regsiters R0 to R3 respectively? 26. Write out the code to mode the hexadecimal values 0,a5,15 and c into the registers R0 to R4 respectively. 27. Write out the code to move the initialise the memory locations 20h to 24h with zero. 28. Write out the code to swap the values in R0 and R1.