Professional Documents
Culture Documents
Unit II
Unit II
• Assembly language allows programmers to have precise control over the computer's
hardware.
1. Efficiency: Assembly language programs can be highly optimized for speed and memory
usage since they operate directly on the hardware.
2. Embedded Systems: Many embedded systems and device drivers are written in assembly
language to maximize performance and minimize resource usage.
3. Operating System Development: Kernel components of operating systems are often written
in assembly language for control and performance reasons.
• Assembly programs typically consist of sections like data, text, and sometimes a stack.
• Instructions are written using mnemonics (e.g., MOV for move) and operands (e.g., registers,
memory addresses).
• Programs start at a specific address (entry point) and execute sequentially unless directed
otherwise.
• Abstraction Level: Assembly language is closer to the hardware, while high-level languages
are more abstract and easier to read/write.
• Portability: High-level languages are more portable across different platforms, while
assembly is specific to a particular architecture.
• Development Speed: High-level languages are faster for application development, while
assembly requires more effort and is error-prone.
• Control: Assembly language offers fine-grained control over hardware, whereas high-level
languages abstract many hardware details.
ADD AX, BX ; Adds the values of AX and BX, storing the result in AX
3. SUB (Subtraction): Subtracts one operand from another and stores the result.
SUB AX, BX ; Subtracts the value of BX from AX, storing the result in AX
5. CMP (Compare): Compares two operands and sets flags based on the result.
• Macros are sequences of instructions that are defined and named to perform specific tasks.
• They allow for code reuse and simplification by encapsulating a series of instructions into a
single, named entity.
• Macros are typically defined using macro assemblers and are invoked using their names.
• To create a macro, you define it using a macro assembler directive, typically starting with
something like MACRO and ending with MEND.
• Macros can be invoked using their names followed by parameter values, if any.
• Macros can greatly improve code readability, maintainability, and reduce redundancy.
• Labels are identifiers used to mark locations or points in your assembly code.
• They are crucial for control flow instructions (e.g., jumps and branches) to reference specific
memory addresses.
• Directives are instructions to the assembler, providing information about the program
layout, data allocation, and other assembly-specific details.
• ORG (Origin): Specifies the memory location where the program should be loaded.
• DB (Define Byte): Reserves memory for one or more bytes and initializes them.
• DW (Define Word): Reserves memory for one or more words (usually 16 bits) and
initializes them.
• There are many other directives like DS for reserving space, EQU for equating values,
and more.
1. Macro Example:
Usage: SQUARE 5
2. Label Example:
START: MOV AX, 1 ADD AX, 2 JMP END LOOP: ; Loop instructions here END: ; End of program
3. Directives Example:
ORG 1000H ; Set program origin to 1000H MOV AX, 5 ; Load 5 into AX DB 10, 20, 30 ; Define three
bytes with values DW 1001H, 2002H ; Define two words with values
• Practical exercises can include creating macros for common arithmetic operations, labeling
code for branching, and using directives to allocate memory and initialize data.
• Arithmetic instructions like ADD and SUB are used for basic calculations.
• Example:
• Input and output operations are crucial for communication with the user.
• Use INT 21h (DOS interrupt) for simple console input and output.
MOV AH, 1 ; Function code for input INT 21h ; DOS interrupt
• Conditional instructions like JZ (jump if zero) and JNZ (jump if not zero) are used.
• Example:
• Microprocessor timings refer to the precise timing and synchronization of various operations
performed by a microprocessor during the execution of instructions.
• Timings are crucial to ensure that instructions are executed accurately and efficiently.
• Timings are critical for designing real-time systems, where precise timing is crucial.
• The instruction cycle is the fundamental process through which a microprocessor executes
instructions.
1. Fetch Cycle:
• Involves retrieving the next instruction from memory.
2. Decode Cycle:
3. Execute Cycle:
4. Memory Cycle:
• Timings are essential for data transfer between the CPU and memory.
• They are used to measure and control the timing of each operation.
• Significance of T states:
Key Takeaways:
• Microprocessor timings are essential for precise and efficient execution of instructions.
• The instruction cycle consists of fetch, decode, execute, and memory stages.
The instruction cycle, also known as the fetch-decode-execute cycle, is the fundamental process that
a computer's central processing unit (CPU) follows to execute instructions from a program. It
consists of several machine cycles, each of which plays a crucial role in the execution of instructions.
The instruction cycle can be summarized in the following steps:
1. Fetch: In this phase, the CPU fetches the next instruction from memory. The program
counter (PC) is used to keep track of the address of the next instruction. The CPU reads the
instruction from memory and loads it into the instruction register (IR).
2. Decode: Once the instruction is in the IR, the CPU decodes it to determine what operation
needs to be performed and which operands are involved. This phase typically involves
breaking down the instruction into its constituent parts, such as the opcode (operation
code) and operand(s).
3. Execute: In this phase, the CPU performs the actual operation specified by the instruction.
This could involve arithmetic calculations, data transfers, logical operations, and more,
depending on the instruction's type.
4. Memory Access: Some instructions may require accessing memory to read or write data.
This phase, known as the memory cycle, is responsible for interacting with the computer's
memory subsystem. It includes memory read and write operations as necessary.
5. Write Back: The final phase of the instruction cycle involves storing the result of the
execution back into registers or memory locations as needed. This phase ensures that any
changes made by the instruction are saved for future use.
In-Depth Discussion of Each Machine Cycle:
1. Fetch Cycle:
• Steps:
• The program counter (PC) is incremented to point to the address of the next
instruction.
• The CPU reads the instruction from the memory location pointed to by the
PC.
2. Decode Cycle:
• Steps:
3. Execute Cycle:
• Steps:
4. Memory Cycle:
• Steps:
• Steps:
• The final results of the operation are written back to registers or memory
locations, ensuring that any changes are saved.
Practical Examples Illustrating Machine Cycles: