[go: up one dir, main page]

0% found this document useful (0 votes)
15 views56 pages

Addressing Modes

The document provides an overview of computer languages, detailing machine language, assembly language, and high-level languages, along with their characteristics and examples. It explains syntax, semantics, compilers, and interpreters, highlighting the differences between compilation and interpretation. Additionally, it covers addressing modes and instruction sets specific to the 8051 microcontroller, including arithmetic, logical, data transfer, and branching instructions.

Uploaded by

yinka8380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views56 pages

Addressing Modes

The document provides an overview of computer languages, detailing machine language, assembly language, and high-level languages, along with their characteristics and examples. It explains syntax, semantics, compilers, and interpreters, highlighting the differences between compilation and interpretation. Additionally, it covers addressing modes and instruction sets specific to the 8051 microcontroller, including arithmetic, logical, data transfer, and branching instructions.

Uploaded by

yinka8380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

CPE 413

Computer Languages

– Machine Language
• Uses binary code
• Machine-dependent
• Not portable
◼ Assembly Language
◼ Uses mnemonics
◼ Machine-dependent
◼ Not usually portable
◼ High-Level Language (HLL)
◼ Uses English-like language
◼ Machine independent
◼ Portable (but must be compiled for different platforms)
◼ Examples: Pascal, C, C++, Java, Fortran, . . .
Machine Language

◼ The representation of a computer program which is


actually read and understood by the computer.
◼ A program in machine code consists of a sequence of machine
instructions.
◼ Instructions:
◼ Machine instructions are in binary code
◼ Instructions specify operations and memory cells involved in the
operation Operation Address
Example: 0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
Assembly Language

◼ A symbolic representation of the machine language of a


specific processor.
◼ Is converted to machine code by an assembler.
◼ Usually, each line of assembly code produces one
machine instruction (One-to-one correspondence).
◼ Programming in assembly language is slow and error-
prone but is more efficient in terms of hardware
performance.
◼ Mnemonic representation of the instructions and data
◼ Example:
Load Price
Add Tax
Store Cost
High-level language
• A programming language which use statements
consisting of English-like keywords such as "FOR",
"PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine
language instructions (one-to-many correspondence).
• Much easier to program than in assembly language.
• Data are referenced using descriptive names
• Operations can be described using familiar symbols
• Example:
Cost := Price + Tax
Syntax & Semantics
◼ Syntax:
◼ The structure of strings in some language. A
language's syntax is described by a grammar.
◼ Examples:
◼ Binary number
<binary_number> = <bit> | <bit> <binary_number>
<bit> =0|1
◼ Identifier
<identifier> = <letter> {<letter> | <digit> }
<letter> =a|b|...|z
<digit =0|1|...|9
◼ Semantics:
◼ The meaning of the language
Syntax & Grammars
◼ Syntax descriptions for a PL are
themselves written in a formal language.
◼ E.g. Backus-Naur Form (BNF)
◼ The formal language is not a PL but it can
be implemented by a compiler to enforce
grammar restrictions.
◼ Some PLs look more like grammar
descriptions than like instructions.
Compilers & Programs
• Compiler
– A program that converts another program from
some source language (or high-level programming
language / HLL) to machine language (object
code).
– Some compilers output assembly language which is
then converted to machine language by a separate
assembler.
– Is distinguished from an assembler by the fact that
each input statement, in general, correspond to
more than one machine instruction.
Compilation into Assembly L

Source Assembly
Program Compiler Language

Assembly Machine
Assembler
Language Language
Compilers & Programs
• Source program
– The form in which a computer program, written
in some formal programming language, is
written by the programmer.
– Can be compiled automatically into object code
or machine code or executed by an interpreter.
– Pascal source programs have extension ‘.pas’
Compilers & Programs

• Object program
– Output from the compiler
– Equivalent machine language translation of the
source program
– Files usually have extension ‘.obj’

• Executable program
– Output from linker/loader
– Machine language program linked with necessary
libraries & other files
– Files usually have extension ‘.exe’
What is a Linker?
◼ A program that pulls other programs together so
that they can run.
◼ Most programs are very large and consist of
several modules.
◼ Even small programs use existing code
provided by the programming environment
called libraries.
◼ The linker pulls everything together, makes sure
that references to other parts of the program
(code) are resolved.
Program Execution
• Steps taken by the CPU to run a program
(instructions are in machine language):
1. Fetch an instruction
2. Decode (interpret) the instruction
3. Retrieve data, if needed
4. Execute (perform) actual processing
5. Store the results, if needed
Program Errors
◼ Syntax Errors:
◼ Errors in grammar of the language

◼ Runtime error:
◼ When there are no syntax errors, but the program can’t complete
execution
◼ Divide by zero

◼ Invalid input data

◼ Logical errors:
◼ The program completes execution, but delivers incorrect results

◼ Incorrect usage of parentheses


Compilation
Source Target
Program Compiler Program

Input Target Program Output

◼ Compiler translates source into target (a machine language


program)
◼ Compiler goes away at execution time
◼ Compiler is itself a machine language program, presumably created
by compiling some other high-level program
◼ Machine language, when written in a format understood by the OS is
object code
Interpretation
Source
Program

Interpreter Output

Input

• The interpreter stays around during execution


• It reads and executes statements one at a time
Compilation vs. Interpretation
◼ Compilation:
◼ Syntax errors caught before running the program

◼ Better performance

◼ Decisions made once, at compile time

◼ Interpretation:
◼ Better diagnostics (error messages)

◼ More flexibility

◼ Supports late binding (delaying decisions about program


implementation until runtime)
◼ Can better cope with PLs where type and size of variables
depend on input
◼ Supports creation/modification of program code on the fly (e.g.
Lisp, Prolog)
Mixture of C & I
Source Intermediate
Program Translator Program

Intermediate
Program
VM Output

Input

• Many programming languages implement this

• Interpreter implements a Virtual Machine (VM).


ADDRESSING MODES &
INSTRUCTIONS SET OF
8051 MICRO CONTROLLER
Addressing modes
❖ Definition:-
The different ways in which a
source operand in an instruction are known
as the addressing modes.
The 8051 provides a total of 5
distinct addressing modes.
Types of Addressing modes

Addressing modes

Immediate Register Direct Register indirect Indexed


Addressing mode Addressing mode Addressing mode Addressing mode Addressing mode
Immediate addressing mode
In this addressing mode the source
operand is constant. In immediate
addressing mode, when the instruction is
assembled, the operand comes
immediately after the op-code.
Continue…

▪ The immediate data must be


preceded by ‘#’ sign.

▪ This addressing mode can be used to


load information into any of the
register, including the DPTR.
Continue…
▪ Ex :-

MOV A,#25H // load 25H in to A


MOV R4,#62 // load the decimal
value 62 into R4.
MOV DPTR,#4532H // DPTR=4532H.
Register addressing mode
Register addressing mode
involves the use of registers to hold
the data to be manipulated.
Continue…
➢ Ex :-
MOV A,R0 // copy the contents of R0 in to
A.
MOV R2,A // copy the contents of A in to
R2.
ADD A,R5 // add the content of R5 to
content of A.
Direct addressing mode
In direct addressing mode, the
data is in a RAM memory location whose
address is known, and this address is given
as a part of the instruction. Contrast this
with the immediate addressing mode in
which the operand itself is provided with the
instruction.
Direct addressing mode
◼ In this mode the operand is specified by
an 8-bit address field In the instruction.

◼ One can access all the 128 bytes of


internal RAM locations and each SFR.

◼ If the MSB bit = 0 then the location is


within on chip internal RAM. If MSB bit = 1
then the location is SFR.
30
Direct addressing mode
◼ The location 00h to 7Fh to address the
internal RAM .
◼ SFR addresses from 80h to FF h

◼ e.g. MOV A,40h


MOV R0,14h

32
Continue…
➢ Ex:-
MOV R0,40H // save content of RAM
location 40h into R0.
MOV 56H,A // save content of A in
RAM location 56H.
Register indirect addressing mode

◼ In the register indirect addressing mode,


a register is used as a pointer to the data.
◼ If the data is inside the CPU, only register
R0 and R1 are used for this purpose.
◼ In other words,R2-R7 cannot be used to
hold the address of an operand located in
RAM when using this addressing mode.
Continue…
➢When R0 and R1 are used as pointers ,
that is, when they hold the address of
RAM locations , they must be preceded by
the “@” sign.
Note : only register R0 and R1 can be used
for indirect addressing mode .
MOV A,@R2 invalid instruction.
Continue…
Ex :-
MOV A,@R0 // move contents of RAM
location whose address
is held by R0 into A.
MOV @R1,B // move contents of B to
RAM location whose
address is held by R1
External addressing mode
or Indexed addressing mode
(a) Code access (ROM access)
◼ Using these instructions only program
memory can be accessed.

◼ This addressing mode is preferred for


reading look up tables in the program
memory.

◼ Either DPTR or PC can be used as pointer.


40
External addressing mode
or Indexed addressing mode
◼ E.g.
MOVC A,@A+DPTR

MOVC A,@A+PC

42
External addressing mode
or Indexed addressing mode
(b) Data access (RAM access)

◼ Using this addressing mode the programmer


can access the external Data memory

◼ E.g. MOVX A,@DPTR


MOVX @R0,A

Prof. Nitin Ahire 43


Continue…
➢ In this instruction the content of A are
added to the 16-bit register DPTR to form
the 16-bit address of the needed data.
Instruction set of 8051
8051 has simple instruction set in
different groups. There are:
▪ Arithmetic instructions
▪ Logical instructions
▪ Data transfer instructions
▪ Branching and looping instructions
▪ Bit control instructions
Arithmetic instructions
These instructions are used to
perform various mathematical operations
like addition, subtraction, multiplication, and
division etc.
Continue…
▪ ADD A, R1 // Add the content of register1
to Accumulator
▪ ADDC A,#2 // Add 2 to accumulator with
carry
▪ SUBB A,R2 // Subtract content of register2
from Accumulator
Continue…
▪ INC A // Increment accumulator
▪ DEC A // Decrement accumulator
▪ MUL AB // Multiply A and B
▪ DIV AB // Divide A by B
Logical instructions
◼ The logical instructions are the instructions
which are used for performing some
operations like AND, OR, NOT, X-OR and
etc., on the operands.
Continue…
◼ ANL A, Rn // AND register to accumulator
◼ ORL A, Rn // OR register to accumulator
◼ XRL A, Rn // Exclusive OR Reg to Acc
◼ CLR A // Clear Accumulator
◼ CPL A // Complement Accumulator
Data Transfer Instructions
◼ These instruction are used to transfer the
data from source operand to destination
operand. All the store, move, load,
exchange input and output instructions
belong to this to this group.
Continue…
◼ MOV A, Rn // Move Reg to Acc
◼ MOVX A,@DPTR // Move external RAM
to Accumulator
◼ PUSH direct // PUSH direct byte on
to stack
◼ POP direct // POP direct byte from
stack
Branch and Looping Instructions
◼ These instructions are used for both
branching as well as looping.
◼ These instructions include conditional &
unconditional jump or loop instructions.
Conditional Jump Instructions
◼ JC // Jump if carry equal to one
◼ JNC // Jump if carry equal to zero
◼ JB // Jump if bit equal to one
◼ JNB // Jump if bit equal to zero
◼ JBC // Jump if bit equal to one and clear
bit
Continue…
◼ JZ // Jump if A=Zero
◼ JNZ // Jump if A not equal to zero
◼ DJNZ // Decrement and Jump if not
equal to zero.
Unconditional Jump Instructions
◼ In 8051 there two unconditional jumps.
They are:
◼ SJMP // Short jump
◼ LJMP // Long jump

You might also like