1.
Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
2. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
3. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
4. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
5. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
6. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
7. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
8. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
9. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
10. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
11. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
12. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
13. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
14. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
15. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
16. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
17. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
18. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
19. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
20. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
21. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
22. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
23. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
24. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
25. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
26. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
27. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
28. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
29. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
30. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
31. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
32. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
33. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
34. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
35. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
36. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
37. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
38. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
39. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
40. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
41. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
42. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
43. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
44. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
45. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
46. Add Two 8-bit Numbers
Problem: Add two numbers stored at memory locations 2050H and 2051H. Store the result at
2052H.
Solution:
LDA 2050H ; Load the first number into A
MOV B, A ; Move A to B
LDA 2051H ; Load the second number into A
ADD B ; Add B to A
STA 2052H ; Store the result at 2052H
HLT
47. Find the Sum of First N Natural Numbers
Problem: Let N be stored at 3000H. Find the sum of first N natural numbers and store result at
3001H and 3002H.
Solution:
LXI H, 3000H ; Load address of N
MOV C, M ; Get N in C
MVI D, 00H ; Clear D (upper byte of result)
MVI E, 00H ; Clear E (lower byte of result)
LOOP: MOV A, C
ADD E
MOV E, A
JC INCR_D ; If carry, increment D
JMP CONT
INCR_D: INR D
CONT: DCR C
JNZ LOOP
LXI H, 3001H
MOV M, E
INX H
MOV M, D
HLT
48. Reverse an Array
Problem: A 5-element array starts at 4000H. Reverse the array and store it starting at 5000H.
Solution:
LXI H, 4000H ; Source
LXI D, 5004H ; Destination starts from end
MVI B, 05H ; Counter
LOOP: MOV A, M ; Load source element
STAX D ; Store at destination
INX H ; Move to next source
DCX D ; Move to previous destination
DCR B
JNZ LOOP
HLT
49. Count Even Numbers in an Array
Problem: Array of 10 numbers starts at 4100H. Count the even numbers and store count at 4200H.
Solution:
LXI H, 4100H
MVI C, 0AH ; Counter = 10
MVI D, 00H ; D = count of even numbers
LOOP: MOV A, M
ANI 01H ; Mask LSB
JNZ SKIP ; If LSB = 1 -> odd, skip
INR D ; Else increment count
SKIP: INX H
DCR C
JNZ LOOP
LXI H, 4200H
MOV M, D
HLT
50. Multiply Two Numbers (by Repeated Addition)
Problem: Multiply two 8-bit numbers stored at 2000H and 2001H. Store the result at 2002H.
Solution:
LDA 2000H ; Multiplicand
MOV B, A
LDA 2001H ; Multiplier
MOV C, A
MVI A, 00H ; Clear accumulator (result)
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT