Question about DEX/DEY/INY/INX opcodes
Moderator: Moderators
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Question about DEX/DEY/INY/INX opcodes
Hi all, I'm currently attempting to write an NES emulator through .NET and I have a question about the particular opcodes that do decrementing and incrementing...
Since X, and Y registers are 8 bits, is it an unsigned or signed byte? That is, is the value range of the X and Y registers from -128 to 127 or 0-255?
I am confused by this because if the X and Y registers are initialized as 0, what happens when a DEX is performed? Or is it up to the programmer to actually worry about that?
Thanks in advance for the help everyone.
Since X, and Y registers are 8 bits, is it an unsigned or signed byte? That is, is the value range of the X and Y registers from -128 to 127 or 0-255?
I am confused by this because if the X and Y registers are initialized as 0, what happens when a DEX is performed? Or is it up to the programmer to actually worry about that?
Thanks in advance for the help everyone.
Last edited by urbanspr1nter on Thu Aug 16, 2012 8:04 pm, edited 1 time in total.
Re: Question about DEX/DEY/INY/INX opcodes
Emus don't matter. It just subtracts one. It'll roll from 00000000 to 11111111.
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Re: Question about DEX/DEY/INY/INX opcodes
So In terms of implementation from what you're saying is it is fine to make it an unsigned byte? 0-255?
So if i were to do a DEX when X = 0, I can basically check first to see if X is already 0, then just reset it to 255?
So if i were to do a DEX when X = 0, I can basically check first to see if X is already 0, then just reset it to 255?
Re: Question about DEX/DEY/INY/INX opcodes
Sure, or you can just use an unsigned char and then it'd be the right size you need.
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Re: Question about DEX/DEY/INY/INX opcodes
Not an "unsigned char" in .NET, char is a 16-bit unicode character. "unsigned char" applies to regular C or C++, where bytes are called "char"s.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Re: Question about DEX/DEY/INY/INX opcodes
So then I'm assuming I could just leave it as a byte since by default in VB.NET bytes are unsigned.
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Re: Question about DEX/DEY/INY/INX opcodes
Also, could someone also verify my logic of thinking?
I was thinking about what 3gen said about value ranges not mattering in terms of implementation and I realized this is due to the fact that the we can read numbers as negative if the SIGN bit of the status register gets set?
I was thinking about what 3gen said about value ranges not mattering in terms of implementation and I realized this is due to the fact that the we can read numbers as negative if the SIGN bit of the status register gets set?
Re: Question about DEX/DEY/INY/INX opcodes
When represented in binary, signed and unsigned numbers are the same: 11111111 is both 255 and -1, it depends on what kind of math the program does with them and how the results are interpreted. The N flag (is this what you call the SIGN bit?) is just a copy of bit 7 of the last manipulated value, and can be used to tell whether it's negative because all negative numbers have this bit set. If the program isn't treating the number as signed, it will just ignore this flag (or use it for purposes other then identifying the sign). The overflow flag is also meant for signed numbers, while the carry can be used to test overflows and underflows of unsigned numbers.
-
- Posts: 39
- Joined: Thu Aug 16, 2012 7:55 pm
Re: Question about DEX/DEY/INY/INX opcodes
Thank you so much for this tokumaru. It is much clearer now.
Re: Question about DEX/DEY/INY/INX opcodes
Just think of all of the Registers (A, P, S, X, Y) as 8-bit unsigned char. For instance X will never be a minus number and when you emulate it's usage you just add it nothing else (so long as its defined as being unsigned).