From: Michael Anburaj [mailto:embeddedeng@...]
Sent: 01 November 2004 17:31
To: lpc2000@yahoogroups.com
Subject: Re: [lpc2000] Division function
I just tried it on my setup.
source:
------
unsigned int test(U32 b, U32 c)
{
return b/c;
}
void APP_vMain (void)
{
unsigned int a=0, b=1000, c=0;
a=test(b,c);
CONSOL_Printf("a = %d, b = %d, c = %d\n\n",a,b,c);
}
from the elf image:
------------------
40000278 <test>:
40000278: e1a0c00d mov ip, sp
4000027c: e92dd800 stmdb sp!, {fp, ip, lr, pc}
40000280: e24cb004 sub fp, ip, #4 ; 0x4
40000284: eb000366 bl 40001024 <__udivsi3>
40000288: e89da800 ldmia sp, {fp, sp, pc}
4000028c <APP_vMain>:
4000028c: e1a0c00d mov ip, sp
40000290: e92dd830 stmdb sp!, {r4, r5, fp, ip, lr,
pc}
40000294: e3a05000 mov r5, #0 ; 0x0
40000298: e3a04ffa mov r4, #1000 ; 0x3e8
4000029c: e1a01005 mov r1, r5
400002a0: e24cb004 sub fp, ip, #4 ; 0x4
400002a4: e1a00004 mov r0, r4
400002a8: ebfffff2 bl 40000278 <test>
400002ac: e1a01000 mov r1, r0
400002b0: e59f000c ldr r0, [pc, #12] ; 400002c4
<.text+0x1c4>
400002b4: e1a02004 mov r2, r4
400002b8: e1a03005 mov r3, r5
400002bc: e89d6830 ldmia sp, {r4, r5, fp, sp, lr}
400002c0: ea000349 b 40000fec <CONSOL_Printf>
400002c4: 40008efc strmid r8, [r0], -ip
40001024 <__udivsi3>:
40001024: e2512001 subs r2, r1, #1 ; 0x1
40001028: 012fff1e bxeq lr
4000102c: 3a000036 bcc 4000110c <__udivsi3+0xe8>
40001030: e1500001 cmp r0, r1
40001034: 9a000022 bls 400010c4 <__udivsi3+0xa0>
40001038: e1110002 tst r1, r2
4000103c: 0a000023 beq 400010d0 <__udivsi3+0xac>
40001040: e311020e tst r1, #-536870912 ; 0xe0000000
40001044: 01a01181 moveq r1, r1, lsl #3
40001048: 03a03008 moveq r3, #8 ; 0x8
4000104c: 13a03001 movne r3, #1 ; 0x1
40001050: e3510201 cmp r1, #268435456 ; 0x10000000
40001054: 31510000 cmpcc r1, r0
40001058: 31a01201 movcc r1, r1, lsl #4
4000105c: 31a03203 movcc r3, r3, lsl #4
40001060: 3afffffa bcc 40001050 <__udivsi3+0x2c>
40001064: e3510102 cmp r1, #-2147483648 ; 0x80000000
40001068: 31510000 cmpcc r1, r0
4000106c: 31a01081 movcc r1, r1, lsl #1
40001070: 31a03083 movcc r3, r3, lsl #1
40001074: 3afffffa bcc 40001064 <__udivsi3+0x40>
40001078: e3a02000 mov r2, #0 ; 0x0
4000107c: e1500001 cmp r0, r1
40001080: 20400001 subcs r0, r0, r1
40001084: 21822003 orrcs r2, r2, r3
40001088: e15000a1 cmp r0, r1, lsr #1
4000108c: 204000a1 subcs r0, r0, r1, lsr #1
40001090: 218220a3 orrcs r2, r2, r3, lsr #1
40001094: e1500121 cmp r0, r1, lsr #2
40001098: 20400121 subcs r0, r0, r1, lsr #2
4000109c: 21822123 orrcs r2, r2, r3, lsr #2
400010a0: e15001a1 cmp r0, r1, lsr #3
400010a4: 204001a1 subcs r0, r0, r1, lsr #3
400010a8: 218221a3 orrcs r2, r2, r3, lsr #3
400010ac: e3500000 cmp r0, #0 ; 0x0
400010b0: 11b03223 movnes r3, r3, lsr #4
400010b4: 11a01221 movne r1, r1, lsr #4
400010b8: 1affffef bne 4000107c <__udivsi3+0x58>
400010bc: e1a00002 mov r0, r2
400010c0: e12fff1e bx lr
400010c4: 03a00001 moveq r0, #1 ; 0x1
400010c8: 13a00000 movne r0, #0 ; 0x0
400010cc: e12fff1e bx lr
400010d0: e3510801 cmp r1, #65536 ; 0x10000
400010d4: 21a01821 movcs r1, r1, lsr #16
400010d8: 23a02010 movcs r2, #16 ; 0x10
400010dc: 33a02000 movcc r2, #0 ; 0x0
400010e0: e3510c01 cmp r1, #256 ; 0x100
400010e4: 21a01421 movcs r1, r1, lsr #8
400010e8: 22822008 addcs r2, r2, #8 ; 0x8
400010ec: e3510010 cmp r1, #16 ; 0x10
400010f0: 21a01221 movcs r1, r1, lsr #4
400010f4: 22822004 addcs r2, r2, #4 ; 0x4
400010f8: e3510004 cmp r1, #4 ; 0x4
400010fc: 82822003 addhi r2, r2, #3 ; 0x3
40001100: 908220a1 addls r2, r2, r1, lsr #1
40001104: e1a00230 mov r0, r0, lsr r2
40001108: e12fff1e bx lr
4000110c: e52de004 str lr, [sp, #-4]!
40001110: eb000034 bl 400011e8 <__div0>
40001114: e3a00000 mov r0, #0 ; 0x0
40001118: e49df004 ldr pc, [sp], #4
400011e8 <__div0>:
400011e8: e12fff1e bx lr
Cheers,
-Mike.
--- dean_j_greaves <dgreaves@...> wrote:
>
> Hi,
> I having a problem with some code i'm developing
> on the LPC2214
> chip using GNU tools.
> I have a simple function that performs a division.
>
> unsigned int a=0, b=1000, c=10;
>
> a=b/c;
>
> When i compile up the code and download to the
> target, the code
> breaks when i step over this division routine. When
> i step in to the
> assembly code for the division, it has compiled in
> __divsi3 from the
> libgcc library.
> The problem appears to be that just before the
> return from the
> division function, it attempts to restore registers
> from the stack
> that it never actually push onto the stack.
> Has anyone ever come across this before. Any help
> would be
> gratefully received.
>
> Dean
>
>
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
Yahoo! Groups Sponsor
<http://us.ard.yahoo.com/SIG=12922u7mr/M=281955.5530326.6602771.3001176/D=gr
oups/S=1706554205:HM/EXP=1099416732/A=2343726/R=0/SIG=12im15sga/*http:/clk.a
tdmt.com/VON/go/yhxxxvon01900091von/direct/01/&time=1099330332354262>
<http://us.ard.yahoo.com/SIG=12922u7mr/M=281955.5530326.6602771.3001176/D=gr
oups/S=1706554205:HM/EXP=1099416732/A=2343726/R=1/SIG=12im15sga/*http:/clk.a
tdmt.com/VON/go/yhxxxvon01900091von/direct/01/&time=1099330332354262>
Get unlimited calls to
<http://us.ard.yahoo.com/SIG=12922u7mr/M=281955.5530326.6602771.3001176/D=gr
oups/S=1706554205:HM/EXP=1099416732/A=2343726/R=1/SIG=12im15sga/*http:/clk.a
tdmt.com/VON/go/yhxxxvon01900091von/direct/01/&time=1099330332354262>
U.S./Canada
<http://us.ard.yahoo.com/SIG=12922u7mr/M=281955.5530326.6602771.3001176/D=gr
oups/S=1706554205:HM/EXP=1099416732/A=2343726/R=1/SIG=12im15sga/*http:/clk.a
tdmt.com/VON/go/yhxxxvon01900091von/direct/01/&time=1099330332354262>
<http://view.atdmt.com/VON/view/yhxxxvon01900091von/direct/01/&time=10993303
32354262>
<http://us.adserver.yahoo.com/l?M=281955.5530326.6602771.3001176/D=groups/S=
:HM/A=2343726/rand=401492818>
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/lpc2000/
* To unsubscribe from this group, send an email to:
lpc2000-unsubscribe@yahoogroups.com
<mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service.
[Non-text portions of this message have been removed]