Module 2B

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

www.covenantuniversity.edu.

ng

Raising a new Generation of Leaders

CEN511: EMBEDDED
SYSTEMS DESIGN AND
PROGRAMMING COURSE LECTURERS
ODUSAMI MODUPE (Engr.)
OMORUYI OSEMWEGIE
Topics
• Instruction Set and Assembly Language Programming:
Addressing modes,
• The 8051 instruction set and typical examples,
• Assembler operation, assembly language format,
assembler directives, operation of assemblers and linkers,
• Programming examples in Assembly and Embedded c.

2
8051 Instruction Set and Assembly Language
Programming
Definition of Terms
• Mnemonic: a given or singular instruction in a CPUs
instruction set.
• Opcode: the part of a mnemonic that specifies the
operation to be carried out.
• Operand: the part of an instruction that specifies the
data or memory location to act on.
3
Data Movement in 8051

The 8051 has 28 distinct mnemonics in its Assembly language for


moving Data.
There are three main opcodes for data movement namely:
• MOV dest., source
• XCH dest., source
• PUSH source or POP dest.
The other mnemonics are often a variation of the above listed
three.
4
Addressing modes
• The 8051 has four addressing modes:
• Immediate- When the source is a part of the instruction. Often times the source is an
operand or value to be stored in a destination. The mnemonic for an immediate value
is the (#) sign. However, assemblers may accept operand values without the #
symbol.
• E.g. MOV A, #n

• Register- When the source (and oftentimes the destination) is a register in the
instruction. The registers A, DPTR, R0-R7can be used in register addressing mode.
• E.g. MOV A, Rn (where n = 0,…..7)

5
Addressing modes
• Direct – The Direct addressing mode allows all 128 bytes of the RAM/SFR
to be addressed using the single byte address allocated to the memory
location. RAM locations are addressed using addresses 00h-7Fh whilst
SFRs use 80h-FFh
• E.g. MOV A, madd (madd is a byte value)
• Indirect- a register or memory address can hold the value of the eventual
source or destination address. The data to be used can be said to be
indirectly accessible this way. The mnemonic symbol used to indicate an
indirect addressing mode is the @ symbol/sign.
• E.g. MOV @Rp, #n (p is a value between 0 and 7)
6
Illustration of Addressing Modes for Data Movement

7
MOV Instruction
• The Move instruction covers movement of data
without modification of the operands.
• Variations include MOVX (when moving to external
data memory location) and MOVC (when moving to
program memory location)

8
MOVX and MOVC Instructions

9
PUSH and POP instructions
• The push instruction copies data from the source
address to the stack(SP- SP is a special function
register is incremented by one) e.g. PUSH add.
• The pop instruction copies data from the stack (SP is
decremented by one) to the destination address. E.g.
POP add.

10
PUSH and POP instructions

11
XCH Instruction
• This Instruction works in a bidirectional way. It moves
instruction from source to destination and from
destination to source.
• Only Register, Direct and Indirect addressing modes can
be used with it.
• XCH instructions may also be used with a port location.
• E.g. XCH A, Rn (n = 0, 1……..7)
12
Boolean (Logical) Operators In 8051
• The following Logical opcodes are in use with the
8051:

• This opcodes can operate on two data levels i.e. Bit


and Byte level.
13
Rotate Opcodes
• There are also auxiliary logical opcodes for rotating byte and the
carry flag in the PSW register.

14
Program Status Word (Flags)

15
Examples of Logical Operation
• Logical operations can be applied in all four
addressing modes:

16
Bit-Level Logical Operations
• Using certain bit addressable RAM addresses certain
bit level logical operations can also be carried out.

17
Bit addressable SFRs and RAM
addresses

18
Arithmetric Operations
• 24 Arithmetic Opcodes are used with the 8051 microcontroller. They are
subdivided into 7 major opcodes namely:

19
Operations affecting Flags
• Three bits of the PSW deal with arithmetic operations. They are the CY, AC
and OV Flags. The following are examples of its modification when
arithmetic operations are been performed:

20
Signed and Unsigned Additions
• All addition operation is done using the A (Accumulator)
register.
• When signed additions are done the MSB (i.e. the 7 bit is
used for the sign). A 1 in the MSB indicates a negative
number whilst a 0 indicates a positive number.
• All negative numbers are in 2’s complement form when
in operation.

21
Jump or Call Operations
Jumps and calls are used for decision making or Branching when
CPU is in operation. Examples include:
• Jump on bit condition
• Call a subroutine
• Decrement a byte and jump on condition value is 0
• Jump unconditionally
• Compare bytes and Jump if equal or not equal
• Return from a subroutine.
22
Jump
• Jumps replace the value in the PC(Program Counter)
with a new value.
• Jump or calls may have one of three ranges:
Short or relative (-127d - +128d)
Long (0000h – FFFFh)
Absolute (2K byte page)

23
Jump Range

24
Bit Jump operation

25
Byte Jump Operation

26
Unconditional Jumps

27
Calls and returns

28
Summary

29

You might also like