GROUP (1)
GROUP (1)
o Examples:
o Types:
Instruction Format:
o Defines how the instruction is encoded.
o Intel x86:
Addressing Modes:
o Determines how operands are accessed (e.g., direct, indirect, immediate).
o Impact: Longer instructions can handle more complex operations but may
reduce execution speed.
Control Flow:
o Instructions like JMP, CALL, and RET manage program flow.
o Addressing Modes: Supports direct (MOV AX, [1234H]), indirect (MOV AX,
[BX]), and immediate (MOV AX, 5).
ARM:
o Opcode: LDR (load data to a register).
Arithmetic (ADD):
o Purpose: Performs addition or subtraction.
Logic (AND):
o Purpose: Performs bitwise operations (AND, OR, XOR, NOT).
Comparison (CMP):
o Purpose: Compares two values and sets flags (e.g., Zero Flag, Sign Flag).
Control (JMP/JE):
o Purpose: Alters the flow of execution.
Direct Addressing:
o The instruction specifies the memory address where the operand is located.
o Example: MOV AX, [1234H] (Load data from memory address 1234H into
AX).
Indirect Addressing:
o The address of the operand is stored in a register.
o Example: MOV AX, [BX] (Load data from the memory address pointed to by
BX).
Register Addressing:
o The operand is in a register.
Indexed Addressing:
o Combines a base address with an offset.
o Example: MOV AX, [BP+4] (Load data from an address offset 4 bytes from
BP).
Program Output
The program:
1. Adds 5 and 3 using immediate addressing.
2. Adds num1 (10) and num2 (20) using direct addressing.
3. Repeats the addition using indirect addressing.
4. Stores the results in result and temp.
1 Task 3.1: Factorial Program
Problem Statement
Write an assembly program to compute the factorial of a given number (e.g., n = 5) using
simple arithmetic instructions.
Step-by-Step Explanation
i. Initialize Data:
o num: The number for which the factorial is to be calculated (e.g., 5).
o result: A variable to store the result.
ii. Load the Number:
o mov cl, [num]: Load the value of num into the CL register.
o mov ax, 1: Initialize AX to 1, as the factorial computation starts with 1.
iii. Factorial Loop:
o Multiply: mul cl multiplies the current value of AX with CL.
o Decrement: dec cl decrements CL by 1.
o Check Condition: jnz factorial_loop jumps back to the loop if CL is not zero.
iv. Store Result:
o mov [result], ax saves the factorial result in memory.
v. End Program:
o mov ah, 0x4C and int 0x21 terminate the program.
Flowchart
Initialize AX = 1, CL = num
Multiply AX = AX * CL
Decrement CL
Is CL == 0?
Yes No
End
Task 3.2: Logic Operations
Problem Statement
Create an assembly program to demonstrate AND, OR, XOR, and NOT operations.
1. Step-by-Step Explanation
Operands:
o operand1: Binary value 01011010.
o operand2: Binary value 10100101.
AND Operation:
o and al, [operand2]: Performs bitwise AND of operand1 and operand2.
OR Operation:
o or al, [operand2]: Performs bitwise OR of operand1 and operand2.
XOR Operation:
o xor al, [operand2]: Performs bitwise XOR of operand1 and operand2.
NOT Operation:
o not al: Inverts all bits of operand1
Load operand1
Perform AND
Perform OR
Perform XOR
Perform NOT
Store Results
End
Task 4.1: Sum of Integers from 1 to N
Loops are essential in assembly programming for performing repetitive tasks. This section
demonstrates programs for summing integers and generating multiplication tables using
loops.
Problem Statement
Write an assembly program to calculate the sum of integers from 1 to N (e.g., N = 10) using a
loop.
Explanation
Initialize Registers:
o CX acts as the counter, initialized to N.
o AX serves as the accumulator to store the running sum.
Loop Structure:
o Add: add ax, cx adds the current counter value to the accumulator.
o Decrement: dec cx reduces the counter by 1.
o Jump: jnz sum_loop repeats the loop until CX = 0.
Store Result:
o The final value in AX is stored in sum.
Significance
Efficiency: Optimized instructions for bulk transfers reduce execution time.
Flexibility: Multiple addressing modes enhance usability.
Performance: Efficient data movement minimizes CPU overhead.
Task 5.2: Assembly Program for Block Data Transfer
Problem Statement
Write an assembly program to transfer a block of data from one memory location (source) to
another (destination).