Https _doc-0o-c4-apps-viewer.googleusercontent

Post on 20-Jun-2015

125 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

12MT06PED009

BY CH. BALAKISHAN

DATA TRANSFER INSTRUCTIONS

MOVMOVCMOVX

MOV INSTRUCTIONThe MOV instruction moves data bytes/bits between the two specified operands. The byte/bit specified by the second operand is copied to the location specified by the first operandThe source data byte/bit is not affected.No other register or flag is affected.

MOV destination, source ;copy source to dest.

MOV A,#55H ;load value 55H into reg. A

MOV A,#35h; moving the 35h to the register A

MOV 35h,45h; moving the content of memory location 45h to the memory location 35h,

Here #35h is a data, 35h is a memory location.

MOV 30h,A; moving the content of reg. A to the memory location 30h,

MOV A,30h;MOV A,R1;

moving the content of reg. R1 to the reg. A

MOV 3,A; = MOV R3,A;MOV A,@R3;

moving the content of memory pointed to by R3 to A;

MOV @R3,A; moving the content of reg. A to the memory pointed to by reg.R3

MOV <dest-bit>,<src-bit> Function: To move bit dataOne of the operands must be the carry flagExample: MOV P1.3,C;

moves the carry bit to 3rd bit of port1 if C=1; the output of P1.3 is high, if C=0; the output of P1.3 is low,

MOV DPTR,16bit dataLoads the data pointer with 16 bit constant,This is 3 byte instruction,Data stored in 2nd and 3rd bytes of the instructionMOV DPTR, # 4567H

DPL=67H;(lower byte) DPH=45H;(higher byte)

MOV DPTR, # 4567H;MOV DPL,#67H;MOV DPH,#45H;=

MOV R1,R2; it is not possible

MOVC A,@A+ <base-reg> these instructions load the accumulator with a code byte or constant from program memoryThe address of the byte fetched is the sum of the original unsigned 8-bit Accumulator contents and the contents of a 16-bit base registerBase register may be either the Data Pointer or the PC

Example:Look-up table SQUR has the of values between 0

to 4, ORG 100HSQUR: DB 0,1,4,9,16 program to fetch the square value of 4

ORG 0H MOV A,#4H; MOV DPTR,100H; MOVC A,@A+DPTR; END;

MOVX <dest-byte>,<src-byte>

The MOVX instructions transfer data between the Accumulator and a byte of external data memory,This data space must be connected externallyAddress of external memory being accessed can be 16-bit or 8-bit

for 16 bit--- DPTR 8 bit----R0 or R1

16 Bit address data transfer:

MOVX @DPTR,A; this moves the contents of the

accumulator to the external memory location whose address is pointed to by DPTR,MOVX A,@DPTR;

this moves into the accumulator a byte from external memory whose address is pointed to by DPTR,

8 Bit address data transfer

MOVX A,@R1; This moves to the accumulator to the

external memory whose 8-bit address is pointed to by R0MOVX @R1,A;

This moves a byte from register into external memory location whose 8-bit address is held by R0

EXAMPLE PROGRAM USING MOVX INSTRUCTION..An external ROM uses the 8051 data space to store the look-up table (starting at 1000H) for DAC data. Write a program to read 30 Bytes of these data and send it to P1.

Solution:

MYXDATA EQU 1000HCOUNT EQU 30MOV DPTR, #MYXDATA;MOV R2, #COUNT;AGAIN: MOVX A,@DPTR;MOV P1,A;INC DPTR;DJNZ R2,AGAIN;

BRANCHING INSTRUCTIONS

Program branching instructions are used to control the flow of actions in program.Some instructions provide decision making capabilities and transfer control to other parts of program.

eg., Unconditional and conditional branches.

SJUMP(short jump):2 byte instruction1st byte opcode2nd byte relative address of target location relative address range is 00 – FFH, All conditional jumps are short jumps

Ex: SJUMP HERE; after executing this instruction it jumps to HERE label

LJUMP(long jump):

Unconditional long jump3byte instruction1st byte for op-code2nd and 3rd byte for 16 bit address of target location

CONDITIONAL JUMPS

JZ AND JNZ INSTRUCTIONSJZ label ; jump if A=0

Can be used only for register A, not any other register.flag registers will not be affected

JNZ label; jump if A is not zero

DJNZ INSTRUCTIONDJNZ reg, Label;The register is decremented.If it is not zero, it jumps to the target address referred to by the label.Prior to the start of loop the register is loadel with the counter for the number of repetitions.Counter can be R0 – R7 or RAM location.

ExampleProgram to complement the accumulator 3 times

ORG 0H; MOV A,0Fh; MOV R3,3; HERE: CPL A; DJNZ R3,HERE; END

EXAMPLE:Write a program to (a) load the accumulator with the value 55H, and (b) complement the ACC 700 times.

MOV A,#55H ;A=55HMOV R3,#10 ;R3=10, outer loop countNEXT: MOV R2,#70 ;R2=70, inner loop countAGAIN: CPL A ;complement A registerDJNZ R2,AGAIN ;repeat it 70 timesDJNZ R3,NEXT

JNC INSTRUCTIONJNC label ;jump if no carry, CY=0If CY = 0, the CPU starts to fetch and execute instruction from the address of the label.If CY = 1, it will not jump but will execute the next instruction below JNC.All conditional jumps are short jumpsThe address of the target must within

-128 to +127 bytes of the contents of PC

BYTE JUMPS:

CALL instructionsTo call a user defined functions in program Transfer control to a subroutineFlags are not affectedRET must be the last instruction of subroutineThese are two types

1) ACALL(absolute call) 2) LCALL (long call)

ACALL: 2 byte instruction 5 bits are used for op-code remaining 11 bits are used for subroutine target addressTarget address must be within 2K byte

Ex: ACALL label; here label address should be 2K byte

only

LCALL: 3 byte instruction1st byte for op-code2nd and 3rd for target address of the subroutineSubroutine address located anywhere within 64K byte

Ex: LCALL label;

Program to display 5 and 4 digits in seven segment display with delay:

ORG 0H; MOV P1,#05DH; ACALL DELAY; MOV P1,#026H; ACALL DELAY; END;DELAY: MOV R3,#55; (count=55) HERE: DJNZ R3,HERE;(loop) RET;

TIME DELAY CALCULATIONS

� CPU executing an instruction takes a certain number of clock cycles. These are referred as to as machine cycles.

� In original 8051, one machine cycle lasts 12 oscillator periods.

� Find the period of the machine cycle for 11.0592 MHz crystal frequency?

�Solution:11.0592/12 = 921.6 kHz;machine cycle is 1/921.6 kHz =

1.085μs

PROBLEM:�For 8051 system of 11.0592

MHz, find how long it takes to execute each instruction.

(a) MOV R3,#55 (b) DEC R3 (c) DJNZ R2 target

(d) LJMP (e) SJMP (f) NOP (g) MUL AB

Solution:

Find the size of the delay in following program,

if the crystal frequency is 11.0592MHz.

MACHINE CYCLEDELAY: MOV R3,#250 1HERE: NOP 1NOP 1NOP 1NOP 1DJNZ R3,HERE 2RET 2

SOLUTION

�The time delay inside HERE loop is [250(1+1+1+1+2)]x1.085μs = 1627.5μs. Adding the two instructions outside loop we have 1627.5μs + 3 x 1.085μs = 1630.755μs.

top related