Computer Organization
CCE131
Lecture 5
8051 Microcontroller-2
Dr. Emad Badry
Lecturer at faculty of Engineering, Suez Canal University
emad.badry@eng.suez.edu.eg
MOV Instructions
❑ The instruction tells the CPU to move (in reality, COPY) the source operand to the destination operand
Value (proceeded with #) can be loaded directly to
registers A, B, or R0 – R7
ADD Instructions
❑ The ADD instruction tells the CPU to add the source byte to register A and put the result in register A.
❑ Source operand can be either a register or immediate data, but the destination must always be register A.
Loop and Jump Instructions
Looping
❑ Repeating a sequence of instructions a certain number of times is called a loop. Loop action is performed by
❑ If we want to repeat an action more times than 256, we use a loop inside a loop, which is called nested loop. We use
multiple registers to hold the count.
Example
Example
➢ If 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.
8051 conditional jump instructions
❑ All conditional jumps are short jumps that means the address of the target must within -128 to +127 bytes of the
contents of PC.
Unconditional Jumps
Call Instructions
❑ Call instruction is used to call subroutine. Subroutines are often used to perform tasks that need to be performed
frequently, this makes a program more structured in addition to saving memory space.
❑ When a subroutine is called, control is transferred to that subroutine, the processor saves on the stack the address of the
instruction immediately below the LCALL Begins to fetch instructions form the new location.
❑ After finishing execution of the Subroutine, the instruction RET transfers control back to the caller. Every subroutine
needs RET as the last instruction
RET Instruction
❑ RET is a 1-byte two-cycle instruction, which does not affect any flag, and is, generally, used as the terminator of any
subroutine.
Nesting of Subroutines