Jim, Thanks. This seems to work ok. Geert jimmcguffin wrote: > > The problem is the "negate" step. You cannot negate the two bytes > separately. Negation is the same as a ones-complement followed by > adding one. This is covered in Atmel's application note #202. They > do it like this: > > ;***** Register Variables > .def ng1l = r16 > .def ng1h = r17 > > ;***** Code > ng16: > com ng1l ;Invert low byte ;Calculated by > com ng1h ;Invert high byte ;inverting all > subi ng1l,low(-1) ;Add 0x0001, low byte ;bits then adding > sbci ng1h,high(-1) ;Add high byte ;one (0x0001) > ;Expected result is 0xCBEE > > Jim > > > --- In AVR-Chat@yahoogroups.com, "Leon Heller" <leon.heller@d...> > wrote: > > ----- Original Message ----- > > From: Geert De Pecker > > To: AVR-Chat@yahoogroups.com > > Sent: Sunday, January 02, 2005 10:21 PM > > Subject: [AVR-Chat] newbie absolute value > > > > > > Hi, > > > > I have a question about abtaining the absolute value. I want to > > substract a 1 16bit values from eachother, but when the result is > > negative, set a bit and get the absolute value of the difference. > > > > I thought of the following, but that doesn't seem to work: > > > > ... > > ldi direction, 0 > > ; Substract values > > sub moveL, curPosL > > sbc moveH, curPosH > > ; If result positive, ok > > brcc PM1 > > ; Result negative, take absolute value and set flag > > neg moveL > > neg moveH > > ldi direction, 1 > > PM1: > > > > Any hints? > > > > I'd compare them first, to find which is the bigger of the two, > then > > subtract them appropriately with two separate bits of code, > setting the flag > > as necessary. > > > > Leon > > > > > > > > -- > > No virus found in this outgoing message. > > Checked by AVG Anti-Virus. > > Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: > 30/12/2004 > > > > > ------------------------------------------------------------------------ > *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 > <mailto:AVR-Chat-unsubscribe@yahoogroups.com?subject=Unsubscribe> > > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of > Service <http://docs.yahoo.com/info/terms/>. > >
Message
Re: [AVR-Chat] Re: newbie absolute value
2005-01-05 by Geert De Pecker
Attachments
- No local attachments were found for this message.