#: 15753 S12/OS9/68000 (OSK)
02-Jul-92 23:58:24
Sb: #15752-C_Question
Fm: Kevin Darling 76703,4227
To: Kevin Darling 76703,4227 (X)
So now we look at Pete's example (very slightly modified):
main() { int x;
char a[5][200];
for (x = 0; x <= 5; ++x)
gets(a[x]); }
psect test_c,0,0,0,0,0 * main() * {
ttl main main:
pshs u
ldd #_1
lbsr _stkcheck
* int x; * char a[5][200]; * * for (x = 0; x <= 5; ++x)
leas -1002,s # make room for int_x and 5*200 one-byte chars
clra
clrb
std 1000,s # x=0
lbra _4 # enter "for" loop
* gets(a[x]); _2
ldd 1000,s # x
pshs d
ldd #200 # size of each array element
lbsr ccmult # multiply stack param (x) * array_element_size
leax 0,s # point to beginning of array
leax d,x # point to a[x][0]
pshs x # push parameter for gets
lbsr gets # call gets function
leas 2,s * } _5
ldd 1000,s # x=x+1
addd #1
std 1000,s _4
ldd 1000,s # etc
cmpd #5
lble _2 _3
leas 1002,s
puls u,pc _1 equ -1072
endsect
Now, even tho we had to guess at the function of ccmult, it was still clear
that we were passing the address of an _allocated_ char subarray to the gets
function... and not just a pointer to hyperspace. Does this make sense?
The other thing that looking at -ca output does is to impress the fact that C
is basically an assembly macro language... and that *pointers are just
variables being used as extra "index registers". best - kevin
|