#176978 - blessingta@hotmail.co.uk - Sun Nov 13, 2011 10:44 pm
hi
What are simple examples or a simple example of where asm is appropriate?
Plus any recommended good tutorials? I've barely got 3weeks left till the deadline
#176980 - Miked0801 - Mon Nov 14, 2011 5:40 pm
Honestly, I wouldn't worry about asm until forced. The only place you probably should have it is in your bootstrap/vector table code and perhaps in a few, very high usage areas.
#176982 - headspin - Tue Nov 15, 2011 8:39 am
If you're interested in learning ARM ASM we have some instructions and examples in this thread
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#176990 - blessingta@hotmail.co.uk - Wed Nov 16, 2011 7:51 pm
i just need this for the coursework criteria so I can get higher marks (one of those annoying uni requirements) otherwise I would try to be as realistic as possible in approaching it and knowing that time would be required before I can get anything decent out of it
#176991 - Dwedit - Wed Nov 16, 2011 10:56 pm
A good example of ASM is writing your own unrolled memcpy function. You can subtract 32 bytes from the bytes remaining, then copy 8 words using ldmia/stmia instructions. Tonc even includes an example.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#176997 - blessingta@hotmail.co.uk - Fri Nov 18, 2011 8:12 pm
thanks
Whats the psuedo code for memory copying?
Is it as simple as taking void data and then typecasting it to the address of what you want to send it too?
I'm planning to learn how to do it in c++, before I adapt it to gba asm
#177008 - Miked0801 - Mon Nov 21, 2011 5:44 pm
Memcopy, written from memory here for you:
Code: |
void memByteCopy(void *dest, const void *src, int bytes);
void memCopy(void *dest, const void *src, int bytes);
void memCopy(void *dest, const void *src, int bytes)
{
if(((int)(dest) & 0x03) != 0 || ((int)(src) & 0x03) != 0)
{
memByteCopy(dest, src, bytes);
return;
}
unsigned int *destAlign = (unsigned int *)dest;
unsigned int *srcAlign = (unsigned int *)src;
int numWords = bytes / 4;
while(numWords--)
{
*destAlign++ = *srcAlign++;
}
bytes &= 0x3;
memByteCopy(destAlign, srcAlign, bytes);
}
void memByteCopy(void *dest, const void *src, int bytes)
{
unsigned char *byteSrc = (unsigned char *)src;
unsigned char *byteDest = (unsigned char *)dest;
while(bytes--)
{
*byteDest++ = *byteSrc++;
}
}
|
MemCopy handled by the compiler:
Code: |
typedef struct _generic_32_bytes
{
unsigned int val[8];
} GENERIC_32_BYTES;
void foo(void *dest, const void *src)
{
// Assumes 4-byte alignment or else bad things will happen...
GENERIC_32_BYTES *destPtr = (GENERIC_32_BYTES *) dest;
GENERIC_32_BYTES *srcPtr (GENERIC_32_BYTES *) src;
// Copy 32-bytes using very efficient compiler generated code.
*destPtr = *srcPtr;
}
|
For bonus points, go look up Duff's Device. It is a very efficient way of getting large amounts of data copied without much looping overhead - like the above memCopy does.
The above code can also be hand assembled, but you won't get that much benefit. The above C code so closely emulates the low level that any good compiler should be able to match a novice hand attempt. Unrolling and jump tables can be also coded on the C side for similar performance as asm as well.