Jump to content



0

ABS in assembly


14 replies to this topic

#1 Willsy OFFLINE  

Willsy

    Dragonstomper

  • 765 posts
  • Location:Uzbekistan (no, really!)

Posted Tue Sep 27, 2011 2:04 AM

Does ABS set the flags such that it tells you the sign of the number BEFORE conversion to positive? The explanation in Editor Assembler is rather obtuse, as usual.

Mark

#2 sometimes99er OFFLINE  

sometimes99er

    Stargunner

  • 1,922 posts
  • Location:Denmark

Posted Tue Sep 27, 2011 3:19 AM

I guess it's always AFTER. Here's some cuts from 9900 Data Manual.

Posted Image

#3 RXB OFFLINE  

RXB

    Dragonstomper

  • 539 posts
  • Location:Vancouver, Washington, USA

Posted Tue Sep 27, 2011 5:05 AM

The first bit is always a sign bit. So if bit 1 is set it is negative before you use ABS.
If it is 0 then it is positive.
I only work in GPL but this is the way I do it, unlikely Assembly or Forth are different.

As per TI Assembly book: Taking the two's complement of a number results in a number of equal absolute value, but the opposite sign.

Edited by RXB, Tue Sep 27, 2011 5:06 AM.


#4 matthew180 OFFLINE  

matthew180

    Stargunner

  • 1,242 posts
  • Location:Marshall, Michigan

Posted Tue Sep 27, 2011 7:06 AM

The status register is updated as the *result of* instruction execution, and in most cases, comparing the result of the instruction to zero.

As RXB mentioned, if you need to know the sign of a value prior to using ABS, you can check the MSb (bit) of the value first (I can think of several ways to do this), or save the value before doing the ABS, then comparing the result to what you saved. It really depends on what you are doing and how your program flow needs to work; one way might fit better than another.

#5 matthew180 OFFLINE  

matthew180

    Stargunner

  • 1,242 posts
  • Location:Marshall, Michigan

Posted Tue Sep 27, 2011 7:06 AM

-- delete double post... not sure how that happened --

Edited by matthew180, Tue Sep 27, 2011 7:07 AM.


#6 Willsy OFFLINE  

Willsy

    Dragonstomper

  • 765 posts
  • Location:Uzbekistan (no, really!)

Posted Tue Sep 27, 2011 9:48 AM

Thanks guys. I used xor to do what I needed. I like xor ;)

#7 Lee Stewart OFFLINE  

Lee Stewart

    Chopper Commander

  • 175 posts

Posted Tue Sep 27, 2011 2:36 PM

Mark...

Actually, for ABS, it is the original source operand that is compared to 0, not the result. Even the cut above from the data manual shows that the result is not compared to 0.

...lee

#8 adamantyr OFFLINE  

adamantyr

    Moonsweeper

  • 424 posts

Posted Tue Sep 27, 2011 3:01 PM

The TI Tech page says this about ABS:

"Takes the absolute value of the destination operand (i.e. negates it if it is less than 0) and compares the result to zero."

The data manual shows it does NOT compare the result to 0... the question is if it compares the source. It's easy enough to check which is right with a short program.

Adamantyr

#9 Lee Stewart OFFLINE  

Lee Stewart

    Chopper Commander

  • 175 posts

Posted Tue Sep 27, 2011 3:28 PM

I am not sure a program is necessary. The overflow bit cannot possibly ever get set if the result is compared to 0 because the result of an ABS instruction can never be >8000, i.e., only the sign bit set. However, as always, the proof of the pudding is in the eating.

...lee

#10 matthew180 OFFLINE  

matthew180

    Stargunner

  • 1,242 posts
  • Location:Marshall, Michigan

Posted Tue Sep 27, 2011 8:10 PM

Interesting observation, Lee. According to the 9900 datasheet, the status bits for the ABS instruction are set based on the value of the *source* operand, i.e. the value prior to performing the ABS operation.

#11 Willsy OFFLINE  

Willsy

    Dragonstomper

  • 765 posts
  • Location:Uzbekistan (no, really!)

Posted Wed Sep 28, 2011 1:49 AM

Exactly, that's what I was getting at.

There's no point in setting L< and A< *after* the instruction executes, since the value will ALWAYS be positive (or 0)!

Still, the ED/AS manual goes 'round the houses as usual instead of just damn spelling it out!

#12 sometimes99er OFFLINE  

sometimes99er

    Stargunner

  • 1,922 posts
  • Location:Denmark

Posted Wed Sep 28, 2011 3:37 AM

View PostWillsy, on Wed Sep 28, 2011 1:49 AM, said:

"Me and me wife's Brian!"
Now that I've looked at it a few times. What's it about ? :)

Edited by sometimes99er, Wed Sep 28, 2011 3:37 AM.


#13 Fishsta OFFLINE  

Fishsta

    Space Invader

  • 27 posts

Posted Wed Sep 28, 2011 5:50 AM

I would hazard a guess at Monty Python's Life of Brian.

In a Spartacus kind of situation, the people set to be crucified on the crosses are asked who is Brian of Nazareth for a reprieve. Brian is too busy shouting at his friends who have left him to die, so "Mr Cheeky" quips "I'm Brian of Nazareth".

Brian, incensed shouts that he's Brian, to which everyone starts joining in, "I'm Brian!"

One man, whose wife is also being crucified says "I'm Brian, and so's my wife!"

I'll not completely spoil the rest if you haven't seen it. But you should.

#14 matthew180 OFFLINE  

matthew180

    Stargunner

  • 1,242 posts
  • Location:Marshall, Michigan

Posted Wed Sep 28, 2011 6:56 AM

View PostWillsy, on Wed Sep 28, 2011 1:49 AM, said:

Still, the ED/AS manual goes 'round the houses as usual instead of just damn spelling it out!

You know, the datasheet is not *that* hard to understand. ;-) It is very clear, concise, and *short*! I don't think I have looked in the E/A manual since I got the datasheet. Give it a try, you might like it.

#15 Willsy OFFLINE  

Willsy

    Dragonstomper

  • 765 posts
  • Location:Uzbekistan (no, really!)

Posted Wed Sep 28, 2011 7:06 AM

View PostFishsta, on Wed Sep 28, 2011 5:50 AM, said:

I would hazard a guess at Monty Python's Life of Brian.

In a Spartacus kind of situation, the people set to be crucified on the crosses are asked who is Brian of Nazareth for a reprieve. Brian is too busy shouting at his friends who have left him to die, so "Mr Cheeky" quips "I'm Brian of Nazareth".

Brian, incensed shouts that he's Brian, to which everyone starts joining in, "I'm Brian!"

One man, whose wife is also being crucified says "I'm Brian, and so's my wife!"

I'll not completely spoil the rest if you haven't seen it. But you should.

You are correct sir.

(In a stupid French accent)

"And now, I will change my sig-a-na-ture one more time!"




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users