Page 310 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 310
PROBLEMS 287
PROBLEMS
In all the following problems, assume lui, gsc, etc., are declared as they are used
throughout this chapter (see §9.1).
1. A global variable declared as long alpha; is loaded from global variables below.
Show assembly-language program segments to load alpha from:
a.unsigned int gui b.int gsi c.unsigned char guc d.char gsc
2 . A global variable declared as long alpha; is stored into global variables below.
Show assembly-language program segments to store alpha to each variable, and
indicate an assembly-language test that sets char error to 1 if an overflow occurs.
a.unsigned int gui b. int gsi c.unsigned char guc d. char gsc
3 . A global variable declared as unsigned long alpha; is stored into global
variables below. Show assembly-language program segments to store alpha to each
variable, and indicate a test on the value of alpha that will result in an error.
a. unsigned int gui b. int gsi c. unsigned char guc d. char gsc
4 . C local variables are not cleared. However, write a shortest program segment that
clears all N local variables of a subroutine, where N is a constant.
5 . Write a shortest program segment to execute each of the following C statements.
a. gui=lsi+lsc; b. lsi=gsi+lsc; C. Isc = luc + gsc; d. gui += Isi;
6 . Write a shortest program segment to execute each of the following C statements.
A
a. gui = Isi Isc; b. Isi /= gsi; c. Isc = ~ luc; d. lui /= gsi;
1 . Global variables are declared as long alpha, beta, v[ 10 ];. Write a shortest
program segment to execute each of the following C statements.
a. beta = v[alpha]; b. beta = v[++alpha]; c. beta = v[—alpha];
8. Global variables are declared as struct { unsigned int alpha:3, beta:?,
gamma: 6 } s; 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 = s.alpha; b. s. beta = i; c. s.alpha = s.gamma;