Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Divide by zero

Divide by zero

2005-12-31 by soren_t_hansen

What happenes if you make a division by zero on the LPC2132? I suspect
that you enter the Undefined Instruction exception handler, but is
that correct? I haven't been able to find anything about it in the manual.

Best Regards
Søren

Re: [lpc2000] Divide by zero

2005-12-31 by Richard Duits

The ARM7TDMI does not have a divide instruction, so this is depending on 
the implementation of your compilers run time library.

Richard.


soren_t_hansen wrote:
Show quoted textHide quoted text
> What happenes if you make a division by zero on the LPC2132? I suspect
> that you enter the Undefined Instruction exception handler, but is
> that correct? I haven't been able to find anything about it in the manual.
>
> Best Regards
> S\ufffdren

Re: [lpc2000] Divide by zero

2005-12-31 by Karl Olsen

---- Original Message ----
Show quoted textHide quoted text
From: "soren_t_hansen" <soren_t_hansen@...>
To: <lpc2000@yahoogroups.com>
Sent: Saturday, December 31, 2005 12:12 PM
Subject: [lpc2000] Divide by zero

> What happenes if you make a division by zero on the LPC2132? I suspect
> that you enter the Undefined Instruction exception handler, but is
> that correct? I haven't been able to find anything about it in the
> manual.

No, the ARM7TDMI does not have a hardware divide instruction, so divisions
are purely a software matter.

With gcc, the compiler calls __divsi3 and __udivsi3 for signed and unsigned
integer divisions, and they are implemented in libgcc, a part of gcc.  If
you try to divide by zero, they call __div0, and then return 0.  The default
implementation of __div0 does nothing.

Other compilers might handle it differently.

Karl Olsen

Re: Divide by zero

2005-12-31 by soren_t_hansen

--- In lpc2000@yahoogroups.com, "Karl Olsen" <kro@p...> wrote:
>
> ---- Original Message ----
> From: "soren_t_hansen" <soren_t_hansen@y...>
> To: <lpc2000@yahoogroups.com>
> Sent: Saturday, December 31, 2005 12:12 PM
> Subject: [lpc2000] Divide by zero
> 
> > What happenes if you make a division by zero on the LPC2132? I suspect
> > that you enter the Undefined Instruction exception handler, but is
> > that correct? I haven't been able to find anything about it in the
> > manual.
> 
> No, the ARM7TDMI does not have a hardware divide instruction, so
divisions
> are purely a software matter.
> 
> With gcc, the compiler calls __divsi3 and __udivsi3 for signed and
unsigned
> integer divisions, and they are implemented in libgcc, a part of
gcc.  If
> you try to divide by zero, they call __div0, and then return 0.  The
default
> implementation of __div0 does nothing.
> 
> Other compilers might handle it differently.
> 
> Karl Olsen
>

I'm using the GNUARM toolchain. Does that mean that a divide by zero
doesn't result in anything?

/Søren

Re: [lpc2000] Re: Divide by zero

2005-12-31 by Karl Olsen

---- Original Message ----
Show quoted textHide quoted text
From: "soren_t_hansen" <soren_t_hansen@...>
To: <lpc2000@yahoogroups.com>
Sent: Saturday, December 31, 2005 2:33 PM
Subject: [lpc2000] Re: Divide by zero

> --- In lpc2000@yahoogroups.com, "Karl Olsen" <kro@p...> wrote:
>>
>> ---- Original Message ----
>> From: "soren_t_hansen" <soren_t_hansen@y...>
>> To: <lpc2000@yahoogroups.com>
>> Sent: Saturday, December 31, 2005 12:12 PM
>> Subject: [lpc2000] Divide by zero
>>
>>> What happenes if you make a division by zero on the LPC2132? I
>>> suspect that you enter the Undefined Instruction exception handler,
>>> but is that correct? I haven't been able to find anything about it
>>> in the manual.
>>
>> No, the ARM7TDMI does not have a hardware divide instruction, so
>> divisions are purely a software matter.
>>
>> With gcc, the compiler calls __divsi3 and __udivsi3 for signed and
>> unsigned integer divisions, and they are implemented in libgcc, a
>> part of gcc.  If you try to divide by zero, they call __div0, and then
>> return 0.  The default implementation of __div0 does nothing.
>>
>> Other compilers might handle it differently.
>
> I'm using the GNUARM toolchain. Does that mean that a divide by zero
> doesn't result in anything?

Yes, the result is zero.  If you want something more to happen, you can 
provide your own __div0 function:

void __div0 (void)
{
  printf ("Division by zero!\n");
}


Karl Olsen

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.