Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] newbie absolute value

2005-01-02 by Leon Heller

----- 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

Attachments

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.