Skip to main content

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:

MEMORY LOATION MAHINE CODE LABEL MNEMONICS COMMENTS
4100 21,00,42

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

MOV B,M Transfer the memory content to B register
4104 C5

PUSH B Push the content of B register to stack pointer
4105 AF

XRA A Clear accumulator
4106 57

MOV D,A Clear D register
4107 5F

MOV E,A Clear E register
4108 23 LOOP1 INX H Increment memory pointer
4109 86

ADD M Add the content of memory location to accumulator
410A D2,0E,41

JNC LOOP2 Jump on no carry to LOOP2
410D 14

INR D Increment D register content
410E 05 LOOP2 DCR B Decrement B register content
410F C2,08,41

JNZ LOOP1 Jump on zero to LOOP1
4112 5F

MOV E,A Move the content of accumulator to E register
4113 C1

POP B Retrieve the content of B register from stack
4114 26,00

MVI H,00 Clear H register
4116 68

MOV L,B Move the [B] to L register
4118 7B LOOP4 MOV A, E Mover the[E] content to accumulator
4119 95

SUB L Subtract [L] content from accumulator
411A 5F

MOV E,A Move the accumulator content to E register
411B 7A

MOV A, D Move the[D] to accumulator
411C 9C

SBB H Subtract [H] from accumulator through borrow
411D DA,25,41

JC LOOP3 Jump on carry to LOOP3
4120 57

MOV D,A Move accumulator content to D register
4121 04

INR B Increment B register
4122 C3,18,41

JMP LOOP 4 Jump to LOOP4
4125 7B LOOP3 MOV A,E Move[E] to accumulator
4126 85

ADD L Add [L] with accumulator content
4217 5F

MOV E,A Move accumulator content to E register
4128 78

MOV A,B Move [B] register to accumulator
4129 32,00,43

STA 4300 Store the accumulator content in 4300
412C EB

XCHG
Exchange [DE]
With [HL]
412D 22,01,43

SHLD 4301 Store the remainder in 4301 and 4302
4130 76

HLT Ends execution





SAMPLE INPUT AND OUTPUT:
MEMORY LOCARION INPUT MEMORY LOCATION OUTPUT











RESULT:

Thus an 8085 assembly language program that finds average of N numbers was written and executed using microprocessor kit.


Questions and Answers

1. What is meant by looping and indexing? explain
2. Explain about following instructions.
i) LHLD ii) RAR iii) SPHL

3. What are the different addressing modes in 8085? explain in detail.
4. Differentiate between memory mapped I/O and peripheral I/O?


EXERCISE

1. Write an 8085 assembly language program to compute the HCF of two 16-bit numbers stored in word locations X and X+2. Store the result in word location X+4.

2. Write an 8085 assembly language program to compute the LCM of two 16-bit numbers stored in word locations X and X+2. Store the result in word location X+4 and X+6.

3. Write an 8085 assembly language program to compute the HCF of two 4-digit BCD numbers stored in word locations X and X+2. Store the result in word location X+4.

4. Write an 8085 assembly language program to compute the LCM of two 4-digit BCD numbers stored in word locations X and X+2. Store the result in word location X+4.




SQUARE ROOT OF A NUMBER
AIM:

To write an assembly language program to find the square root of a number and execute the program using 8085 microprocessor kit.

APPARATUS REQUIRED:

8085 microprocessor kit, power supply.

METHOD TO FIND SQUARE ROOT OF A NUMBER:

Suppose that X is the square root of number N. To find the square root, we derive the following equation

Let X2=N
Add X2 on both sides. Then
2 X2=N+ X2
X2=(N+ X2)/2
X=(N+ X2)/(2*X)
X=((N/X)+X)/2
Xnew= ((N/X)+X)/2

To find the square root of a given number we provide an initial guess X. With this value we calculate Xnew and compare it with X. If Xnew=X, it gives the result .If Xnew ≠ X then we take the Xnew as X and using the equation we find Xnew. This process is repeated until Xnew=X.


ALGORITHM:
Step1: load HL register pair with a memory pointer.
Step2: get the number into accumulator and E register.
Step3: increment memory pointer.
Step4: get the initial guess to D and B registers.
Step5: call the division program.
Step6: add the initial guess with the accumulator.
Step7: divide the content of accumulator by 2 using division program.
Step8: if the calculated value is equal to guess, store the result in the memory location.
Step9: else take calculated value as guess and go to step5.

PROGRAM:

MEMORY LOCATION MACHINE CODE LABEL MNIMONICS COMMENTS
4100 21,00,42

LXIH, 4200 Initialize HL register pair with memory pointer
4103 7E

MOV A, M Transfer the content of memory location to accumulator
4104 5E

MOV E, M Transfer the content of memory location to E register
4105 23

INX H Increment memory pointer
4106 56

MOV D, M Move the initial guess to D register
4107 46

MOV B,M Move the initial guess to to B register
4108 0E,00 LOOP3 MVI C,00 Clear C register
410A CD,1E,41

CALL DIV Call division program
410D 80

ADDB Add guess with accumulator
410E 06,02

MVI B,02 Move 02 to B register
4110 0E,00

MVI C,00 Clear C register
4112 CD,1E,41

CALL DIV Call division program
4115 7A

MOV A,D Move [D] to accumulator
4116 51

MOV D,C Move [C] to D register
4117 B9

CMP C Compare the guess with calculated value
4118 C2,28,41

JNZ LOOP1 Jump on no zero to loop1
411B 23

INX H Increment memory pointer
411C 71

MOV M,C Move [C] to memory location
411D 76

HLT Ends execution
411E 90 DIV SUB B Subtract [B] from accumulator
411F DA,26,41

JC LOOP2 Jump on carry to loop2
4122 0C

INR C Increment C register content
4123 C3,1E,41

JMP DIV Jump to division program
4126 79 LOOP2 MOV A,C Move [C] to accumulator
4127 C9

RET Return to main program
4128 7B LOOP1 MOV A,E Move[E] to accumulator
4129 41

MOV B,C Move [B] to C register
412A C3,08,41

JMP LOOP3 Jump to loop3








SAMPLE INPUT AND OUTPUT:

INPUT DATA [4200] OUTPUT DATA [4202]







RESULT:

Thus an 8085 assembly language program that finds the square root of a given number was written and executed using microprocessor kit.

Questions and answers:

1. Explain in detail about interrupt structure of 8085?
2. Write about the following instructions.
i) PUSH
ii) XTHL
iii) PCHL
3 What is the function of HOLD pin in 8085?
4. Differentiate between 8088 and 8086?

EXERCISES:

1. Write an 8085 assembly language program to convert a 32 bit binary number stored in locations X to X+3 to equivalent BCD number. Store the result in locations X+4 and X+7.

2. Write an 8085 assembly language program to convert a 8-digit BCD number stored in locations X to X+3 to equivalent binary number. Store the result in locations X+4 to X+7.

3. Write an 8085 assembly language program to sort a given set of 16-bit numbers in ascending order using Bubble sort algorithm. The number of elements to be sorted is provided in location X. The elements are in word locations starting from X+1.

4. Write an 8085 assembly language program to sort a given set of 16-bit numbers in descending order using Selection sort algorithm. The number of elements to be sorted is provided in location X. The elements are in word locations starting from X+1.


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. what should I do to get the power of a number (x ^ y) in 8085 assembly? I need help urgently! please! What will be the code that? thank you

    ReplyDelete
  3. I CAN'T EXECUTE THIS PROGRAM IN GNUSIM8085 SIMULATOR.

    ReplyDelete

Post a Comment

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

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