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

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
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 ? ? ? ?
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).
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
Write a RIMS-compatible C-language for-loop that counts the number of times a bit of A is...
Write a RIMS-compatible C-language for-loop that counts the number of times a bit of A is followed by a bit of the opposite parity (01 or 10) and writes the value to B. For example 00100110 has 4 cases: 00100110, 00100110, 00100110, 00100110.
Convert the following statement into the 8-bit unsigned binary ASCII representation: Bob’s laptop receives the frame...
Convert the following statement into the 8-bit unsigned binary ASCII representation: Bob’s laptop receives the frame containing the ARP reply message. First, convert each character into it's ASCII equivalents. Then, convert to a Binary number. For example: Bob's -> 066 111 098 039 115 -> 01000010 01101111 01100010 00100111 01110011 Remember, each Binary number has to be 8-bits.
For the following exercises, find the number of subsets in each given set. {a, b, c, … , z}
For the following exercises, find the number of subsets in each given set.{a, b, c, … , z}
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT