Question

Define a union data struct WORD_T for a uint16_t integer so that a value can be...

Define a union data struct WORD_T for a uint16_t integer so that a value can be assigned to a WORD_T integer in three ways:
(1) To assign the value to each bit of the integer,
(2) To assign the value to each byte of the integer,
(3) To assign the value to the integer directly.

a) Show the code of defining the union data struct WORD_T.
b) Show the code to assign 17 to the WORD_T variable foo.
b.1) Assign 17 to the bits of foo.
b.2) Assign 17 to the bytes of foo.
b.3) Assign 17 to the integer of foo.

Homework Answers

Answer #1

A)

union WORD_T
{
uint16_t word;

struct
{
uint8_t byte0;
uint8_t byte1;
};

struct
{
uint8_t bit0:1;
uint8_t bit1:1;
uint8_t bit2:1;
uint8_t bit3:1;
uint8_t bit4:1;
uint8_t bit5:1;
uint8_t bit6:1;
uint8_t bit7:1;
uint8_t bit8:1;
uint8_t bit9:1;
uint8_t bit10:1;
uint8_t bit11:1;
uint8_t bit12:1;
uint8_t bit13:1;
uint8_t bit14:1;
uint8_t bit15:1;
};
};

B.1)

union WORD_T foo;

foo.bit0 = 1; // (1) Assign to individual bits
foo.bit1 = 0;
foo.bit2 = 0;
foo.bit3 = 0;
foo.bit4 = 1;

B.2)

foo.byte0 = 1; // (2) Assign to individual byte
foo.byte1 = 2;

B.3)

foo.word = 0x11; // (3) Assign to entire word


Know the answer?
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
Similar Questions
1. Suppose we have a 32KB direct-mapped data cache with 32-byte blocks. a) Show how a...
1. Suppose we have a 32KB direct-mapped data cache with 32-byte blocks. a) Show how a 32-bit memory address is divided into tag, index and offset. Show clearly how many bits are in each field. b) How many total bits are there in this cache? 2. Suppose we have a 8KB direct-mapped data cache with 64-byte blocks. a) Show how a 32-bit memory address is divided into tag, index and offset. Show clearly how many bits are in each field....
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval...
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval qword 11111111h thirdval qword 22222222h sum qword 0 .code main proc      mov rax,firstval                         add rax,secondval             add    rax,thirdval      mov    sum,rax      mov    ecx,0      invoke ExitProcess main endp end main b) Transmitted messages often include a parity bit, whose value is combined with a data byte to produce an even number of 1 bits. Suppose a message byte in the AL...
A 4-bit data is transmitted using a Hamming code to ensure that the receiver can detect...
A 4-bit data is transmitted using a Hamming code to ensure that the receiver can detect and correct single bit errors. Show the bit pattern transmitted for data 1010 (left to right: from the most significant bit to the least significant bit). Assume that even parity is used in the Hamming code. How many redundant bits are needed in the Hamming code? And what is the value of each Hamming code bit? In your answer, please indicate the data bit...
A set of parity-check equations for a distance-4 Hamming code with 64 data bits and 8...
A set of parity-check equations for a distance-4 Hamming code with 64 data bits and 8 parity-check bits are specified by the eight 72-bit constants below, each representing one row the parity-check matrix: C[1] = 72'h80000000000000007f; C[2] = 72'h400000003FFFFFFF80; C[3] = 72'h20001FFFC0007FFF80; C[4] = 72'h100FE03FC07F807F80; C[5] = 72'h0871E3C3C78787878F; C[6] = 72'h04B66CCCD9999999B3; C[7] = 72'h02DAB5556AAAAAAAD5; C[8] = 72'hFFFFFFFFFFFFFFFFFF; Assuming that bits are numbered D[17:0], bits D[71:64] are the check bits, D[63:0] are the data bits. Write a Verilog model for a...
- An ISP has a CIDR block 71.94.128.0/17 (01000111 01011110 10000000 00000000). The ISP wants to...
- An ISP has a CIDR block 71.94.128.0/17 (01000111 01011110 10000000 00000000). The ISP wants to sub-divide this into 4 smaller CIDR blocks (all of the same size) for its customers. a. How many bits should the ISP add to the mask to identify the subnets? b. What are the addresses of each smaller block in binary? (Show Work) - A large IPv4 packet with Identification = 123 and with a 20 byte header and 1000 bytes of payload data...
Rather than using an array of struct-type elements, set up a linked list of struct-type nodes,...
Rather than using an array of struct-type elements, set up a linked list of struct-type nodes, where each node has the following fields or use Class using struct-type: -a four-digit integer identification number -the annual income for the household -the number of household members -a pointer field, linking this node to the next node The results of a survey of the households in your township are available for public scrutiny. Each record (struct-type entity) contains data for one household as...
1. In the following C code, elements of each row are stored contiguously in memory. Assume...
1. In the following C code, elements of each row are stored contiguously in memory. Assume each element in an array is a 32-bit integer. p = 0; for (j=0; j<8; ++j) for(i=500; i>0; --i ) {     A[ i] = 2 * B[j]; ++p; } a. How many 32-bit integers can be stored in a 32-byte cache block? b. Which variable references exhibit temporal locality? c. Which variable references exhibit spatial locality?
1. (a) Draw a fully-labelled diagram of the constellation for QAM, using the symbols 0, 1,...
1. (a) Draw a fully-labelled diagram of the constellation for QAM, using the symbols 0, 1, 2, 3. (b) How many bits are required to uniquely label each symbol? (c) Label your constellation with a binary code that minimises the bit error rate, and explain why it minimizes the bit error rate. (d) Describe two ways that this system could be modified to increase the data rate
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize...
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize it with value 9.99 (2) Given two integer variables var2 and var3, write a statement that gives var3 a value that is 4 more than the value of var2. (3) Define a double variable var4, initialize it with value 1234.56. Write a statement to change var4 so it will just hold one third (1/3) of the original value (4) Given four double variables var5,...
1) The decimal equivalent of the unsigned 8-bit hex number 0B4H is ______________. 2) The value...
1) The decimal equivalent of the unsigned 8-bit hex number 0B4H is ______________. 2) The value of the expression ‘H’ – ‘B’ is less than / equal to / greater than that of the expression ‘L’ – ‘C’. If the .data segment contains declarations. A BYTE 2 DUP (‘a’), ‘+’ B BYTE 3 DUP (‘b’), 0 C BYTE 4 DUP (‘c’), ‘–’ D BYTE 5 DUP (‘d’), 0 then the instruction input A, D, 6 will display a Windows dialog...