0% found this document useful (0 votes)
3 views11 pages

Mat

The document explains the three levels of programming languages for the 8051 Microcontroller: Machine Language, Assembly Language, and High-level Language. It details the characteristics and advantages of Assembly Language, including its efficiency and direct hardware control, and outlines the structure of assembly programs, types of instructions, and the assembly process. Additionally, it describes the development tools and environments necessary for embedded system development.

Uploaded by

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

Mat

The document explains the three levels of programming languages for the 8051 Microcontroller: Machine Language, Assembly Language, and High-level Language. It details the characteristics and advantages of Assembly Language, including its efficiency and direct hardware control, and outlines the structure of assembly programs, types of instructions, and the assembly process. Additionally, it describes the development tools and environments necessary for embedded system development.

Uploaded by

senthil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1

Programming Languages
There are three types or levels of Programming Languages for 8051
Microcontroller. These levels are based on how closely the statements
in the language resemble the operations or tasks performed by the
Microcontroller.

Machine language
In Machine language or Machine Code, the instructions are written in
binary bit patterns i.e. combination of binary digits 1 and 0, which are
stored as HIGH and LOW Voltage Levels. This is the lowest level of
programming languages and is the language that a Microcontroller or
Microprocessor actually understands.

Assembly Language
The next level of Programming Language is the Assembly Language.
Since Machine Language or Code involves all the instructions in 1’s
and 0’s, it is very difficult for humans to program using it.

Assembly Language is a pseudo-English representation of the


Machine Language. The 8051 Microcontroller Assembly Language is
a combination of English like words called Mnemonics and
2

Hexadecimal codes.

It is also a low level language and requires extensive understanding of


the architecture of the Microcontroller.

High-level Language
The name High-level language means that you need not worry about
the architecture or other internal details of a microcontroller and they
use words and statements that are easily understood by humans.

Few examples of High-level Languages are BASIC, C Pascal, C++


and Java. A program called Compiler will convert the Programs written
in High-level languages to Machine Code.

Why Assembly Language?


The name High-level language means that you need not worry about
the architecture or other internal details of a microcontroller and they
use words and statements that are easily understood by humans.

Although High-level languages are easy to work with, the following


reasons point out the advantage of Assembly Language

 The Programs written in Assembly gets executed faster and they occupy
less memory.
 With the help of Assembly Language, you can directly exploit all the
features of a Microcontroller.
 Using Assembly Language, you can have direct and accurate control of
all the Microcontroller’s resources like I/O Ports, RAM, SFRs, etc.
 Compared to High-level Languages, Assembly Language has less rules
and restrictions.
3

1. Fundamentals of Assembly Language Programming


Assembly Language is a low-level programming language that provides direct control over
hardware. It uses mnemonics (symbolic operation codes) to represent machine-level
instructions.

Key Features:

 Close to hardware (direct memory, port access).


 Faster and memory-efficient.
 Specific to processor architecture (e.g., 8051, x86).
 Needs an assembler to convert into machine code.

2. Components of Assembly Language


Component Description
Label Name assigned to a line/address for jumps, loops, etc.
Mnemonic Instruction opcode (e.g., MOV, ADD, SUB)
Operands Data or registers the instruction acts on
Comments Explanatory text following ; (semicolon)

📝 Example:
asm
CopyEdit
START: MOV A, #0x25 ; Load immediate data into accumulator
ADD A, R1 ; Add register R1 to accumulator
SJMP START ; Infinite loop

3. Instruction to Assembler
When writing assembly code, instructions are written using mnemonics and assembled using
an assembler, which converts them into machine code (hex code) that the microcontroller
understands.

🔑 Types of Instructions:

Type Description Example


Data Transfer Move data between registers, memory MOV A, #0x10
Arithmetic Add, subtract, multiply, divide ADD A, R1
Logical AND, OR, XOR, NOT ANL A, #0Fh
4

Type Description Example


Branching Jump, call, return, conditional jumps SJMP LOOP, JNZ LABEL
Bit Manipulation Set, clear, complement bits SETB P1.0, CLR CY
Control Instructions Stop or manage execution NOP, RET

4. Assembly Process Overview


1. Writing Code: Use mnemonics and structure your code.
2. Assembler: Converts .asm → .obj → .hex file.
3. Linker: Combines multiple object files if needed.
4. Simulator/Debugger: Test and debug code before deployment.
5. Burn/Flash: Transfer .hex to microcontroller memory.

5. Example: Simple Assembly Program (8051)


asm
CopyEdit
ORG 0000H ; Origin – program start
MOV A, #0x05 ; Load 5 into accumulator
MOV B, #0x02 ; Load 2 into register B
MUL AB ; Multiply A and B → A = 0x0A, B = 0x00
HERE: SJMP HERE ; Infinite loop
END ; End of program

Assembler Directives vs Instructions


Assembler Directive Purpose Example
ORG Set start address ORG 0000H
END End of source file END
DB, DW Define byte/word DB 'HELLO'
EQU Define constant MAX EQU 0xFF

These directives guide the assembler but do not generate machine instructions.

Assembly language programming gives precise control of hardware, essential for embedded
systems like the 8051. Understanding the basic structure, instruction types, and how to
communicate with the assembler is fundamental for low-level programming and
microcontroller-based system design.
5

Assembly Language of 8051


Assembly languages were developed to provide mnemonics or symbolic names for machine-
level instructions. These mnemonics make programming more readable and understandable than
using binary opcodes directly.

Assembly language programs consist of mnemonics, and these must be translated into machine
code for execution. A program that performs this conversion is called an assembler.

Why Assembly Language is Called Low-Level

Assembly language is often termed a low-level language because it directly interacts with the
internal architecture of the CPU. Programming in assembly requires detailed knowledge of:

 CPU registers
 Memory structure
 Flags
 Instructions set

In contrast, high-level languages like C, C++, Java abstract away the hardware details and are
easier to write and debug. They rely on a compiler to convert source code into machine code.

🔹 Role of Assembler vs. Compiler

Language Type Translator Example


Assembly Language Assembler ADD A, B → Opcode
High-Level Language Compiler a = b + c; → Opcode

 An assembler translates assembly language into machine code (also called object code
or opcode).
 A compiler translates a high-level language into machine language.
6

Structure of an Assembly Language Program


An assembly program is made up of lines of code consisting of:

1. Instructions (e.g., ADD, MOV)


2. Assembler directives (e.g., ORG, END)

 An instruction tells the CPU what operation to perform.


 A directive tells the assembler how to process the program (these are not converted into
machine instructions).

Typical Line Format

Each line of an assembly program may contain up to four fields:

css
CopyEdit
[label:] mnemonic [operands][;comment]

Field Description Example


Label (Optional) Name used for jumps or references LOOP:
Mnemonic Operation code (instruction) MOV, ADD, SJMP
Operands Registers, memory addresses, or constants A, #0x05
Comment (Optional) Explanation, begins with ; ; Load 5 into accumulator

Example Program (8051)


asm
CopyEdit
ORG 0000H ; Set starting address
MOV A, #0x05 ; Load 5 into accumulator
MOV B, #0x03 ; Load 3 into B
MUL AB ; Multiply A and B
SJMP $ ; Stay here (infinite loop)
END ; End of program
7

Steps in Assembly Language Programming:

8051 Microcontroller Assembly Directives


8

Assembly Language Directives are actually instructions to the Assembler and


directs the Assembler Program what to do during the process of Assembling.
9

8051 Development Tools and Environments:

The goal of an Embedded System Development Environment is to enable a developer to


create the application firmware for a Microcontroller Control Unit (MCU) based hardware
design. Application development consists of five steps:

 Coding - writing the application in a humanly readable form


 Building - converting the humanly readable code to a machine-readable
code
 Simulation - verifying the application will work before it is programmed
into an MCU
 Programming - placing the machine-readable code into the MCU's non-
volatile program memory
 Debugging - identifying and removing any unforeseen anomalies in
operation after the application has been programmed into the MCU
The primary component of a contemporary development system is a
software package called an Integrated Development Environment
(IDE). IDEs provide a user interface for the application developer to
coordinate the development activities. Depending on the developer's
needs, the IDE may communicate with other software packages called
compilers and hardware devices called programmer/debuggers.
1. Move Immediate Data
assembly
CopyEdit
MOV A, #25H ; Load 25H into Accumulator
MOV R0, #10H ; Load 10H into Register R0
10

✅ 2. 8-bit Addition
assembly
CopyEdit
MOV A, #0AH ; A = 0AH
ADD A, #05H ; A = A + 05H = 0FH

✅ 3. 8-bit Subtraction
assembly
CopyEdit
CLR C ; Clear carry before subtraction
MOV A, #10H
SUBB A, #06H ; A = A - 06H = 0AH

✅ 4. 8-bit Multiplication
assembly
CopyEdit
MOV A, #03H
MOV B, #04H
MUL AB ; A = LSB, B = MSB → A = 0CH, B = 00H

✅ 5. 8-bit Division
assembly
CopyEdit
MOV A, #10H ; 16
MOV B, #04H ; 4
DIV AB ; A = 04H (quotient), B = 00H (remainder)

✅ 6. Logical AND, OR, XOR


assembly
CopyEdit
MOV A, #0F0H
ANL A, #0FH ; A = 00H
ORL A, #03H ; A = 03H
XRL A, #01H ; A = 02H

✅ 7. Rotate Accumulator
assembly
CopyEdit
MOV A, #81H
RL A ; Left rotate → A = 03H
11

RR A ; Right rotate → A = 81H

✅ 8. Call Subroutine (using LCALL)


assembly
CopyEdit
MAIN: LCALL DELAY
SJMP MAIN

DELAY: MOV R2, #FFH


LOOP1: DJNZ R2, LOOP1
RET

✅ 9. Counter with DJNZ


assembly
CopyEdit
MOV R3, #0AH ; Initialize counter
LOOP: DJNZ R3, LOOP

✅ 10. Store Data in Internal RAM


assembly
CopyEdit
MOV A, #55H
MOV 30H, A ; Store 55H at RAM location 30H

✅ 11. Toggle a Pin (e.g., P1.0)


assembly
CopyEdit
SETB P1.0 ; Set pin high
ACALL DELAY
CLR P1.0 ; Set pin low
ACALL DELAY
SJMP $

✅ 12. Send Data to Port


assembly
CopyEdit
MOV A, #0FFH
MOV P2, A ; Send FFH to port 2

You might also like