Hi
This is not an exact answer for your question, but below are some functions
written in assembly language (in fact C functions wit assembly part), which
do something... And which run.=20
May be there is better, because I don't know assembly language of HC12 very
well, and I write 99.99% of my soft in C language. But sometimes, assembly
is quicker than what compiler do.=20
So, keep in your mind I'm not a specialist of assembly. I wrote some
functions, and after debug, I saw they are OK, that's all.
Hope this helps you... Good luck... And go to C language ! It's so easy !
Joel
//************************************************************************
// Simple copy of nb_octets from a source array to a destination array
// C function, with assembly part
void CAL_CopierTab (char *dest, const char *srce, char nb_octets)
{ asm (
"ldab %nb_octets\n" // b <-- nb of bytes
"pshx \n" // save X
"pshy \n" // save Y
"ldy %dest \n" // Y points on destination
"ldx %srce \n" // X points on source
"CopieTab1: \n"
"ldaa 0,x \n" // A <-- *X
"staa 0,y \n" // *Y <-- A
"inx \n"
"iny \n"
"dbne b,CopieTab1\n" // done ? sort
"puly \n"
"pulx \n"
);
}
"pshx", "pshy" and "puly", "pulx" are because of call structure of a C
function... So, maybe you can omit them.
So, I can suppose in assembly language for a 10 bytes array :
ldab #10 ; B register contains number of
bytes
ldy #dest_address ; Y <- destination address
ldx #srce_address ; X <- source address
CopieTab1:
ldaa 0, X ; A <-- content of the address
pointed by X
staa 0, Y ; A --> address pointed by Y
inx ; next source address
iny ; next destination address
dbne b, CopieTab1 ; decrement counter B and branch if not zero
=09
As you can see, I use accu B for the counter, X index for source, Y for
destination. Accu A is used as accu from source to destination :
A <- source
A -> destination
So, you can use accu A to store the min number, for example, in ordre to
search for the min :
ldaa #$ff ; A <- the max possible value
loop:
cmpa 0, x ; compare A avec byte pointed by (X
+ 0)
bcs next ; branch if Carry clear
ldaa 0, x ; a <- byte pointed by (X + 0)
next:
dbne loop=09
Be careful, I'm not sure for "cmpa 0, x", but I suppose it's OK when I read
data sheets.
Data sheet says "cmpa" do (A) - (M), and move flags NZVC.
So, I think if Carry is set, it's because (M) is greater than (A).
So, if carry set, I've nothing to do, else I've to change A value.
In C language, "on the fly" (I don't have time to check) :
#define Byte unsigned char // replace "Byte" by
"unsigned char"
// C function which returns the min value of an array
Byte LookForMini (Byte *array, Byte nb_elem)
{ Byte mini;
mini =3D 255; // the maxi value possible
while (nb_elem)
{ if (*array < mini) mini =3D *array;
array++; // next element of the array
nb_elem--; // decrement counter of elements
}
return mini;
}
And you call this function as follow :
void main (void)
{ Byte value; // the value you need
Byte array[10];
// Init the array...
// Find for the mini value
// "sizeof (array)" : the compiler will calculate for you=20
// the number of bytes of the array, so, if you change
// it, you will not have to change each call
value =3D LookForMini (array, sizeof (array)/sizeof (Byte));
// some things to do...
// Find for the maxi value
value =3D LookForMaxi (array, sizeof (array));
// some things to do...
}
Some comments :
"sizeof" asks the compiler to calculate the number of bytes of something.
Example : "sizeof (long)" will return 4, if a long use 4 bytes with this
compiler.
So, "sizeof (array)" calculates the number of bytes of that array
divided by "sizeof (Byte) calculates the number of ELEMENTS of that array.
I know, it's a little bit heavy ?
But this system is good for each type you can find, define, use... and make
easier update of a program. For example, on a big program, you just change
the number of elements of the array, and you don't have to look for each
time you use that array, and modify, without any error, etc...
But I'm not here to give you a course about C Language.
Just know C is a very very good language !
//************************************************************************
// Below an other example which rotate left an array of bytes
// Shift left of an array of "nb_elem"
void CAL_DecalerAigus1 (char *tab, char nb_elem)
{
asm (
"ldab %nb_elem \n" // b <-- nb d'=E9l=E9ments
"pshx \n" // sauve X
"ldx %tab \n" // X pointe sur le tableau
"clra \n" // efface A et flags
"Aigus1: \n"
"rol 0,x \n" // d=E9calage gauche de
l'octet point=E9 par X
"inx \n"
"dbne b,Aigus1 \n" // fini ? sort
"pulx \n"
);
}
> -----Message d'origine-----
> De=A0: 6...@yahoogroups.com [mailto:6...@yahoogroups.com] De la part =
de
> knadoor
> Envoy=E9=A0: jeudi 6 mars 2008 16:48
> =C0=A0: 6...@yahoogroups.com
> Objet=A0: [68HC12] Re: need help with a small number sorting program
> please!!
>=20
> Yes I see where your coming from but the thing is that we just started
> this stuff like last week when semester started, also I don't see my
> tutor until mid next week. This is the last exercise which I'm eager
> to finish off by then to work on other stuff... So if you know how to
> do it I'm *only* after a hint in the right direction...
>=20
> thanks.
>=20
>=20
>=20
>=20
>
=20

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )