LAB 11 REPORT

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

LAB 11 REPORT

NAME – UJJAWAL CHHAJER

ROLL No. - 210108076


Task 1: Let x and y be the last and second last non-zero digits from your Roll Number. For
example, if your Roll Number is 18101104, then x = 4 and y = 1. Execute a loop to store 10
numbers in the address range A to (A + 9). These 10 numbers are in an Arithmetic
Progression with the First Term as x and Common Difference as y. Execute a loop to copy
these 10 numbers from source address range A to (A + 9) to the destination address range B to
(B + 9). Execute a loop to copy these 10 numbers from source address range A to (A + 9) to
the destination address range C to (C + 9) in a reversed order.

Code:

1. LDA 1000
2. MOV B,A //x
3. LDA 1001 4.
MOV C,A //y
5.
6. //1st
7. MVI H,40 //store in 4000-4009 data (HL pair)
8. MVI L,00
9.
10. MVI D,0A //counter
11. MOV A,B
12.
13. LOOP1:
//loop to
store 10
numbers in
AP
14. MOV M,A
15. ADD C
16. INR L
17. DCR D
18. JNZ LOOP1
19.
20. //2nd
21. MVI H,50 //store in 5001-500A data (HL pair)
22. MVI L,01
23. MVI B,40 //read the 4000-4009 data (BC pair)
24. MVI C,00
25.
26. MVI D,0A //counter reset
27.
28. LOOP2:
29. LDAX B
30. MOV M,A
31. INR L
32. INR C
33. DCR D
34. JNZ LOOP2
35.
36. //3rd
37. MVI H,60 //store in 6000-6009 data (HL pair)
38. MVI L,00
39. MVI B,50 //read the 500A-5001 data (BC pair)
40. MVI C,0A
41.
42. LOOP3:
43. LDAX B
44. MOV M,A
45. INR L
46. DCR C
47. JNZ LOOP3
48.
49. HLT
50.
51. #ORG 1000
52. #DB 02,06
Logic: In this task, we generate an Arithmetic Progression (AP) using a loop. The process starts
by initializing a counter to 10 (decimal 10) and storing the address of the first number in the HL
pair. In each iteration of the loop, we add a common difference to the number, decrement the
counter by one, and increment the address stored in the HL pair by one. This process continues
until the counter reaches zero. Moving on to the second part, we store the source address from
where the numbers are being copied in the DE pair and the destination address where the
numbers are copied to in the HL pair. We load the number to be stored into the accumulator
using the LDAX command and then store it at the address stored in the HL pair using the MOV
M,A command. This operation repeats in a loop for 10 times, and with each iteration, both the
addresses stored in the DE and HL pairs are incremented by one. The third part follows a similar
approach to the second part. In this case, we store the address of the last number in the DE pair.
During each iteration, we increment the address stored in the DE pair, and the address stored in
the HL pair is also incremented by one.

Task 2: Manually store ten 8-bit numbers (not in ascending or descending order) in the
address range A to (A+ 9). Implement Bubble Sort to arrange these numbers in ascending
order.

Code:
1. //BUBBLE SORT
2. MVI D,0A //counter for LOOP1
3.
4. LOOP1:
5.
6. MVI H,40 //resetting to the initial memory address
7. MVI L,00
8.
9. MVI E,09 //counter for LOOP2
10.
11. LOOP2:
12.
13. MOV A,M //1st number for comparision
14. INR L
15. MOV B,M //2nd number for comparision
16.
17. CMP B 18.
JC NOSWAP
19.
20. MOV M,A //swapping
21. DCR L
22. MOV M,B
23. INR L
24.
25. NOSWAP:
26.
27. DCR E 28. JNZ LOOP2
//closing LOOP2
29.
30. DCR D 31. JNZ LOOP1
//closing LOOP1
32.
33. HLT
34.
35. #ORG 4000
36. #DB FF,23,45,11,01,04,08,05,04,22
Logic: In this task, we begin by storing numbers in memory using the ORG command. To sort
these numbers, we employ a comparison and swapping process. We compare adjacent numbers
using the CMP command, and if they are found to be out of order, we perform a swap. This
operation is repeated nine times for pairs of numbers (A1A2, A2A3, and so on, up to A9A10).
During this loop, we maintain a flag in register D. If a swap occurs during an iteration, we set the
flag to 01 (0000 0001). After completing the iteration, if the flag is 01, indicating one or more
swaps were made, we repeat the iteration by calling the LOOP again. However, if the flag
remains at 00, it signifies that no swaps occurred, meaning all the numbers are now in ascending
order, and the program terminates
Task 3: The 8-bit number x8 is stored in address A. Multiply its upper and lower nibble. Store
the result in address B.

Code:

1. LDA 2000
2.
3. ANI F0
4. RRC
5. RRC
6. RRC
7. RRC
8. MOV B,A //upper nibble
9.
10. LDA 2000
11.
12. ANI 0F
13. MOV C,A //lower nibble
14.
15. MVI A,00
16.
17. LOOP: //multiplication
18. ADD C
19. DCR B 20. JNZ LOOP
21.
22. STA 4000
23.
24. HLT
25.
26. #ORG 2000
27. #DB 35

Logic: In this task, we start by fetching a number from memory located at address 2000. Next,
we perform nibble-level operations. The lower nibble is isolated by using a bitwise AND
operation with 0F (0000 1111), and the upper nibble is extracted by performing a bitwise AND
operation with F0 (1111 0000), followed by a 4-bit right rotation. After these nibble extractions,
we proceed with multiplication through repeated additions. The result of this multiplication is
then stored in memory at the address 4000.

Task 4: The 8-bit number x8 and the 4-bit number y4 are stored in addresses X and Y
respectively. Multiply x8 and y4 and store the result in address A

Code:
1. LHLD 1000 //8bit data
2. MOV D,H
3. MOV E,L
4.
5. LDA 1002 //4bit data
6. DCR A
7.
8. LOOP: DAD D
9. DCR A 10. JNZ LOOP
11.
12. SHLD 2000
13. HLT
14.
15. #ORG 1000
16. #DB 77,00,06
Logic: In this task, we initially place the number "x8" into register E, and the number "y4" into
register B. We leverage the DAD D command, which allows us to add a 16-bit number stored in
the DE register pair to the HL pair. By invoking this command repetitively, we effectively add
"x8" to the HL pair a total of "y4" times. The resulting sum is then stored in memory locations
2000 and 2001 using the SHLD command.

You might also like