## How neg a 10-bit value in ASM?

13 posts / 0 new
Author
Message

How to make a 10-bit value negative in ASM?

RES

do you want it sign extended to 16bits? is the value left or right justified?

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

RES,

With your endless series of questions about Asm programming maybe you chould get yourself a C compiler and it would answer all these questions for you?

Cliff

Quote:
How to make a 10-bit value negative in ASM?

You do a two's complement.

Regards,
Steve A.

The Board helps those that help themselves.

-N = 0-N

Or just flip the bits (1s complement) and add 1.

well that would depend... is that 10 bit value signed, or unsigned? Is it left or right justified? Is the result also to be 10 bits?

I'm amazed with all the questions RES has posted, he has not grasped a simple concept as this. It seems he spends too much time in the minutia of a single operation, and fails to see the larger concept.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

Last Edited: Tue. Dec 1, 2009 - 06:57 PM

This will, as glitch says, give you a sign extended 16 bit number. If that's not what you want, go to plan B.

```neg    r21
neg    r20
sbci   r21,0x00```

I was responding to glitch's first post. His second raises even more salient (pithy :? ) points. This snippet makes some assumptions.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

Chuck's code is ok, provided that the input is either
A) unsigned 10bit value, and is right justified
or
B) signed 10bit value, and is left justified

In both cases the result is 16bit signed. If the output is to be 10bit signed, it simply needs to be masked to the left or right boundaries.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

Are you sure? I got it from a compiler.

ignore this - it makes no sense out of context.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

Given "10 bit", I'd guess ADC counts.

For normal people (with single-ended conversions), that would lead to an unsigned result and the negate would be no different than any other negate.

If it is differential, then the ADC result can easily be sign-extended (the datasheet tells how to check polarity) and then it is again a standard negate.

Again RES has raised one of these "puzzles". Someone ought to mention to him that AVRStudio has simulator(s) that can be used.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

zbaird wrote:
Are you sure? I got it from a compiler.

ignore this - it makes no sense out of context.

I'm guessing that was in reference to me noting there was an error in your code... The error wasn't in your code, just in my head. [brainfart] I caught it, and removed that part of my reply, but I guess you were in the process of replying when I did.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

I wasn't going to blow your cover, glitch, being the king of the brainfarters.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org