Page 311 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 311
288 Chapter 9 Implementation of C Procedures
9. Global variables are declared as struct { unsigned int alpha: 3, beta:?,
gamma: 6 } *p; int i;. A struct with bit fields is packed from leftmost bit for the
first field named on the left, through consecutive fields, toward the right. Write a shortest
program segment to execute each of the following C statements.
a. i = p->alpha; b. p->beti =- i; c.p->alpha = p->gamma;
10. Write a shortest program segment to execute each of the following C statements,
a. gui = (gui & Oxc7ff) + ((Isc « 11) & 0x3800);
b. lux = (lui & Oxffc?) \ ((gsc « 3) & 0x38);
c. lui = (lui & Oxc7c7) + ((gsc«3)&0x38) \ ((Isc«ll)&0x3800);
11. Write a shortest program segment to execute each of the following C statements,
a. guc = gui >= lac ; «
b. luc = lui < gsc ;
c. lui = (gui >= Isc) \ \ (lui < gsc) ;
12. Write a shortest program segment to execute each of the following C statements.
a. if{ gui >= Isc ) lui++;
A
b. if( ! ( gui Isc) ) lui *= 10;
A
c. if(( gui >= Isc )&&(! ( (gui Isc) & gsc) ) ) lui A = gui;
13. Write a shortest program segment to execute each of the following C statements.
a. if(( gui <= Isc )|j ( gui >=( Isc +7)) ) lui++;
b. if( ( gui > Isc) && ( gui < (Isc + 3) ) ) lui *= 10;
c. if(( gui >= 0 ) && ( Isi < 0 ) && ( gui > Isi ) ) lui "= gui;
14. Write the case statement below according to the conventions of Figure 9.9a.
switch(guc){case 2: gui = -1; break;case 4:Isc = -1;default:Isi = -1;}
15. Repeat Problem 14 according to the conventions of Figure 9.9b.-
16. Rewrite the assembly-language program of Figure 9.1 Ib for a main program, like
Figure 9.11 a, in which the declaration int sum; is replaced by int k;, and the
statement sum += a[i][j]; is replaced by if (k > a[i][j]) k = a[i][j];
17. Write the C program and the resulting assembly-language program that transposes
a two-dimensional matrix of size 4 by 4, following the approach of Figure 9.11.
18. Write the C program and the resulting assembly-language program that stays in a
do while loop as long as both bits 7 and 6 of the byte at location $dO are zero, following
the approach of Figure 9.13b.