CPE317 Microprocessor (Part 2) PDF

Summary

This document provides an overview of assembly language, compilation flow, and machine language for microprocessors. It details instructions, directives, and data definitions used in assembly language programming.

Full Transcript

**CPE317 MICROPROCESSOR (part 2)** - **ASSEMBLY LANGUAGE:** Low-level programming language for microprocessors and other devices.\ Basic programming language for processors.\ Processors understand machine language instructions. - **COMPILATION FLOW:** - ***C/C++ Compi...

**CPE317 MICROPROCESSOR (part 2)** - **ASSEMBLY LANGUAGE:** Low-level programming language for microprocessors and other devices.\ Basic programming language for processors.\ Processors understand machine language instructions. - **COMPILATION FLOW:** - ***C/C++ Compilation Process***:\ \ **[Preprocessing:]** Processes include-files, conditional compilation instructions, and macros.\ **[Compilation:]** Takes preprocessor output and source code, generates assembler source code.\ **[Assembly:]** Produces assembly listing with offsets from assembly source code.\ **[Linking:]** Combines object files or libraries to produce a single file. - **MACHINE LANGUAGE --** z=x+y ![](media/image2.png) - **MACHINE & ASSEMBLY LANGUAGE:** - ***Assembly Language Overview:\ *** Uses symbolic names for operations, registers, memory locations.\ Higher-level language with better instructions readability.\ Provides one-to-one correspondence with machine language instructions. - **[Assemblers]** translate assembly to machine code - **[Compilers]** translate high-level programs to machine code, either directly or indirectly, via an assembler - **ASSEMBLER** - An assembler is a program that converts source-code programs written in assembly language into object files in machine language. - TASM (Turbo Assembler from Borland) - MASM (Microsoft Macro Assembler) - NASM (Netwide Assembler for both Windows and Linux), and - GNU assembler distributed by the free software Foundation - **MNEMONICS --** MOV AX, BX Specify opcode for complete machine language instruction.\ Assembler translates to generate object code.\ MOV used for data copy/movement between registers/memory locations. - **INSTRUCTION:**\ Program commands i***nstructions*** computer actions.\ Computers handle binary data; hence instructions must be in binary format (0s, 1s).\ All binary instructions form the computer\'s ***machine language***, also known as the ***instruction set***. - **INTRUCTION FIELDS:** - Opcode field specifies specific operation. - Each operation has unique opcode. - Operands fields specify source and destination operands. - Source/destination can be constant, memory, or general-purpose registers. - **ASSEMBLY INSTRUCTION --** Built from two pieces ![](media/image4.png) - **TYPES OF OPCODES:** - ***Arithmetic & Logical*** ADD, SUB, MULT, AND, OR, CMP - ***Memory Load/Store*** LOAD, LD, LOD, ST - ***Control Transfer*** JMP, BNE - ***Complex*** MOVS - **ASCII:** Scheme for assigning numeric values to punctuation marks, spaces, numbers, etc.\ Uses 7 bits for character representation.\ Uses values 0000000-1111111 or 00-7F for 128 characters.\ Extended version assigns characters from 80-FF. - **PARTS OF ASSEMBLY LANGUAGE PROGRAM:** - Header Files - Directives - Labels - Comments - **ASSEMBLY LANGUAGE: HEADER FILES** No direct concept of header files.\ Used to define functions, variables, macros.\ Can be included in multiple source files. - **MACROS:** Defined using ***.macro*** and ***.endm*** directives.\ Useful for defining reusable code blocks.\ Can take parameters and be expanded inline during assembly. 1. **INCLUDE:** Supports ***.include*** for file inclusion.\ Facilitates sharing of common definitions or code snippets. 2. **EXTERNAL REFERENCE:** Declareable using ***.extern*** directive.\ Symbols can be in assembly files or C/C++ code.\ Linker resolves external references during linking process. 3. **Org 100h:** Specific to MASM and TASM.\ Sets code segment origin.\ Involves org 100h, instructing assembler to place instructions at memory address 100h. 4. **include 'emu8086.inc':\ ** Includes emu8086.inc file for EMU8086 environment definitions.\ Provides macro functions for IO, mathematic operations**.** - **DIRECTIVES:** Commands for controlling assembly process.\ Guide assembler in interpreting and translating assembly code. 1. **DATA DEFINITION DIRECTIVES:** A. **[DB/db] -** This data definition directive defines bytes of data. Example: message DB \'Hello, world!\', 13, 10, '\$' message db 'Hello, world!', 13, 10, '\$' B. **[DW/dw -]** This data definition directive defines words of data. Example: number DW 1234h number dw 1234h C. DD/dd - This data definition directive defines doublewords of data. Example: dword\_value DD 12345678h dword\_value dd 12345678h D. **DQ/dq -** This data definition directive defines quadwords of data. Example: qword\_value DQ 123456789ABCDEF0h qword\_value dq 123456789ABCDEF0h 2. **SEGMENT DEFINITION DIRECTIVES:** A. **.data -** This segment definition directive defines the data segment. ![](media/image6.png) B. **.code -** This segment definition directive defines the code segment. C. **.bss -** EMU8086 Assembly: Segment Definition Directive\ Defines initialized data segment.\ Doesn\'t support this directive.\ Uses.data directive. - **OTHER DIRECTIVES:** *\*\* These directives are not directly supported in the EMU8086 assembler. \*\** - ***.align:*** Aligns the next data or instruction to a specified boundary. - ***.byte:*** Defines a byte-sized value. - ***.word:*** Defines a word-sized value. - ***.long:*** Defines a long word-sized value. - **MEMORY MODEL:** Organize and manage memory segments for code, data, and stack.\ Crucial in older 16-bit x86 architectures.\ Ensured limited and segmented memory. - *Here is the list of common memory model stacks used in* *Assembly Language:* a. Small Model b. Medium Model c. Compact Model d. Large Model e. Huge Model A. **SMALL MODEL:** Specifics 64KB code and data segments.\ Ideal for small programs. B. **MEDIUM MODEL:** Code segments up to 1MB.\ Data segments limit to 64KB each. C. **COMPACT MODEL:** Data segments up to 1MB.\ Code segments limit to 64KB each. D. **LARGER MODEL:** Specifies memory model.\ Can hold up to 1MB code/data segments. E. **HUGE MODEL:** Specifies memory model.\ Can accommodate up to 4GB code/data segments. - **KEY POINTS OF MEMORY MODELS:** - Memory Model Impact on Program\ Affects addressing modes and instructions.\ Choice impacts performance and code size.\ Limitations exist, especially for larger programs. - **LABELS:** Symbolic names for memory locations.\ Mark jump instructions target.\ Define entry procedure.\ Reference data locations. - **COMMENTS -** Comments are supplementary text added to the code to enhance comprehension, but they are typically ignored by the assembler. - **BEST PRACTICE FOR USING LABELS & COMMENTS:** a. ***Clear and Concise Labels:*** Use meaningful labels that reflect the purpose of the code. b. ***Consistent Formatting:*** Use consistent indentation and spacing to improve readability. c. ***Explain Non-Obvious Code:*** Comment on complex or tricky parts of the code. d. ***Use Comments to Describe the Overall Purpose of a Code Section.*** e. ***Avoid Over-Commenting:*** Too many comments can clutter the code. f. ***Update Comments as Code Changes:*** Ensure comments remain accurate. - **CONTROL FLOW INSTRUCTION -** Control flow instructions are used to alter the normal sequential execution of instructions. Here are some common control flow instructions: a. Unconditional Jump b. Conditional Jump c. Looping d. Procedures and Subroutines - **UNCONDITIONAL JUMP:** Fundamental control flow mechanism.\ Allows abrupt program execution transfer.\ Doesn\'t meet specific condition.\ Defined as \"unconditional.\" - **CONDITONAL JUMP:** Instruction altering program\'s control flow.\ Condition evaluated through value comparison or processor flag status check. - ***Conditional Jumps instruction:*** a. **[JZ label:]** Jump if zero b. **[JNZ label]**: Jump if not zero c. **[JA label:]** Jump if 1st operand is above the 2nd d. **[JB label:]** Jump if 1st operand is below the 2nd e. **[JE label:]** Jump if 1st operand is equal to the 2nd f. **[JNE label]**: Jump if 1st operand is not equal to the 2nd g. **[JG:]** Jump inf 1st operand is greater than the 2nd h. **[JL:]** Jump if the 1st operand is less than the 2^nd^ - **LOOPING:** Executes code block repeatedly until condition is met.\ Combines conditional jumps and instruction counters. a. ***Loop instruction*** automatically decrements CX register and jumps back to label if CX isn\'t zero. b. ***Conditional jump (JLE)*** checks if condition is met, jumps back to loop start if necessary. - **PROCEDURES & SUBROUTINES:** Facilitates modularity.\ Enhances code reusability.\ Improves program organization. a. ***Procedures:*** Sequence of instructions for specific tasks. b. ***Subroutines:*** Smaller, specialized tasks for multiple locations.

Use Quizgecko on...
Browser
Browser