PocketMatrix forums

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

Newbie need help

Hi.

I'm a newbie for arm asm, I try write a function for mask blt,but it worked incorrect :(
anyone can help me find out error? thanks

Code:

my_maskblit
MOV r12, sp
stmfd sp!, {r4 - r11,pc}

; r0 destination ( unsigned short )
; r1 source ( unsigned short )
; r2 mask color ( unsigned short )
; r3 length ( int )
my_maskblit_start
ldrh r5, [r0]
ldrh r6, [r1]
cmp r6, r2
bne my_maskblit_copyword
my_maskblit_nextword
add r0,r0,#2
add r1,r1,#2

subs r3,r3,#1
cmp r3,#0
bne my_maskblit_start
b my_maskblit_end
my_maskblit_copyword
strh r6, [r0]
b my_maskblit_nextword
my_maskblit_end
ldmfd sp!, {r4-r11,pc}
As a general note, you should use the conditional execution a lot more rather than using that many branches.

The SUBS sets the flags explicitly and thus doesn't need the CMP after it.

You certainly don't want to send the destination and source through as (16-bit) unsigned shorts.

At a guess, you're wanting something like (I can't test it):
Code:
; r0 destination ( unsigned long (address) )
; r1 source ( unsigned long (address) )
; r2 mask color ( unsigned short )
; r3 length ( int )

my_maskblit
stmfd sp!,{r5-r6,lr}

my_maskblit_start
ldrh r5, [r0] ; r5 = dest pixel
ldrh r6, [r1],#2 ; r6 = source pixel , move onto next source
cmp r6, r2 ; if source<>mask color
strneh r6,[r0] ; then dest=source
add r0,r0,#2 ; next destination
subs r3,r3,#1 ; decrement the count
bne my_maskblit_start ; if count<>0 then test the next pixel

ldmfd sp!,{r5-r6,pc}


If that's not what you're after, post what you're trying to do in a high(er)-level language like C (or any readable pseudo-code) and I'll show you how to do it in ARM.

For a potential (hacky) optimisation (maybe instruction count only - I can't remember if a post-indexed strneh has a latency penalty without a manual around), you could do:

Code:
; r0 destination ( unsigned long (address) )
; r1 source ( unsigned long (address) )
; r2 mask color ( unsigned short )
; r3 length ( int )

my_maskblit
stmfd sp!,{r5-r6,lr}

my_maskblit_start
ldrh r5, [r0],#2 ; r5 = dest pixel
ldrh r6, [r1],#2 ; r6 = source pixel , move onto next source
cmp r6, r2 ; if source<>mask color
strneh r6,[r0,#-2] ; then dest=source
subs r3,r3,#1 ; decrement the count
bne my_maskblit_start ; if count<>0 then test the next pixel

ldmfd sp!,{r5-r6,pc}
Hi.
refractor

Thanks your code and clear explain

my C function like below
Code:

inline void maskblit( ushort* pDest, ushort* pSrc, ushort nMask, int nLen )
{
for( i = nLen; i > 0; --i,++pDest,++pSrc )
if( *pSrc != nMask )
*pDest = *pSrc;
}


I think your code is right, will test soon, Thanks again.
Whoopsie, Correction:
Code:
stmfd sp!,{r5-r6,pc}

Should have been:
Code:
stmfd sp!,{r5-r6,lr}

(I've just corrected my post above).

You want to stack the link-register (a.k.a. lr, a.k.a. R14) which is the address the function should return to.

When you do:

Code:
ldmfd sp!,{r5-r6,pc}


you're then loading that value back into the program counter (PC) and the function should return correctly.