Author Topic: How do you test for NC?  (Read 366 times)

0 Members and 1 Guest are viewing this topic.

Offline IndyUK

  • CPC464
  • **
  • Posts: 15
  • Country: gb
  • Liked: 0
  • Likes Given: 1
How do you test for NC?
« on: 23:48, 01 July 20 »
Hi Folks

I need a little help please. I'm converting my current sprite routine to use the Stack to plot to the screen. That's kind of working fine but, I do have a problem. I use a bit of code to test if one of my inner loops has reached the end of the scanline. This is so I can check if I need to proceed to the next scanline (in this case previous because we're working in reverse due to using the Stack) of the sprite. This approach worked absolutely perfectly with my non-Stack version, however, when I try and use the following in the new version, the logic check never seems to work. Here's the code I'm using;

Code: [Select]
xor a          ;this block checks to see if we have reached the end of the scanline
ld a,40       ;load value 40 into A
sub c         ;deduct A from the C register (contains the current width count)
jr nc,skip   ;if no-carry occurs, then the number in C was wholly divisible by 40, meaning we reached the end of the scanline

Using the inbuilt debugger in WinApe I can see the NC flag does get set (11 under NC) but, my jump never works. Because this never fires the plotting is garbled. I don't know if it's my code that isn't correct or my lack of knowledge of how the NC flag should be interpreted. I would appreciate any help.

Thanks

Offline dthrone

  • CPC6128
  • ****
  • Posts: 203
  • Country: gb
    • SOHDE
  • Liked: 148
  • Likes Given: 208
Re: How do you test for NC?
« Reply #1 on: 02:25, 02 July 20 »
One thing to note is that sub c deducts C from the A register not vice versa unless it's just your comments that are incorrect  ;)

Offline Axelay

  • 6128 Plus
  • ******
  • Posts: 585
  • Country: au
  • Liked: 383
  • Likes Given: 87
Re: How do you test for NC?
« Reply #2 on: 15:57, 02 July 20 »
In addition to what dthrone mentioned, also note that 'NC' in the flags indicator in the Winape debugger is not 'No Carry'.


The 'N' is the add/subtract flag (set to 1 if the previous operation was a subtract).


The 'C' is the carry flag.  Carry is set to 1 if there is overflow from the last instruction to affect the flag, so where you are seeing a 1 in the carry flag, carry is set, and so a test for NC will be false.  It will not make your NC jump unless you see a 0 in the carry flag.

Offline IndyUK

  • CPC464
  • **
  • Posts: 15
  • Country: gb
  • Liked: 0
  • Likes Given: 1
Re: How do you test for NC?
« Reply #3 on: 18:47, 02 July 20 »
Hi Guys,

I would like to thank both of you.

One thing to note is that sub c deducts C from the A register not vice versa unless it's just your comments that are incorrect  ;)
You were absolutely right, I had thought that A was being deducted from C. Thanks for claifying this

In addition to what dthrone mentioned, also note that 'NC' in the flags indicator in the Winape debugger is not 'No Carry'.


The 'N' is the add/subtract flag (set to 1 if the previous operation was a subtract).


The 'C' is the carry flag.  Carry is set to 1 if there is overflow from the last instruction to affect the flag, so where you are seeing a 1 in the carry flag, carry is set, and so a test for NC will be false.  It will not make your NC jump unless you see a 0 in the carry flag.
Thanks for clearing this up for me. I always struggled with getting my head around this because I always assumed the labels NC were working in tandem. Hopefully I can now go back to my code and get it working.


Once again, thanks for helping.