avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## [avr-gcc-list] Problem With Call to Mulsi3

 From: Thomas D. Dean Subject: [avr-gcc-list] Problem With Call to Mulsi3 Date: Mon, 16 Feb 2009 13:00:47 -0800

```I have code producing strange results.  The application uses an 8-bit
counter and overflow counts to measure distance with an ultrasonic
transponder.  The overflow and count look Ok.  Fitting an equation to
experimental data, I get
dist = 0.013657 * cnts + -3.996578.
Converting the multiplication, I have
distance = (overflow*256 + count)*895/2^16 - 4
Where 895 is 0.013657 * 65536

I cannot find what I am doing wrong.  Must be something simple.

I want to multiply a 16-bit value by a 16-bit value and keep the high
order 16 bits, using only the low 8 bits of the result.

extern volatile uint8_t range_local_ovfl;
extern volatile uint8_t range_local;
extern volatile uint8_t range_count;

if (range_new == TRUE)
{
{
uint32_t distance = range_local_ovfl<<8;
distance += (uint32_t)range_count;
distance = =895*distance;
distance = distance >> 16;
range_local = (uint8_t)(distance - 4);
}
...
}
895*distance generates a call to __mulsi3, multiplying r25:22 by r21:18
and returning the result in r25:22.

However, I cannot find where r21:18 are set in the code.  Looking at the
output of avr-gcc -S, I cannot find any of r18:21.

avr-gcc  -S -mmcu=atmega32  -Wall -Wmissing-prototypes  -Os
-fno-strict-aliasing -I../include -I../../../avrx2.6   -I.
-I../../../../asus-avr-1.0/include   -c ../common/range.c -o -
| grep r18
produces nothing.  Same for all of r19..r21

>From avr-objdump,
1bce:       0e 94 e3 12     call    0x25c6 ; 0x25c6<AvrXStartTimer>
1bd2:       80 91 c7 02     lds     r24, 0x02C7
1bd6:       81 30           cpi     r24, 0x01       ; 1
1bd8:       f9 f4           brne    .+62    ; 0x1c18 <range+0x60>
1bda:       80 91 96 02     lds     r24, 0x0296
1bde:       18 2f           mov     r17, r24
1be0:       00 e0           ldi     r16, 0x00       ; 0
1be2:       b8 01           movw    r22, r16
1be4:       88 27           eor     r24, r24
1be6:       77 fd           sbrc    r23, 7
1be8:       80 95           com     r24
1bea:       98 2f           mov     r25, r24
1bec:       e0 91 87 02     lds     r30, 0x0287
1bf0:       6e 0f           add     r22, r30
1bf2:       71 1d           adc     r23, r1
1bf4:       81 1d           adc     r24, r1
1bf6:       91 1d           adc     r25, r1
1bf8:       0e 94 ec 16     call    0x2dd8  ; 0x2dd8 <__mulsi3>
1bfc:       bc 01           movw    r22, r24
1bfe:       88 27           eor     r24, r24
1c00:       99 27           eor     r25, r25
1c02:       64 50           subi    r22, 0x04       ; 4
1c04:       60 93 b6 02     sts     0x02B6, r22
1c08:       80 91 87 02     lds     r24, 0x0287
1c0c:       80 93 7a 02     sts     0x027A, r24
1c10:       80 91 c6 02     lds     r24, 0x02C6
1c14:       80 93 b9 02     sts     0x02B9, r24
1c18:       c0 9a           sbi     0x18, 0 ; 24

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]