Re: A89: matrix in C
[Prev][Next][Index][Thread]
Re: A89: matrix in C
Or rather a experienced programmer in general (on a 68k chip) would
write:
int a[5][5];
asm volatile ("move.l %0,%a0" :: "g" (a));
asm volatile ("
move.w #12,d0
\ClearVarALoop:
clr.l (a0)+
dbra \ClearVarALoop
clr.w (a0)
");
... I was bored... that would be quicker than memset or whatever the one
is that sets it to 0... since neither of them optimize themselves by
using longs...
Zeljko Juric wrote:
>
> Basically, to declare a matrix, you need to use:
>
> type name[dimension1][dimension2];
>
> for example:
>
> int a[5][5];
>
> And, to access element of the matrix, you need to use:
>
> name[index1][index2];
>
> for example:
>
> a[2][3]=10;
>
> or
>
> x=a[1][2];
>
> But note that indices are not from 1 to dimension, but from
> 0 to dimension-1. So, in the above example, both indices are
> in range 0 to 4, not 1 to 5.
>
> To fill all matrix by zeroes, you can use this code (more
> clear than the code given by Robin):
>
> int main ( void )
> {
> int a[5][5],i,j; // A 5x5 array of ints, and a single one
> for(i=0;i<5;i++)
> for(j=0;j<5;j++)
> a[i][j]=0;
> }
>
> although the experienced C programmer will simply use:
>
> memset(a,0,25*sizeof(int));
>
> Zeljko Juric
--
Scott "_Wrath_" Dial
wrath@calc.org
ICQ#3608935
Member of TCPA - tcpa.calc.org
_____________________________________________
NetZero - Defenders of the Free World
Click here for FREE Internet Access and Email
http://www.netzero.net/download/index.html
References: