In: Electrical Engineering
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory using the algorithm below. Hand trace (execute) the program showing the changes made to all affected registers and memory locations.
Max = a(1)
For i = n to N
If max < a(i) then max = a(i)
Next i
ALGORITHM:
1) Load the address of the first element of the array in HL pair
2) Move the count to B – reg.
3) Increment the pointer
4) Get the first data in A – reg.
5) Decrement the count.
6) Increment the pointer
7) Compare the content of memory addressed by HL pair with that of A - reg.
8) If Carry = 0, go to step 10 or if Carry = 1 go to step 9
9) Move the content of memory addressed by HL to A – reg.
10) Decrement the count
11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12) Store the largest data in memory.
13) Terminate the program.
PROGRAM
PROGRAM |
Description |
LXI H,4200 |
Set pointer for array |
MOV B,M |
Load the Count |
INX H |
Set 1st element as largest data |
MOV A,M |
Copy data from register M to accumulator |
DCR B |
Decrements the count |
LOOP: INX H |
Increment of HL pair by 1 |
CMP M |
f A- reg > M go to AHEAD |
JNC AHEAD |
Jump to AHEAD if carry is not = 1 |
MOVA,M |
the new Set value as largest |
AHEAD: DCR B |
Decrement B |
JNZ LOOP |
Repeat comparisons till count = 0 |
STA 4300 |
Repeat comparisons till count = 0 |
HLT |
Stop program |