Question

In: Advanced Math

Develop an assembly language program for 89c51 to do following {Marks 10} Store any 8 values...

  1. Develop an assembly language program for 89c51 to do following {Marks 10}
  1. Store any 8 values of one byte each anywhere in Scratch Pad area of RAM. You are bound to use loop to store values.
  2. Find Mean of these 8 values (use shift operator for division) and send it to port P2 (formula for to find mean is given below)
  3. Find the lowest number among the numbers saved in part (1), take its 2’s complement and send it to P3

Formula for mean

μ=i=1nXin

Where X is values, and n is total number of values

  1. Develop an assembly language program for 89c51 to do following
  1. Store any 8 values of one byte each anywhere in Scratch Pad area of RAM. You are bound to use loop to store values.
  2. Find Mean of these 8 values (use shift operator for division) and send it to port P2 (formula for to find mean is given below)
  3. Find the lowest number among the numbers saved in part (1), take its 2’s complement and send it to P3

Formula for mean

μ=i=1nXin

Where X is values, and n is total number of values

Solutions

Expert Solution

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


Related Solutions

Write a program to sort the following using HeapSort. Use any language you want. A=[10, 8,...
Write a program to sort the following using HeapSort. Use any language you want. A=[10, 8, 7, 9,16, 14, 3, 2, 4, 1]
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
Develop an x86 assembly language program that properly executes an "x to the y power" function:...
Develop an x86 assembly language program that properly executes an "x to the y power" function: int power(int x, int y) Compute the integer value that is x to the y power Do not concern yourself with the possibility of overflow You may only use only a loop structure to compute the value Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
Develop an x86 assembly language program that properly executes an "is even" function: bool isEven(int value)...
Develop an x86 assembly language program that properly executes an "is even" function: bool isEven(int value) If the value passed in is even, return 1 If the value passed in is odd, return 0 Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to their initial states prior to exiting Allow an end user to test this function in the following manner: Prompt...
Thinking in Assembly language What values will be written to the array when the following code...
Thinking in Assembly language What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE ExitProcess,0 main ENDP proc_1 PROC call proc_2 add esi,4 add eax,10 mov array[esi],eax ret proc_1 ENDP proc_2 PROC call proc_3 add esi,4 add eax,10 mov array[esi],eax ret proc_2 ENDP proc_3 PROC mov array[esi],eax ret proc_3 ENDP
Using MIPS assembly language In this program, you should define an array of 10 elements in...
Using MIPS assembly language In this program, you should define an array of 10 elements in your data segment with these values: ? = {11, 12,−10, 13, 9, 12, 14, 15,−20, 0} a. Write a function which finds the maximum value of this array. b. Write another function which calculates the summation of this array. c. Call these functions in your main program, and print the outputs of these functions to the user i. “The maximum is 15” ii. “The...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT