JUMP, LOOP AND CALL INSTRUCTIONS

Similar documents
Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS

Assembly Language programming (3)

ELEG3924 Microprocessor

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call


ET2640 Microprocessors

8051 Microcontroller Assembly Programming

Microcontroller Intel [Instruction Set]

SN8F5000 Family Instruction Set

8051 Overview and Instruction Set

8051 Microcontroller

Programming of 8085 microprocessor and 8051 micro controller Study material

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Microcontrollers

Principle and Interface Techniques of Microcontroller

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Chapter Family Microcontrollers Instruction Set

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Chapter 3. Bit Addressable Area. By DeccanRobots

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Module Contents of the Module Hours COs


UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

TUTORIAL Assembly Language programming (2)

Digital Blocks Semiconductor IP

Assembly Language programming (2)

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

Digital Blocks Semiconductor IP

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

LCD AND KEYBOARD INTERFACING

Digital Blocks Semiconductor IP

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

DR bit RISC Microcontroller. Instructions set details ver 3.10

ELEG3924 Microprocessor

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

~: Simple Programs in 8051 assembly language :~

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

Assembly Language Programming of 8085

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Instruction Set Of 8051

Dodatak. Skup instrukcija

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

Microcontroller and Applications

Assembly Language Programming of 8085

MICROPROCESSOR LABORATORY MANUAL

Principle and Interface Techniques of Microcontroller

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

Microcontroller and Embedded Systems:

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Engr. A. N. Aniedu Electronic and Computer Engineering Nnamdi Azikiwe University, Awka

Introduction To MCS-51

Embedded Controller Programming

ELEG3923 Microprocessor Ch.4 I/O Ports

1. LCD (Liquid Crystal Display)interface

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

CPEG300 Embedded System Design. Lecture 8 Timer

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

C51 Family. Architectural Overview of the C51 Family. Summary

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

Contents. Join the Technical Community Today!

S.J.P.N Trust's. Hirasugar Institute of Technology, Nidasoshi.

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller and Applications Subject Code:

The 8051 Microcontroller and Embedded Systems

MICROCONTROLLER BASED WATER LEVEL CONTROL SYSTEM

MCS -51 Programmer s Guide and Instruction Set

Assembly Language programming (1)

Chapter Addressing Modes

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

8051 Programming using Assembly

Microcontroller. Instruction set of 8051

Question Bank Microprocessor and Microcontroller

INTERFACING 16 2 LCD WITH 8051



Instruction : A command to the microprocessor to perform a given task on specified data. Each instruction has two parts

CPEG300 Embedded System Design. Lecture 6 Interrupt System

1. Pin diagram of 8051 and ports

ORG ; TWO. Assembly Language Programming

Counters & Time Delays. Microprocessors & Interfacing 1

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

Applications of 8051 Microcontrollers

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

Displaying of Digital Clock through digital circuits and through Assembly Language Programs of 8051 microcontroller

Highlights. FP51 (FPGA based 1T 8051 core)

CHAPTER TIMER PROGRAMMING

Introduction to uc & Embedded Systems

Dragonchip. Instruction Set Manual

SUMMER 13 EXAMINATION

Interrupt Programming: Interrupts vs. Polling Method:

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

Application Brief D-005

TOPIC 6 LATCH. FIGURE 1 INTERFACING OF ROM/EPROM TO µc 8051.

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

Department of Electronics and Instrumentation Engineering Question Bank

Programming the 8051/8052

CPU. Fall 2003 CSE 207 Digital Design Project #4 R0 R1 R2 R3 R4 R5 R6 R7 PC STATUS IR. Control Logic RAM MAR MDR. Internal Processor Bus

Transcription:

JUMP, LOOP AND CALL INSTRUCTIONS After you have understood the tutorial on Introduction to assembly language which includes simple instruction sets like input/output operations, now it s time to learn how to create loops, function calls and jumps while writing a code in assembly language. Let us first discuss an important concept that relates RAM & ROM. You can skip this section if you wish but it is an important to understand registers which helps in building up understanding of architecture of microcontrollers. How a program which is burned in ROM gets executed in RAM? The program you write is burned in ROM and this program is executed in RAM. The data burned is in the form of logics or binary digits (0 & 1) also called an Opcode or machine code. The program written in assembly language is converted to opcode by assembler. Each line of the assembly code is assigned a unique opcode by the assembler as shown below. These opcodes are then stored in ROM one after another. There is a register called Program Counter (PC) which always points to the current opcode being executed. When the power is switched on it sets itself to zero and it keeps on incrementing itself as opcodes are executed one after another. This information is used by RAM to extract correct opcode from ROM which is then executed. This process goes on line by line till the whole program is executed.

Let s take an example:- PC Mnemonic, Operand Opcode (Machine code) 0000 ORG 0H 0000 MOV R0, #0 7800 0002 MOV A, #55H 7455 0004 JZ NEXT 6003 0006 INC R0 08 0007 AGAIN: INC A 04 0008 INC A 04 0009 NEXT: ADD A, #77H 2477 000B JNC OVER 5005 000D CLR A E4 000E MOV R0, A F8 000F MOV R1, A F9 0010 MOV R2, A FA 0011 MOV R3, A FB 0012 OVER: ADD, R3 2B 0013 JNC AGAIN 50F2 0015 HERE: SJMP HERE 80FE 0017 END We can clearly see that the PC increases with execution of program. The PC starts with zero when ORG 00H line is executed and then in subsequent lines PC keeps on incrementing as machine codes are executed one after another. Program Counter is a 2 byte or 16 bit register. Therefore we cannot have internal ROM of more than the number this register can hold (i.e. not exceeding the FFFF hex value). LOOP AND JUMP INSTRUCTIONS

Let us start with a simple example that will help you to learn how to create loops in assembly. In the following code the instruction DJNZ is used to reduce the counter and is repeated till the counter becomes zero. Eg-1: ORG 0H MOV A, #0 ; clear A MOV R1, #10 ; load counter R1 =10 AGAIN: ADD A, # 05 ; add five to register A DJNZ R1, AGAIN ; repeat until R1=0 (10 times) MOV R3, A ; save A in R3 END In this code R1 acts as a counter. The counter value is initialized i.e. 10 HEX is loaded to R1. In each iteration, the instruction DJNZ decrements R1 by one until it becomes zero. This loop adds 5 HEX to A every time it runs. After ten iterations R1 becomes zero and the instructions below it are executed. Note: - Some Jump statements can only be performed on some special register A (or bit CY) as mentioned in the table below.

Nested loops: ORG 0H MOV A, #55H ; A= 55 hex MOV R1, #100 ; the outer counter R1 =100 NEXT: MOV R2, # 20 ; the inner counter AGAIN: CPL A, # 05 ; add five to register A DJNZ R2, AGAIN ; repeat until R1=0 (100 times) DJNZ R1, NEXT ; repeat till 20 times (outer loop) END SJMP refers to short jump and LJMP refers to long jump. All the conditional jumps are short jumps. SJMP: This instruction is of two bytes in which first one is opcode & second is the address. The relative address of the instruction called should be in between -127 to 127 bytes from the current program counter (PC). LJMP: This instruction is of three bytes in which the first is the opcode and the second & third are for address. The relative address of the instruction can be anywhere on the ROM.

So it is clear from the above examples that we can use different jump instructions with a condition or counter called conditional loop. And when we create loop inside an existing loop it is called nested loop. CALL INSTRUCTIONS: Example: LCALL (long call) ORG 0H BACK : MOV A, #55H ; load A= 55 hex value MOV P1, A ; issue value of register A to port1 LCALL DELAY ; to call DELAY function created below MOV A, #0AAH ;load AAH hex value to A MOV P1,A ;issue value of register A to port 1 LCALL DELAY ; to call DELAY function as created below SJMP BACK ; keep doing this ; this is the delay subroutine DELAY: MOV R5, #0FFH ; R5= 255 hex, the counter AGAIN: DJNZ R5, AGAIN ; stay here until R5 becomes zero RET ; return to caller END In this code we keep on toggling the value of the register of port 1 with two different hex values and a DELAY subroutine is used to control how fast the value is changing. Here in DELAY subroutine the program is kept busy by running an idle loop and counting 256 counts. After the DELAY subroutine is executed once the value of port 1 is toggled and this process goes on infinitely.

By using DELAY we can create PWM (Pulse Width Modulation) to control motors or LED blinking for further details view our tutorial on Input/ output instructions in Assembly Language[coming soon]. We can also use ACALL i.e. absolute call for calling a subroutine that is within 2K byte of PC.