Section 9.7
Review Questions
A pointer example
-
Which of the following C declarations creates a pointer?
int *m;
int n;
answer...
int *m;
-
What is the meaning of the asterisk in the following C code?
z = *m;
answer...
use m's value as a memory address for load;
don't use m's value directly as data
-
What are pointers, really?
a. memory addresses
b. pieces of data
c. complete arrays
d. special machine instructions?
answer...
a. memory addresses
-
Why is there not much difference in machine language between arrays and
pointers?
answer...
because they all use indirect addressing
-
In C, how does the initial pointer get created and put into a pointer
variable? Write the line of code that puts the base address of the source
block into pointer p1.
answer...
p1 = &array[0];
-
Some computers have machine instructions which can do address calculations
while loading the data into the accumulator, thereby circumventing the need
for 3 or 4 separate instructions. What is the downside of this?
answer...
the computer's control unit is much more complicated
-
Why can characters be manipulated by the CSC-1 by merely shuffling integers
around between memory and the registers? (HINT: Remember ASCII?)
answer...
because there really are no characters! They are all just small numbers.
-
Write a short chunk of CSC-1 code to get the integer pointed at by
p
and store it into the A register. Do not change p.
answer...
LOD P
A2S
LDS
-
Write a short chunk of CSC-1 code to get the integer pointed at by
p, add 1 to it, and store it back into memory at the same
location. Do not change p.
(harder)
answer...
LOD P
A2S
LDS
ADD ONE
STS
...
ONE: NUM 1