English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. Asm / Hardware (http://eab.abime.net/forumdisplay.php?f=112)
-   -   Newbie question: what is the difference between #-1 and #$ff? (http://eab.abime.net/showthread.php?t=102108)

pushead 05 May 2020 06:12

Newbie question: what is the difference between #-1 and #$ff?
 
Hi,

In the "Compute's Machine Language Programming" book it says:

moveq #$ff,d7 ; Move the value $FFFFFFFF (the sign-extended version of $FF) into data register D7.

This sounds like a smart way (and fast!) to set all the bits of a register.

But if I write this instruction in AsmOne I get an error message 'Out of range 8-bit'.

Now, if I instead write 'moveq #-1,d7' it works fine.

What is the difference between #$ff and #-1? And why does not moveq #ff,d7 work at all?

meynaf 05 May 2020 08:07

That's because $ff is seen as 255, not -1.
If you write moveq #$ffffffff,d7 then it will work.

Auscoder 05 May 2020 13:17

Quote:

Originally Posted by meynaf (Post 1397704)
That's because $ff is seen as 255, not -1.
If you write moveq #$ffffffff,d7 then it will work.

Because #$ff in as a long is positive (moveq == moveq.l faster but functionally equivalent to move.l)
#$ff as a word is still positive (move.w)
#$ff as a byte is negative (move.b)

#-1 is negative in any type (8/16/32 bits), sign extending to long it remains negative

You may be interested to try in the debugger

Code:

sub.l d0,d0 ; just clear
move.b #$ff,d0 ; negative - see N flag is set
ext.w d0 ; still negative - n flag is still set
ext.l d0 ; still negative .... n flag set

Code:

sub.l d0,d0 ; just clear
move.w #$ff,d0 ; positive - see N flag is not set
ext.l d0 ; still positive .. N flag is not set

#$ff is always 255. It can also be -1 in the case of a byte.

Try with -1 and see what happens. Hope this helps! seems Abacus has led you astray here!

pushead 05 May 2020 19:34

Thanks both of you!

Have been playing around with the samples in the debugger and it's getting clearer! Thanks!

It makes sense now - when I think of the moveq as a longword instruction which translates #$FF to 255 and not -1.

Still, I think the book is a bit unclear on this subject... Can I complain on a book written back in 1988, hehe!


All times are GMT +2. The time now is 00:42.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.

Page generated in 0.04203 seconds with 11 queries