Question

E 2.12 Write a program to compute the average of the square of all elements of...

E 2.12 Write a program to compute the average of the square of all elements of an array with 32 8-bit unsigned numbers. the array is stored at $1000-$101F. Store the results at $1020-$1021.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program is commented array elements is not entered, the addresses are mentioned

N: equ 32 ;array count

org $1000 ;starting address of the elements

array: dw -elements- from $1000 - $101F

sum: rmb 4 ;array sum

i: rmb 1 ;array index

org $1500 ;starting addr of program

ldaa #0

staa sum ;initiallize sum to 0

staa mul ;

staa i ; intialize loop counter zero

loop ldab i ;B

cmpb #N ;is i=N?

beq done ;if i=N then branch to label ‘done’

ldx #array ;use index register X as pointer to the array , X=$1000

abx ;X <-X+B = X+I, to compute the address of current element

ldd 0,x ;place array[i] in D

ldy 0,x ;D

emuls ; perform signed multiplication D*D

std mul ;

sty mul ;

ldd 0,x ; D <- mul , D is set to array[i]*array[i]

addd sum+2 ;D=D+sum

std sum+2

ldaa #0

adca sum+1 ;propagating carry to msb

staa sum+1

inc i ;moving to next element

inc I

bra loop

$1020 - $1021

ldd sum ;load the dividend into D

ldx N ;load the divisor into X

idivs ; perform signed division

stx $1020 ;storing the quotient

std $1021 ;storing the remainder

done swi

end

Add a comment
Know the answer?
Add Answer to:
E 2.12 Write a program to compute the average of the square of all elements of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • E2.15 In assembly code, write a program to count the number of elements in an array...

    E2.15 In assembly code, write a program to count the number of elements in an array that are smaller than 16. The array is stored at memory locations starting from $1010. The array has 30 8-bit unsigned elements. Store the count in the memory location $C001.

  • PROGRAMMING ASSIGNMENT: Write a fully-commented program for the HC12 board, including appropriate directives and labels for...

    PROGRAMMING ASSIGNMENT: Write a fully-commented program for the HC12 board, including appropriate directives and labels for memory operands and constants. The program should do the following: • The program should start execution at address $2000. • Use directives to create an array of N=20 unsigned 8-bit decimal values: 15,20,14,13,17,9,10,5,18,7,19,8,1,3,4,11,2,6,12,16 stored in contiguous memory at locations start at $1000. • Sort given numbers in a descending order. • Store sorted numbers at memory locations starting from $1000. *assembly programming language*

  • this program is in C. Write a program that computes the number of elements in an...

    this program is in C. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...

  • Using Atmel studio 7 -C language programming Write a program to find the median of an...

    Using Atmel studio 7 -C language programming Write a program to find the median of an array of 8-bit unsigned integers. When the array has an even number of elements, the median is defined as the average of the middle two elements. Otherwise, it is defined as the middle element of the array. You need to sort the array in order to find the median. SHOW THAT THE CODE IS WORKING PROPERLY IN ATMEL STUDIO 7

  • C- PROGRAMMING PROJECT #4 Design and Write a C program to calculate an average of an...

    C- PROGRAMMING PROJECT #4 Design and Write a C program to calculate an average of an array of numbers and produce the following output: 1. Your first and last name 2. Course Number 3. C Project Number 4. All the numbers in the array 5. The sum of all the numbers in the array 6. The count of all the numbers in the array 7. The average of all the numbers in the array Double-space after lines 3, 4, 5,...

  • Need to write a MIPS assembly program that finds the minimum and maximum and sum of...

    Need to write a MIPS assembly program that finds the minimum and maximum and sum of a stored array. It also finds the locations of the minimum and maximum. The interaction between the main program and the function is solely through the stack. The function stores $ra immediately after being called and restores $ra before returning to main. The main program reserves a static C like array (index starts from 0) of 10 elements and initializes it. The maximum should...

  • Write a program using the LOOP instruction to sum all the even numbers from 20H to...

    Write a program using the LOOP instruction to sum all the even numbers from 20H to 80H. Write a program using the ADC (or add with carry) instruction to add these two 48 bit numbers. Assume the first number is store at an address starting 400H and that the second number is stored at an address starting at address 500H. Store the results in memory starting at address 600H. (Note that each number consists of three 16 bit words). Show...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • Write a program to add the 32-bit numbers stored at data memory locations 0x200~0x203 and 0x204~0x207,...

    Write a program to add the 32-bit numbers stored at data memory locations 0x200~0x203 and 0x204~0x207, respectively, and store the sum at 0x208~0x20B.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT