PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to process multiple data in ARM assembly

I was just writing ARM assembly in these few days.
And I want to implement a bilinear filter like

void Interpolate(uchar *src,uchar *dest, int width)
{
int i;
for(i=0;i<width;i++)
*(dest) = (*(src) + *(src+1) +1) >> 1;
}

And I want to use LDR to load 4 bytes instead of using LDRB 4 times, but the program seems crashed when I ran it on my PDA,can anyone tell me why?
the ASM is like :

Interpolate_ASM
stmdb sp!, {r4-r8, r10, r11, lr}
ldr r4,[r0] ;I added this useless
;code and r4 will never be
;used ,but the program
;crashed anyway

;start original code
.
.
.
;end of original code

ldmia sp!, {r4-r8, r10, r11, pc} ; ldmfd
ENDP
Check you're loading from a 4-byte aligned address.
refractor wrote:
Check you're loading from a 4-byte aligned address.


I used my mem_alloc() to ensure that the memory is aligned, but it seems that this function does not work. So I doubt that is it worth to use LDR insteadof IDRB?Or there is another way to ensure the
memory is aligned before I enter Interpolate()?

Code:
void* mem_alloc(int size)
{
unsigned char *tmp = NULL;
unsigned char *mem_ptr = NULL;

if((tmp = (unsigned char*)malloc((size+32)*sizeof
(char))) != NULL)
{
mem_ptr = (unsigned char*)((unsigned int)(tmp + 32 - 1)&(~
(unsigned int)(32 - 1)));
if(mem_ptr == tmp) mem_ptr += 31;
*(mem_ptr - 1) = (unsigned char)(mem_ptr - tmp);
return (void *) mem_ptr;
}
malloc should return a pointer that is already 4 byte aligned.

Your mem_alloc routine is a whole lot more complex than it needs to be. Something like this would suffice:

char *pData=(char *)malloc(nBytes+4);
pData+=4-(((unsigned int)pData)&3);

However, that should not be necessary in the first place.

Dan East
Dan East wrote:
malloc should return a pointer that is already 4 byte aligned.

Your mem_alloc routine is a whole lot more complex than it needs to be. Something like this would suffice:

char *pData=(char *)malloc(nBytes+4);
pData+=4-(((unsigned int)pData)&3);

However, that should not be necessary in the first place.

Dan East


I guess I know where the problem is.....
thanks a lot