I need to create a little assembly app for arm cpu which reads two 32 bit numbers from the address which register r0 points out. Then it compares absolute value of those two numbers and puts them back to those same addresses the way there's number which absolute value is higher in the first address. Finally the app sets 0 as the register r0 value, if the numbers were in the right order and sets 1 if the number orders needed to be changed.

The problem is that my little app isn't workin.
Hope someone can help me solve the problems there. thanks.

ldr r1,[r0,#0]
ldr r2,[r0,#4]
mov r3,#-1
cmp r1, #0
mulmi r4, r1, r3
movpl r4, r1
cmp r2, #0
mulmi r5, r2, r3
movpl r5, r2
subs r3,r4,r5
strmi r1,[r0,#4]
strmi r2,[r0,#0]
strpl r2,[r0,#4]
strpl r1,[r0,#0]
movpl r0,#0
movmi r0,#1

I need to create a little assembly app for arm cpu which reads two 32 bit numbers from the address which register r0 points out. Then it compares absolute value of those two numbers and puts them back to those same addresses the way there's number which absolute value is higher in the first address. Finally the app sets 0 as the register r0 value, if the numbers were in the right order and sets 1 if the number orders needed to be changed.

The problem is that my little app isn't workin.
Hope someone can help me solve the problems there. thanks.

ldr r1,[r0,#0]
ldr r2,[r0,#4]
mov r3,#-1
cmp r1, #0
mulmi r4, r1, r3
movpl r4, r1
cmp r2, #0
mulmi r5, r2, r3
movpl r5, r2
subs r3,r4,r5
strmi r1,[r0,#4]
strmi r2,[r0,#0]
strpl r2,[r0,#4]
strpl r1,[r0,#0]
movpl r0,#0
movmi r0,#1

The problem is easy to fix. You used an unsigned multiply. Another way of doing it is this:

LDMIA r0,{r1,r2}
orrs r1,r1,r1
rsbmi r4,r1,#0
movpl r4,r1
orrs r2,r2,r2
rsbmi r5,r2,#0
movpl r5,r2
cmp r4,r5
strlt r2,[r0]
strlt r1,[r0,#4]
mov r0,#0
movlt r0,#1

There's no need to write back the 2 values if their places don't need to be swapped.

Larry B.
P.S. my blog covers topics like this:
bitbank.wordpad.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.