Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


attached
hes

ge programs
y primitive
assembly to
red it. The bootloader was only 81 bytes long. I
ntly and saw many a set of eyes glaze over. Anyone
hat I was doing suggested, after rolling his eyes to
OM programmer and write my code on a PC, like
normal person. They just didn’t get it -- I wanted to design the cheapest possible
to zero dollars. Some of us prefer to do
be learned and I learned beyond any doubt
enter 81 lousy bytes on a hand made computer.
ade the thing work
reenter all the data. 81
much until you try to enter them and their addresses in
After all the cursing died down I retired my machine,
ogrammer, and joined the real world.

er, burned into my mind the relation of data
relation until you get to C where this topic
ugs than any other.

ata is These
ses – information about the whereabouts of memory
ations. Memory is a place. Addresses tell us how to find the place. Sometimes
fusion occurs when we realize that addresses are just numbers and can become
mory locations having... addresses. The data at one
mory location can be the address of another memory location whose data may
may not be an address. Data is just a number, in our case an 8-bit byte. When
address of another location of data it is called a pointer. This might
m simple, but pointers can become so confusing and error prone that many
gher ages won’t let the programmer touch them. This ability

I once hand built an 8051 microprocessor ‘system’ with SRAM memory
to huge lantern battery (SRAM forgets if the power goes off) and switc
attached to the data and address ports. I would set a data byte then set an address
(two bytes) and push a button to write the data to the SRAM. When it was all
loaded, I pressed another button to start the 8051. I bet you can guess what I had
the program do. That’s right: blink LEDs. Later I wrote a program that allowed
the 8051 to communicate with an original IBM PC and download lar
from the PC, and once loaded – run them. I carefully wrote m
bootloader on paper in assembly language, then translated it from
machine code, then hand ente
bragged about this incessa
who knew anything about w
clear the glaze, that I get an EPR
a
system and factored in my time as equal
things the hard way if something is to
just how hard it is to correctly
Fortunately for me I’m too darn stubborn to admit defeat and m
until I accidentally disconnected the battery and had to
bytes may not seem like
binary on DIP switches.
bought an EPROM pr


That experience more than any oth
and addresses, a seemingly
nfusion and b


trivial
causes more co


D stored in memory locations – real tangible things made of silicon.
locations have addres
loc
con
data that can be stored in me
me
or
the data is the
se
hi


e
programming langu
Free download pdf