✅ 1.
Factorial Program (already written example)
MVI B, 05H ; Load the number (5) whose factorial is to be calculated into
register B
MVI A, 01H ; Load 1 into accumulator A (factorial starts with 1)
FACTORIAL: MUL B
DCR B ; Decrement B by 1
JNZ FACTORIAL ; Repeat loop until B = 0
STA 2025H ; Store result at memory address 2025H
HLT ; Stop program
✅ 2. Prime Number Check
MOV B, 05H ; Number to check if it is prime (example: 5)
MVI C, 02H ; Initialize divisor with 2
MVI D, 00H ; D = Flag register to check division result
LOOP: MOV A, B
CMP C ; Compare number with divisor
JZ PRIME ; If equal, it's a prime (no division found)
MOV A, B
MOV D, A ; Copy number into D
MOV A, C ; Load divisor in A
CALL MODULO ; Check if divisible (you'll create a manual routine)
MOV A, D
CPI 00H ; If remainder is 0, number is divisible → not prime
JZ NOT_PRIME
INR C ; Increase divisor
JMP LOOP ; Repeat
PRIME: HLT ; Stop if prime
NOT_PRIME: HLT ; Stop if not prime
✳️ Note: CALL MODULO means create a subroutine to perform division and
get remainder.
✅ 3. Addition of Two Numbers
MOV B, 05H ; Load first number into B
MOV C, 03H ; Load second number into C
MOV A, B ; Move first number to accumulator
ADD C ; Add contents of C to A
STA 2050H ; Store result at memory location 2050H
HLT ; Stop program
✅ 4. Subtraction of Two Numbers
MOV B, 06H ; Load first number into B
MOV C, 02H ; Load second number into C
MOV A, B ; Move first number into accumulator
SUB C ; Subtract C from A
STA 2051H ; Store result at 2051H
HLT ; Stop execution
✅ 5. Multiplication of Two Numbers (Using Addition Method)
MOV B, 04H ; Load multiplier into B
MOV D, 03H ; Load multiplicand into D
MOV E, B ; Copy B into E for loop counter
MVI A, 00H ; Clear accumulator A to store result
MULTIPLY: ADD D ; Add D (multiplicand) to accumulator
DCR E ; Decrease counter
JNZ MULTIPLY ; Repeat until E becomes 0
STA 2052H ; Store the result in memory location 2052H
HLT ; End program
✅ 6. Fibonacci Series (First 5 Terms)
MVI D, 00H ; First term = 0
MVI E, 01H ; Second term = 1
MVI C, 05H ; Total number of terms (5)
LXI H, 2050H ; HL pair points to memory 2050H
; Store first two terms
MOV A, D
MOV M, A ; Store first term at 2050H
INX H ; Move to next memory
MOV A, E
MOV M, A ; Store second term at 2051H
INX H
MVI B, 03H ; Remaining 3 terms
NEXT: MOV A, D ; A = previous term
ADD E ; A = A + E (current term)
MOV D, E ; Shift E to D
MOV E, A ; E = new term
MOV M, A ; Store new term in memory
INX H ; Next memory location
DCR B
JNZ NEXT ; Repeat for next terms
HLT ; End program