English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 05 May 2020, 06:12   #1
pushead
Registered User

 
Join Date: May 2019
Location: Norway
Posts: 14
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?
pushead is offline  
Old 05 May 2020, 08:07   #2
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
That's because $ff is seen as 255, not -1.
If you write moveq #$ffffffff,d7 then it will work.
meynaf is online now  
Old 05 May 2020, 13:17   #3
Auscoder
Registered User

 
Join Date: Jan 2019
Location: Brisbane
Posts: 70
Quote:
Originally Posted by meynaf View Post
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!
Auscoder is offline  
Old 05 May 2020, 19:34   #4
pushead
Registered User

 
Join Date: May 2019
Location: Norway
Posts: 14
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!
pushead is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Probably a newbie Question... balric support.WinUAE 1 10 May 2017 19:45
newbie hd question turrican3 support.FS-UAE 2 13 March 2014 17:54
Newbie question Mart support.WinUAE 10 15 December 2006 11:24
Newbie Question immodium New to Emulation or Amiga scene 1 03 November 2005 16:24
is this a newbie question? deadduck New to Emulation or Amiga scene 11 27 November 2001 18:17

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:25.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.06248 seconds with 12 queries