Page 272 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 272
PROBLEMS 249
14. Write a shortest C program int check(int base, int size, int range) to
n
write a checkerboard pattern in a vector of size s = 2 elements beginning at base,
and then check to see that it is still there after it is completely written. It returns 1 if the
vector is written and read back correctly; otherwise it returns 0. A checkerboard pattern is
k
k
k
range r = 2 elements of Os, followed by 2 element of $FF, followed by 2 elements
of Os, , . . for k < n, repeated throughout the vector. (This pattern is used to check
dynamic memories for pattern sensitivity errors.)
15. Write a class BitQueue that is fully equivalent to the class Cstack in §8.3, but
pushed, stores, and pulls 1-bit values, and all sizes are in bits rather than 16-bit words.
The bits are stored in 16-bit int vector allocated by the allocate ( ) procedure.
16. Write a class Shif tint that is fully equivalent to the class Cstack in §8.3, but
the constructor has an argument n, and function member j = obj . shift (i); shifts
an int value i into a shift register of n ints and shifts out an int value to j .
17. Write a class Shif tchar that is a derived class of the class Shif tint in Problem
18. where function member j = shift(i); shifts a char value i into a shift register
of n chars and shifts out a char value to j . ShiftChar uses Shiftlnt's
constructor.
18. Write a class Shif tBit that is fully equivalent to the class Shif tint in Problem
19, but shifts 1-bit values, and all sizes are in bits rather than 16-bit words. The bits are
stored in 16-bit int vector allocated by the allocate ( ) procedure.
19. Write a templated class Deque that is a derived class of templated class Cstack,
and that implements a deque that can be pushed into and pulled from either end. The
member functions pstop( ) push to top, pltop( ) pull from top, psbot() push to
bottom, and plbot( ) pull from bottom. Use inherited data and function members
wherever possible.
20. Write a templated class indexStack which is a derived class of templated class
Cstack (§8.7), that implements an indexable stack, in which the rth member from the
top can be read. The member functions push() pushes, pull() pulls, read(i) reads
the ith element from the top of the stack. Function member read( i) does not move
the stack pointer. Use inherited data and function members wherever possible.
21. Write a templated class indexDeque that is a derived class of templated class
Queue, that implements an indexable deque that can be pushed into and pulled from
either end, and in which the ith member from the top or bottom can be read. The
member functions pstop( ) push to top, pltop( ) pull from top, psbot() push to
bottom, plbot ( ) pull from bottom, rdtop(i) reads the ith element from the top,