4. ASSEMBLY LANGUAGE PROGRAMMING
Assembly language programming is used for writing low-level programs that directly control the hardware of the microcontroller. It allows for more efficient use of system resources and is often used in embedded systems. In this section, we’ll cover software development steps, development tools, the role of files in simulators like RIDE or KEIL, and important directives in assembly language programming.
4.1. Software Development Steps
The software development for 8051 assembly programming typically follows a series of structured steps to create and run the program. These steps are:
Problem Analysis:
- Understand the requirements of the system or problem that needs to be solved.
- Break down the problem into smaller, manageable tasks.
Algorithm Design:
- Develop an algorithm that logically solves the problem.
- The algorithm should be written in a step-by-step manner that can be translated into assembly code.
Writing the Program:
- Use an assembler to write the assembly code.
- The program is written using instructions from the 8051 instruction set.
- Proper labels, comments, and structured code should be used.
Compiling the Code:
- The assembler converts the assembly code into machine code.
- The output of the assembler is an object file (.obj).
Linking:
- The object file is linked with other necessary code libraries or external code using a linker.
- The linker generates an executable file that can be loaded onto the microcontroller.
Loading:
- The final executable file is loaded into the microcontroller’s memory using a loader.
- This step prepares the program for execution.
Testing and Debugging:
- Simulators or real hardware can be used to test the program.
- Any errors or issues found during testing are fixed by updating the assembly code and repeating the compilation process.
Optimization (Optional):
- If necessary, optimize the code for better performance or reduced memory usage.
4.2. Software Development Tools
There are several software development tools used in the creation and debugging of 8051 assembly programs. These tools help streamline the development process and ensure that programs run as expected.
1. Editor
- An editor is used to write the assembly code. Some popular editors include:
- KEIL µVision: A fully-featured IDE that includes an editor for writing assembly programs.
- Notepad++ or Sublime Text: General text editors that support syntax highlighting for assembly language.
- The editor allows the programmer to write, edit, and save the assembly code in a text file (usually with the
.asm
extension).
2. Assembler
- The assembler is a tool that converts the assembly language code into machine code or object code.
- KEIL Assembler or ASM51 can be used as assemblers for the 8051 microcontroller.
- The output of the assembler is an object file (.obj), which contains machine code that can be executed by the 8051 microcontroller.
3. Linker
- A linker combines multiple object files into a single executable file, resolving references between different files or external libraries.
- The linker generates an executable file (often with the
.hex
or.bin
extension). - Example tools: KEIL Linker, RIDE Linker.
4. Loader
- A loader is a tool that transfers the executable file to the microcontroller's memory.
- The loader communicates with the hardware (via USB, serial, or other interfaces) to write the program into the Flash memory or EPROM of the 8051.
5. Hex Converters
- Hex converters are used to convert the machine code into a hexadecimal format that can be used by the microcontroller.
- The hex file is the final output that is used by the loader to upload the program into the microcontroller.
- The .hex file is typically a Intel HEX format that contains memory addresses and corresponding data.
4.3. Role of Various Files Created at Various Levels in Running an Assembly Program Using Simulators like RIDE or KEIL
When writing and running an 8051 assembly program, multiple files are generated at various stages of the development process. Each of these files serves a specific role in the creation, debugging, and execution of the program. Below are the main file types and their roles:
Source Code File (.asm)
- This is the original assembly language file where the programmer writes the code.
- Example:
program.asm
- The file contains instructions, labels, data, and comments.
Object File (.obj)
- After the code is assembled, the object file is generated.
- This file contains the machine code but is not yet executable.
- It may need to be linked with other object files or libraries before it becomes an executable program.
- Example:
program.obj
Executable File (.hex)
- After linking, the executable file is created, often in the hexadecimal format.
- This file can be loaded onto the microcontroller and executed.
- It contains memory addresses and machine code in a format that the microcontroller can read.
- Example:
program.hex
Listing File (.lst)
- This file is an optional output generated by some assemblers and linkers.
- It contains a detailed listing of the assembly code, the corresponding machine code, and memory addresses.
- It is useful for debugging and understanding how the assembly code translates to machine code.
- Example:
program.lst
Symbol File (.sym)
- This file contains symbolic information used for debugging purposes.
- It includes information about variable names, function names, and memory locations.
Map File (.map)
- This file provides memory layout information, showing how different parts of the code and data are stored in memory.
4.4. Various Directives of Assembly Language Programming
Directives are special instructions in assembly programming that do not generate machine code but instead control the assembly process, memory allocation, and other aspects of code generation. The most commonly used 8051 assembly language directives are:
1. EQU (Equate)
- Used to assign a constant value to a label or symbol.
- Example:
2. DB (Define Byte)
- Used to define one or more bytes of data.
- Example:
3. DW (Define Word)
- Used to define a word (2 bytes) of data.
- Example:
4. ORG (Origin)
- Specifies the starting memory address where the code or data should be placed in memory.
- Example:
5. END
- Marks the end of the source file.
- Example:
6. JMP (Jump)
- A control flow instruction used to jump to a different part of the program.
- Example:
7. CODE and DATA Sections
- Define sections for code and data.
- Example:
8. MACRO
- Defines a macro (a set of instructions that can be reused multiple times in the program).
- Example:
9. IF, ELSE, ENDIF
- Conditional assembly: Assembler directives that allow for conditional compilation of code.
- Example:
0 Comments