Question

In: Computer Science

2. Given variables A, B and C; each holding an 8-bit unsigned number. Write an AVR...

2. Given variables A, B and C; each holding an 8-bit unsigned number. Write an AVR assembly program to find the average of A to C, placing the result into variable F.

-embedded system-

Solutions

Expert Solution

Write an AVR assembly language code to find the average of A to C variables, placing the result into variable F:

Provided variables A, B and C are holding an 8-bit unsigned number.

Assembly code:

.DSEG

A: .BYTE 1

B: .BYTE 1

C: .BYTE 1

F: .BYTE 1

.CSEG

Average:

lds r18, A

lds r19, B

lds r20, C

add r18, r19

lsr r18

add r19, r20

lsr r19

add r18, r19

lsr r18

sts F, r18

rjmp Average

Description:

.DSEG ; Data segment or Data space

A: .BYTE 1 ; Variable A

B: .BYTE 1 ; Variable B

C: .BYTE 1 ; Variable C

F: .BYTE 1 ; Result Variable F

.CSEG ; Code segment or Code space

Average: ; Procedure Average

lds r18, A ; Loads a single byte from the labeled data space A to r18 register.

lds r19, B ; Loads a single byte from the labeled data space B to r19 register.

lds r20, C ; Loads a single byte from the labeled data space C to r20 register.

add r18, r19 ; Addition of two register. r18 = r18 + r19

lsr r18 ; Logically shift right that divides by two.

add r19, r20 ; Addition of two register. r19 = r19 + r20

lsr r19 ; Logically shift right that divides by two.

add r18, r19  ; Addition of two register. r18 = r18 + r19

lsr r18   ; Logically shift right that divides by two.

sts F, r18 ; Stores a single byte from the r18 Register to the labeled data space F.

rjmp Average ; Relative jump to Average


Related Solutions

Write a program in C that takes as input an 8-bit binary number and prints the...
Write a program in C that takes as input an 8-bit binary number and prints the next 10 binary numbers. Define a binary number as int binNum[8]; Use binNum[0] to store the most significant (i.e., leftmost) bit and binNum[7] to store the least significant bit. Ask the user to input the first binary number with each bit separated by at least one space.
Let A be a three-bit unsigned number. Use a seven-bit adder (and NOT gates, as necessary)...
Let A be a three-bit unsigned number. Use a seven-bit adder (and NOT gates, as necessary) to design a circuit that calculates the following operations. Note that the output may be assumed as unsigned, unless it is possible for the operation to produce a negative answer, in which case, the output must be correct in 2’s complement: W = 3A + 1 X = 2A – 17 Y = 40A + 6 Z = 32 – 4A
Description of how buses are used within a microprocessor such as the 8-bit AVR used in...
Description of how buses are used within a microprocessor such as the 8-bit AVR used in the Arduino microcontroller A block diagram that shows the 8-bit AVR along with the data and address busses. Use a graphics package such as Fritzing or equivalent
Let A be a three-bit unsigned number. Configure a seven-bit adder to perform the following operations....
Let A be a three-bit unsigned number. Configure a seven-bit adder to perform the following operations. You may shift A, shift the output, and set specific inputs or outputs to 1 or 0, as needed. You may also use NOT gates to invert A, if needed. Make sure you label each bit of your output, and that your output uses enough bits. For examples of how to draw and label the figures, see P6. a. W = 3A + 2...
Interpret these signed 8-bit sequences with each type of signed/unsigned encoding. Remember the bits are arbitrary!...
Interpret these signed 8-bit sequences with each type of signed/unsigned encoding. Remember the bits are arbitrary! They can be interpreted in many different ways. C.1: Complete the following table using decimal (base-10) numbers. The first line is already completed for you bit sequence unsigned sign-magnitude 1s’ complement 2’s complement 00000101 +5 +5 +5 +5 11110001 ? ? ? ? 01010011 ? ? ? ? 10000000 ? ? ? ? 11111111 ? ? ? ?
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers...
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers as shown. 01110101 + 00111011 Add the following unsigned 8 bit binary numbers as shown. 01000100 + 10111011
Convert the following numbers to 8-bit binary and 8-bit hexadecimal: a) 20 b) 78 c) -25...
Convert the following numbers to 8-bit binary and 8-bit hexadecimal: a) 20 b) 78 c) -25 d) -96 Convert the following hexadecimal numbers to binary and decimal assuming two's compliment format: a) 0x56 b) 0x14 c) 0xF8 d) 0xCC MUST DO ALL PROBLEMS AND SHOW ALL WORK!!!!
Write -127 as 8 bit signed binary number both using 2'complement and sign/magnitude notation.
Write -127 as 8 bit signed binary number both using 2'complement and sign/magnitude notation.
Implement a 2 by 2 multiplier using structure VHDL. The circuit will have two 2-bit unsigned...
Implement a 2 by 2 multiplier using structure VHDL. The circuit will have two 2-bit unsigned inputs (A and B), a 4-bit unsigned product outputs (P). you must use some full adders and gates (AND, OR, NOT, XOR).
Implement a 2 by 2 multiplier using structure VHDL. The circuit will have two 2-bit unsigned...
Implement a 2 by 2 multiplier using structure VHDL. The circuit will have two 2-bit unsigned inputs (A and B), a 4-bit unsigned product outputs (P). Please use some full adders and gates (AND, OR, NOT, XOR).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT