In: Advanced Math
Formula for mean
μ=i=1nXin
Where X is values, and n is total number of values
Formula for mean
μ=i=1nXin
Where X is values, and n is total number of values
Here the RAM of 89c51 is given as follows:
Therefore we can store the 8, 8-bit values in the scratch-pad
area 30H - 7FH.
Instructions in 89c51
MOV - It copies a value from one location to
another.
Syntax - MOV destination, source
ADD - This instruction adds a source operand with the content of
accumulator and store the result in accumulator
Syntax- ADD A, source operand
DIV - Divides the unsigned value of the Accumulator by the unsigned
value of the "B" register. The resulting quotient is placed in the
Accumulator and the remainder is placed in the "B" register.
Syntax - DIV AB
INC - It increments the register value by 1.
Syntax - INC register - This instruction incremets the address in
register
DJNZ - It is a conditional instruction which first decremet the
corresponding stored value and jump to the destination whether the
result is not zero.
Syntax - DJNZ register, destination
Here we need to move any 8 values. And they need to be moved to 30H
to 37H.
Let the 8 values stored in 12H to 19H and the destination is 30H to
37H.
And we have to do this 8 times so let use R7 as a counter
register.
ORG 00H // Start the program main:MOV R7, #08H // Store the counter
value in R7 MOV R0, #12H // Initialize R0 with the starting address
of the values MOV R1, #30H // Move the destination to R1 loop:MOV
A,@R0 // Move the value to be stored to accumulator MOV @R1,A //
Move the accumulator value to destination INC R0 // Increment the
R0 and to the next address where next value stored INC R1 //
Increment destination address DJNZ R7, loop // Decrement R7 and if
it is not 0 then go to loop. So 8 values will be stored in 30H to
37H END
•
The algorithm to find the mean is given by,
• Start
• Initialize a register with base address of memory location where the first value is stored
• Initialize counter register with number of values
• Enter the loop and add all the stored values
• Divide the sum stored by number of values and store the result
• Stop
ORG 00H // Start the program
main: MOV R0,#30H //Initializing base address location where values are stored
MOV R1,#08H // Number of values
MOV R2,#00H // Set the sum = 0 initially
MOV A,R1 // Storing number of values in accumulator MOV R3,A // Store the number of values in new register loop: MOV A,@ R0 // Coping value from memory location at which R0 is pointing
ADD A,R2 // Add the value in R0 with R2
MOV R2,A // Sum is stored in R2 register I
R0 // Increment R0 to the next location
DJNZ R1, loop // Repeat till 8 values are added
MOV B,R3 // Moving number of values to register B
MOV A,R2 // Moving Sum all values to register A
DIV AB // Finding mean
MOV R7,A // Storing the result in R7 register
MOV A, #00H MOV P2, A // Port 2 is initialized as output port
MOV A,R7 // Move result to Accumulator
MOV P2, A // Move the result to Port 2 END
•
Now Algorithm to find smallest number.
• Start
• Store the base adress of the values stored in scratch pad area to a register
• Initalize the counter register
• Move the value in the base adress to accumulator
• Increment register and store the incremented value in another register
• Compare value in accumulator and the value in the new register
• If the accumulator value is less than value stored in register the contents remains same
• If the accumulator value is greater than value stored in register, move the value in register to accumulator
• Repeat untill the counter register is 0.
• Stop
ORG 00H // Start
main: MOV R0, #30H // Move the base address to R0
MOV R7, #08H // Move the counter value to R7
MOV A, @R0 // Move the value at R0 to Accumulator
loop: INC R0 // Increment the base address
MOV R6, @R0 // Move the new value to R6
CJNE A,06H,Label1 // Compare A and R6 and if they are not equal goto label1
SJMP Lable2 // If A = R6 , then unconditional jump to Lable2
Label1: JC Lable2 // If A < R6 then goto lable 2
MOV A,R6 //If A> R6 then swap A with R6
Lable2: DJNZ R7, loop // Decrement the counter and repeat if it is not 0
CPL A // Find the 1's complement of the result
ADD A, #01H // Find the 2's complement
MOV R7,A // Storing the result in R7 register
MOV A, #00H
MOV P1, A // Port 1 is initialized as output port
MOV A,R7 // Move 2's complement to Accumulator
MOV P2, A // Move the result to Port 1.
end : SJMP end // End the program
I gave my best to help you.
Thank you so much sir