There are several Atmel app notes on multi-byte math. I think there are examples in both assy and C. Jim On Mon, 30 Aug 2004 12:31:12 -0300 "Mark Jordan" <mark@cpovo.net> wrote: > > > > > > I'm dealing with > two-complement math using 16bit registers. > Please take a look at my > routines and tell me if I'm doing > anything wrong or if there is a better way of doing it: > > --------- > > Adding two signed numbers > is: > > > add numl, fatl > > adc numh, fath > > --------- > > For subtracting two signed > numbers I'm using this: > > > sub numl, fatl > > sbc numh, fath > > Maybe I should use this > instead (I guess the result is the same): > > > com fatl > > com fath > > adiw fatl, $01 > > add numl, fatl > > adc numh, fath > > --------- > > For 16x16bit signed > multiply : > > > clr zero > > muls auxh, > genh > ; (signed)S1h * > (signed)S0h > > movw matl, prdl > > > mul auxl, > genl > ; S1l * S0l > > mov inth, prdh > > > mulsu genh, > auxl > ; (signed)S0h * S1l > > sbc math, > zero > ; Sign extend > > add inth, prdl > > adc matl, prdh > > adc math, zero > > > mulsu auxh, > genl > ; (signed)S1h * S0l > > sbc math, > zero > ; Sign extend > > add inth, prdl > > adc matl, prdh > > adc math, > zero > ; Result here > > --------- > > Thanks, > Mark Jordan > > > > > > > > > > > Yahoo! Groups Sponsor > > > ADVERTISEMENT > > > > > > > > > > > > > Yahoo! Groups Links > > To visit your group on the web, go > to:http://groups.yahoo.com/group/AVR-Chat/ > To unsubscribe from this group, send an email > to:AVR-Chat-unsubscribe@yahoogroups.com > Your use of Yahoo! Groups is subject to the Yahoo! Terms > of Service. > > > > > > > > > --------------------------------------------------------------- The Think Different Store http://www.thinkdifferentstore.com/ For All Your Mac Gear ---------------------------------------------------------------
Message
Re: [AVR-Chat] Back to basics - math questions
2004-08-30 by James Wagner
Attachments
- No local attachments were found for this message.