EASy68K  
It is currently Tue Jun 18, 2019 4:38 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Questions about CMP
PostPosted: Wed May 26, 2010 10:48 pm 
Offline

Joined: Wed May 26, 2010 10:29 pm
Posts: 2
Location: /dev/null
I am writing a simple memory test program that allows the user to input the starting address, ending address, and a test pattern.

The problem I am having is in testing whether the addresses the user entered are between $00002000 and $000FFFFF.

Code:
addr1      EQU   $00002000   *min start address
addr2      EQU   $000FFFFF   *max end address


I am currently doing the tests after the user has entered both addresses, and both addresses have been converted from ascii to hex.


Code:
addr_chk   CMP.L   #addr1,addr_st   *check if start addr is in range
      BGE   addr_chk1         *valid, go to next check
      MOVE.B   #0,D0      *print with newline
      LEA   msg0,A1         *get address of msg0
      MOVE.W   #msg0_ln,D1   *get length of msg0
      TRAP   #15            *output msg0         
      JMP   addr_prompt      *invalid, try again
      
addr_chk1   CMP.L   #addr2,addr_end   *check if end addr is in range
      BLE   addr_chk2   *valid, go to next check
      MOVE.B   #0,D0      *print with newline
      LEA   msg0,A1      *get address of msg0
      MOVE.W   #msg0_ln,D1   *get length of msg0
      TRAP   #15      *output msg0
      JMP   addr2_prompt   *invalid, try again




The first part, where I'm testing addr_st, works fine. However in the second section, where I'm testing addr_end, it branches to addr_chk2 whenever addr_end >= $80000000 ($79999999 works fine). Other than that it behaves normally, only branching to addr_chk2 when addr_end <= #addr2.

Both addr_st and addr_end are correct in memory, and both have a buffer of one null byte before and after them.

Any ideas??


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2010 12:43 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Quote:
However in the second section, where I'm testing addr_end, it branches to addr_chk2 whenever addr_end >= $80000000 ($79999999 works fine).

Welcome to the world of signed vs. unsigned values.

Because the highest bit of an address >= $80000000 is set it it interpreted as being a negative value when doing a signed compare so it will always be smaller than a value without this bit set.

Here is a table of signed and unsigned branches ..

Code:
      CMP.x    <src>,<dst>      * Relationship    Signed    Unsigned
      Bcc      addr             * ------------    ------    --------
                                * <dst> <  <src>   BLT       BCS
                                * <dst> <= <src>   BLE       BLS
                                * <dst> =  <src>   BEQ       BEQ
                                * <dst> <> <src>   BNE       BNE
                                * <dst> >  <src>   BGT       BHI
                                * <dst> >= <src>   BGE       BCC

Lee.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2010 6:01 pm 
Offline

Joined: Wed May 26, 2010 10:29 pm
Posts: 2
Location: /dev/null
It works! Thanks =)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group