Skip to main content

Block Transfer and Sorting

3. a) SMALLEST OR LARGEST NUMBER IN AN ARRAY

Aim:
            To write an 8085 assembly language program that finds the smallest (or largest number in an array and execute the program using microprocessor kit.

Apparatus required: 8085 Microprocessor kit, Power supply

Algorithm:

Smallest number in an  array

Step 1:             Initialize HL register pair with a memory pointer.
Step 2:             Get the count to B register and decrement the count.
Step 3:             Increment the memory pointer
Step 4:             Move contents of memory pointer to accumulator.
Step 5:             Increment memory pointer and compare the contents with accumulator.
Step 6:             If carry won't  result  move the contents of memory pointer to
                         Accumulator
Step7:              Decrement the count
Step 8:             If count becomes zero increment the memory pointer and store contents of
                        accumulator to that memory location.

Memory Location
Machine code
Label
Mnemonics
Comment
4100 
21,00,42 

LXI  H, 4200
Initialize HL register pair with a memory pointer
4103
46

MOV   B, M
Transfer the count to B register
4104
05

DCR   B
Decrement B register
4105
23

INX   H     
Increment memory pointer
4106
7E

MOV  A, M
Get first number to accumulator
4107
23
 LOOP2
INX   H     
Increment memory pointer
4108
BE

CMP  M
Compare the contents of memory location with accumulator
4109
DA,  0D,  41

JC      LOOP1
If [A]<[M] go to  LOOP1
410C
7E

MOV A,  M
Move  [M] to accumulator
410D
05
LOOP1
DCR  B
Decrement the count
410E
C2, 07, 41

JNZ   LOOP2
If [B] is not equal to zero go to LOOP 2
4111
23

INX   H     
Increment memory pointer
4112
77

MOV  M,  A
Move the smallest number to memory location
4113
76

HLT
End  execution


Sample input and output:
Dataset   1
                           Memory location
                      Data






 


 Dataset 2
                           Memory location
                      Data






 

           
Largest number in an  array

Step 1:             Initialize HL register pair with a memory pointer.
Step 2:             Get the count to B register and decrement the count.
Step 3:             Increment the memory pointer
Step 4:             Move contents of memory pointer to accumulator.
Step 5:             Increment memory pointer and compare contents with accumulator.
Step 6:             If carry results  move the contents of memory pointer to
                         Accumulator
Step7:              Decrement the count
Step 8:             If count becomes zero increment the memory pointer and store contents of
                        accumulator to that memory location


Memory Location
Machine code
Label
Mnemonics
Comment
4100 
21,00,42 

LXI  H, 4200
Initialize HL register pair with a memory pointer
4103
46

MOV   B, M
Transfer the count to B register
4104
05

DCR   B
Decrement B register
4105
23

INX   H     
Increment memory pointer
4106
7E

MOV  A, M
Get first number to accumulator
4107
23

INX   H     
Increment memory pointer
4108
BE

CMP  M
Compare the contents of memory location with accumulator
4109
DA,  0D,  41

JNC   LOOP1
If [A]>[M] go to  LOOP1
410C
7E

MOV A,  M
Move  [M] to accumulator
410D
05
LOOP1
DCR  B
Decrement the count
410E
C2, 07, 41

JNZ      LOOP2
If [B] is not equal to zero  go to LOOP 2
4111
23

INX   H     
Increment memory pointer
4112
77

MOV  M,  A
Move the smallest number to memory location
4113
76

HLT
End  execution

Sample input and output

Memory Location
                             Data












Result: Thus an  8085 assembly language program that finds the smallest (or largest number in an array was written and executed using microprocessor kit.

-------------------------------------------------------------------------------------------------------------------------------

                                    b) SORTING OF NUMBERS IN AN ARRAY
AIM:
            To write an 8085 assembly language program that sorts the given array in ascending order (or descending order) and execute the program using microprocessor kit.

Apparatus required: 8085 Microprocessor kit, Power supply

Algorithm

Ascending order

Step 1:             Initialize HL register pair as memory pointer.
Step 2:             Get the count and decrement it.
Step 3:             Increment memory pointer
Step 4:             Push the memory location and the count to stack pointer.
Step 5:             Call subroutine.
Step 6:             Get the count and memory location from stack pointer.
Step 7:             Move the contents of accumulator to memory location
Step 8:             Decrement the count, if it is not zero go to step 3.
Step 9:            Else end  the execution

 subroutine:

Step 1:             Move the contents of memory location to accumulator.
Step 2:             Increment memory pointer and compare it with the contents of accumulator.
Step 3:             If carry does not exist swap the contents of accumulator and memory pointer.
Step 4:             Decrement the count, if count is not zero go to step 2.
Step 5:             Else return to main program.


Memory Location
Machine code
Label
Mnemonics
Comment
4100
21,00,42

LXI  H, 4200
Initialize HL register pair with a memory pointer
4103
46

MOV   B, M
Transfer the count to B register
4104
05

DCR   B
Decrement B register
4105
23
LOOP1
INX   H     
Increment memory pointer
4106
E5

PUSH   H
Push the contents of HL register pair to stack pointer
4107
C5

PUSH   B
Push the contents of B register to stack pointer
4108
CD, 13, 41

CALL    Sub
Call subroutine to find the smallest number
410B
C1

POP  B
Retrieve the contents of B from stack
410C
E1

POP    H
 Retrieve the contents of HL register pair  from stack
410D
77

MOV  M,  A
Move the smallest number to memory location
410E
05

DCR   B
Decrement register B
411F
C2, 05, 41

JNZ  LOOP 1  
If [B] is not equal to zero  go to LOOP 1
4112
76

HLT
End  execution

  
SUBROUTINE
Memory Location
Machine code
Label
Mnemonics
Comment
4113
7E

MOV  A,  M
Transfer the contents of memory location to accumulator
4114
23
LOOP  2
INX   H
Increment memory pointer
4115
BE

CMP  M
Compare the contents of memory location with accumulator
4116
D2,  1C,  41

JC    LOOP1
If [A]<[M] go to  LOOP1
4119
56

MOV D,  M
Move  [M] to D register
411A
77

MOV M,  A
Move the contents of accumulator  to memory location
411B
7A

MOV A,  D
Move the [D] to accumulator
411C
05
 LOOP1
DCR    B
Decrement count
411D
C2, 14, 41

JNZ  LOOP2
If [B is not equal to zero go to LOOP 2
4120
C9

RET
Return to main program


Sample input and output

Memory Location
                             Data











 Descending order:

Step 1:             Initialize HL register pair as memory pointer.
Step 2:             Get the count and decrement it.
Step 3:             Increment memory pointer
Step 4:             Push the memory location and the count to stack pointer.
Step 5:             Call subroutine.
Step 6:             Get the count and memory location from stack pointer.
Step 7:             Move the contents of accumulator to memory location
Step 8:             Decrement the count, if it is not zero go to step 3.
Step 9:             Else end  the execution

 Subroutine:

Step 1:             Move the contents of memory location to accumulator.
Step 2:             Increment memory pointer and compare it with the contents of accumulator.
Step 3:             If carry  exists swap the contents of accumulator and memory pointer.
Step 4:             Decrement the count, if count is not zero go to step 2.
Step 5:             Else return to main program

  
Memory Location
Machine code
Label
Mnemonics
Comment
4100
21,00,42

LXI  H, 4200
Initialize HL register pair with a memory pointer
4103
46

MOV   B, M
Transfer the count to B register
4104
05

DCR   B
Decrement B register
4105
23
LOOP1
INX   H     
Increment memory pointer
4106
E5

PUSH   H
Push the contents of HL register pair to stack pointer
4107
C5

PUSH   B
Push the contents of B register to stack pointer
4108
CD, 13, 41

CALL    Sub
Call subroutine to find the smallest number
410B
C1

POP  B
Retrieve the contents of B from stack
410C
E1

POP    H
 Retrieve the contents of HL register pair  from stack
410D
77

MOV  M,  A
Move the smallest number to memory location
410E
05

DCR   B
Decrement register B
411F
C2, 05, 41

JNZ  LOOP 1  
If [B] is not equal to zero  go to LOOP 1
4112
76

HLT
End  execution


SUBROUTINE
Memory Location
Machine code
Label
Mnemonics
Comment
4113
7E

MOV  A,  M
Transfer the contents of memory location to accumulator
4114
23
LOOP  2
INX   H
Increment memory pointer
4115
BE

CMP  M
Compare the contents of memory location with accumulator
4116
D2,  1C,  41

JNC    LOOP1
If [A]>[M] go to  LOOP1
4119
56

MOV D,  M
Move  [M] to D register
411A
77

MOV M,  A
Move the contents of accumulator  to memory location
411B
7A

MOV A,  D
Move the [D] to accumulator
411C
05
 LOOP1
DCR    B
Decrement count
411D
C2, 14, 41

JNZ  LOOP2
If [B is not equal to zero go to LOOP 2
4120
C9

RET
Return to main program

 Sample input and output

Memory Location
                             Data










            

Result:
            Thus  an 8085 assembly language program that sorts the given array in ascending order (or descending order) was written and executed using microprocessor kit.

----------------------------------------------------------------------------------------------------------------                                               

c). BLOCK TRANSFER 

Aim:
            To Write an assembly language that transfer a block of data from one set of memory locations to other set of locations and test the program using 8085 microprocessor kit.

Apparatus required: 8085 Microprocessor kit, Power supply

Algorithm:

Step 1:             Initialize the count value.
Step 2:             Initialize the source memory pointer.
Step 3:             Initialize the destination memory pointer.
Step 4:             Move the contents of source memory to accumulator.
Step 5:             Store the accumulator contents to destination memory location.
Step 6:             Increment the source and the destination memory pointers.
Step 7:             Decrement the count, if count is not zero, go to step 4.
Step 8:             Else stop.


Memory Location
Machine code
Label
Mnemonics
Comment
4100
06 , 05

MVI B, 05
Initialize a count
4102
21,  00, 42

LXI  H, 4200
Initialize HL register pair as source memory pointer
4105
11,  00, 43

LXI  D, 4300
Initialize DE register pair as Destination memory pointer
4108
7E
LOOP
MOV A,  M
Move the contents from source location to accumulator
4109
12

STAX  D  
Store the contents of accumulator to destination location
410A
23

INX   H
Increment memory pointer
410B
13

INX  D
Increment DE register pair
410C
05

DCR    B
Decrement the count
410D
C2, 08, 41

JNZ   LOOP
Increment memory pointer
4110
76

HLT
End execution

 
Input
Output
Source location
Data
Destination location
Data
4200

4300

4201

4301

4203

4302

4204

4303

4205

4304




Result:
            Thus an assembly language that transfer a block of data from one set of memory locations to other set of locations was written and tested using 8085 microprocessor kit.

Questions  and Answers:
1.                  Define: Instruction cycle, Machine cycle, T-state
2.                  What are 8085 interrupts? Discuss in detail.

3.                  With suitable examples explain in detail about the following instructions
a.       STAX   D
b.      LDAX  B
c.       SPHL
d.      PUSH B
    4. What is stack pointer?
    5. Explain the steps in execution in CALL instruction.
  

EXERCISE
1.      A block of data is stored in the memory locations from XX55H to XX5AH. Transfer the data to locations XX80H to XX85 H in the reverse order
2.      Data bytes are stored in memory locations from XX50 H to XX5FH. To insert an additional five data bytes, it is necessary to shift the data string by five memory locations. Write a program to store the data string from XX55H to XX64H. 
3.      Write a program to find the mode and median of a set of 10 numbers stored from location XX60.



Comments

Popular posts from this blog

Installing and Activating KEIL uVision

*** NOTE: Click on the images to view them in full resolution Download: Download Keil from the link below: Keil Latest Version Free download with keygen After Installation: 1. File -> License Management 2. Open Keygen from the folder where rar file is unpacked 3. Copy computer ID ( CID ) to clipboard 4. Paste CID in KEYGEN exe, Press generate, copy generated serial and paste in new license textbox of Licence management. *** NOTE: Click on the images to view them in full resolution

Average and Square Root Using 8085

AVERAGE OF N NUMBERS AIM:       To write an assembly language program that finds the average of N numbers and executes the program using 8085 microprocessor kit. APPARATUS REQUIRED: 8085 microprocessor kit, power supply. ALGORITHM: STEP 1: Load HL register pair with a memory pointer. STEP 2: Get the count to B register and clear accumulator. STEP 3: Push the count to stack pointer. STEP 4: Increment memory pointer. STEP 5: Add the content of memory location to accumulator. STEP 6: If carry results increment D register. STEP 7: Decrement count. If it is not zero go to STEP 4. STEP 8: Else move the sum to E register. STEP 9: Get the count from stack pointer. STEP10: Subtract the count from sum(content of DE pair). STEP11:If the subtraction results a carry add the count to the result and get the remainder STEP12: Otherwise increment B register content and go to STEP10. STEP 13: Store the quotient and remainder in successive memory location. PROGRAM:

Laws of Thermocouple

The Seebeck Effect A German physician turned physicist named Thomas Johann Seebeck took two different metals, with one at a higher temperature than the other, and made a series circuit by joining them together to form a junction. He found that by doing so he was able to generate an electromotive force (emf). Emfs are voltages. Seebeck found that the larger the temperature differences between the metals, the higher the generated voltage, regardless of their shapes. His discovery is called the Seebeck effect, and it is the basis of all thermocouples. Background Seebeck, H.G. Magnus, and A.C. Becquerel proposed the empirical rules of thermoelectric circuits. Lord Kelvin explained their thermodynamic basis, and W.F. Roesser compiled them into a set of three fundamental laws. They have all been verified experimentally. The second law is sometimes broken up into three parts by modern day researchers, to give a total number of five, but Roesser's are still the standar