Yahoo Groups archive

AVR-Chat

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

Thread

Negarive numbers in .db statements

Negarive numbers in .db statements

2012-03-21 by David V

All this time working with the AVR, and I've never had to do this...

I need a way to change the sign on a term in a .db statement.

Something like this: (which does not work..)

.equ  SignBit = -1;

.db  Thing,(Thing + (3*SignBit)), (Thing - (3*SignBit)), Thing
.and so on..


Otherwise, I'm going to be forced to do an annoyingly large amount of hand editing data files. :P

Any pointers?

Re: [AVR-Chat] Negarive numbers in .db statements

2012-03-21 by STEVEN HOLDER

David,
 
If you need to change the sign, you could cast the signbit as a signed char and xor with 0x80, which is the sign bit, would that do the trick as not quiet sure what you are trying to do.
 
Regards
 


________________________________
Show quoted textHide quoted text
From: David V <microbrix@gmail.com>
To: AVR-Chat@yahoogroups.com 
Sent: Wednesday, 21 March 2012, 5:56
Subject: [AVR-Chat] Negarive numbers in .db statements


  

All this time working with the AVR, and I've never had to do this...

I need a way to change the sign on a term in a .db statement.

Something like this: (which does not work..)

.equ SignBit = -1;

.db Thing,(Thing + (3*SignBit)), (Thing - (3*SignBit)), Thing
.and so on..

Otherwise, I'm going to be forced to do an annoyingly large amount of hand editing data files. :P

Any pointers?




[Non-text portions of this message have been removed]

Re: Negarive numbers in .db statements

2012-03-21 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, David VanHorn <microbrix@...> wrote:
>I need the distortion to be positive or negative..
I've never used avrasm before but I just tried this and it seems to work.

.equ SignBit = (0-1)
.equ Thing = 5
.db Thing,(Thing + (3*SignBit)), (Thing - (3*SignBit)), Thing

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Re: [AVR-Chat] Negarive numbers in .db statements

2012-03-21 by David VanHorn

On Wed, Mar 21, 2012 at 3:05 AM, STEVEN HOLDER
<s.holder123@btinternet.com> wrote:
> David,
>
> If you need to change the sign, you could cast the signbit as a signed char and xor with 0x80, which is the sign bit, would that do the trick as not quiet sure what you are trying to do.


That won't get it for me.
I'm trying to establish a distortion on some test case data, and I
need the distortion to be positive or negative..
In the truncated example I gave, if the distortion is "+3" then the
values might be something like

100,103,97,100

If the distortion is -3, then the values would be

100, 97, 103, 100

The thing is that I should be able to include a term like (Sign * Var)
in an addition, and have it work properly.

Re: [AVR-Chat] Negarive numbers in .db statements

2012-03-21 by Jim Wagner

On Mar 21, 2012, at 7:23 AM, David VanHorn wrote:

> On Wed, Mar 21, 2012 at 3:05 AM, STEVEN HOLDER
> <s.holder123@btinternet.com> wrote:
> > David,
> >
> > If you need to change the sign, you could cast the signbit as a signed char and xor with 0x80, which is the sign bit, would that do the trick as not quiet sure what you are trying to do.
> 
> That won't get it for me.
> I'm trying to establish a distortion on some test case data, and I
> need the distortion to be positive or negative..
> In the truncated example I gave, if the distortion is "+3" then the
> values might be something like
> 
> 100,103,97,100
> 
> If the distortion is -3, then the values would be
> 
> 100, 97, 103, 100
> 
> The thing is that I should be able to include a term like (Sign * Var)
> in an addition, and have it work properly.
> 
It depends entirely on how your code uses the data. If you read it into an unsigned int, which is the effective format for most asm code, it will interpret -1 as a positive number. You can't fool it. If your code CAN use negative numbers, as negative, then simply subtract the positive value from zero.

Jim Wagner
Oregon Research Electronics



[Non-text portions of this message have been removed]

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.