6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 11:53 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Dec 03, 2010 8:35 am 
Offline
User avatar

Joined: Fri Dec 12, 2003 7:22 am
Posts: 259
Location: Heerlen, NL
Hallo allemaal,


I don't know who copied my test program for the 6502 but I found a huge bug in it. Please have a look at the following example:
Code:
          ldx  #0
L039i
          bne  L039i   ; error, ->
L039j
          bmi  L039j   ; error, ->

It looks as if the program tests if X is loaded with the value zero. Coincidentally I saw an error in the core: in this specific case X would never be loaded with the read value. So I wondered how RB65 could pass the test ???
Studying the above piece of code and the core I realised that the ALU tested the loaded value, not what was stored in X. To test the actual value in X I have to add the instruction "CPX #0". I did and now the program ended with an error.

After correcting the error, the program ended well. But knowing now that my program certainly isn't as good as I thought, I wonder if my VHDL is OK. Back to the drawing board..... :(

_________________
Code:
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: www.baltissen.org



Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 03, 2010 9:22 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
I'm confused: that doesn't look wrong to me. Did you mean
Code:
  LDX $0
which loads from zero page, or did you really mean
Code:
  LDX #0
which loads the constant value zero, and does indeed update the flags?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 03, 2010 1:09 pm 
Offline
User avatar

Joined: Fri Dec 12, 2003 7:22 am
Posts: 259
Location: Heerlen, NL
BigEd wrote:
.. or did you really mean
Code:
  LDX #0

In reality it was the "LDX $nn,Y" instruction that went wrong. I just used the immediate instruction as example.
During LDx instructions the ALU is loaded with the read value as well because I need to (re)set the Zero and Negative flag. The ALU saw a Zero, set the Zero flag etc. and the branches were not taken (=no error in this case). But in this particular case X wasn't loaded with the value. I only found out that there was an error by adding the CPX instruction.

The core of the message was that just checking the Flags is not sufficient some times.

_________________
Code:
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: www.baltissen.org



Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 03, 2010 2:29 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Ah, I see! Sorry, I could have read the post more carefully.

It's an interesting aspect of test programs - to some extent you're operating with a model of what might go wrong. Most 6502 tests wouldn't bother to check that a LDX left Y unchanged, say, or that a TXA hadn't ORed in some other register. But these bugs could arise in a homebrew.

(And then there's the extra problem of self checking code, when you wouldn't want one bug to mask out another.)

Cheers
Ed


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 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: