It is currently Thu Dec 13, 2018 9:53 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 347 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24  Next
Author Message
PostPosted: Wed Oct 03, 2018 5:13 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11012
Location: Rio de Janeiro - Brazil
All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:25 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
tokumaru wrote:
All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.



The answer on this one? Or the answer about what I wrote earlier before the questioned about signed/unsigned numbers?

So it's like a mirror-mirror style of positive and negative where...............

255 is positive [unsigned]

and 1 is negative [signed]

-

251 is positive [unsigned]

and 5 is negative [signed]

-

190 is positive [unsigned]

and 64 is negative [signed]

255
-65
---
190


?????

I would see the pattern if that's correct..? Which is why BCC and BCS / BPL and BMI exists?


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:28 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20870
Location: NE Indiana, USA (NTSC)
In two's complement, 0 through 127 ($00 through $7F) are positive, and 128 through 255 ($80 through $FF) are treated as negative. They represent -128 through -1. All the positive numbers have bit 7 clear (0), and all the negative numbers have bit 7 set (1). This is why BPL (branch if plus) jumps if the last result had bit 7 clear, and BPL (branch if minus) jumps if the last result had bit 7 set.

BCC and BCS are used if you're comparing two unsigned numbers, and BPL and BMI are used if you're comparing two signed numbers. You also use BPL in a loop that counts down to 0 and stops once the index has passed zero:
Code:
  ldy #4
loop:
  ; Y will equal 4, then 3, then 2, then 1, then 0.
  ; Do something with Y each time (omitted).

  ; Now count down: 4 becomes 3, 3 becomes 2, ..., 0 becomes -1
  dey
  ; If Y hasn't become negative, stay in the loop
  bpl loop


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:32 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
tepples wrote:
In two's complement, 0-127 are positive, and 128-255 are treated as negative. They represent -128 through -1.


.......

But that's single.. what about what tokumaru wrote about that they're signed and unsigned at same time?

So in Tokumaru part, it's a mirror of positive and negative of +255 and -1, and it can go down into +3 and -253.

And in your part, it's two parts where 0-127 is positive lever, and 128-255 is negative lever, also known as -1 and -128..?

[Obviously[[?]], zero is a positive number.]


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:36 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20870
Location: NE Indiana, USA (NTSC)
The number $C0 can represent 192, or it can represent -64. The 6502 itself couldn't give a care. In practice, it depends on the context of the code around it. As an assembly language programmer, you are responsible for imbuing numbers with semantics, defining what each value means in context.

Zero is traditionally neither negative nor positive. But the BPL and BMI branches treat a zero result as nonnegative, as if it were positive. To treat zero differently from positive numbers proper, you'll need to use both a BNE or BEQ and a BPL or BMI. You'll need to do this, for example, to distinguish a stopped character from one moving to the right.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:39 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
tepples wrote:
The number $C0 can represent 192, or it can represent -64. The 6502 itself couldn't give a care. In practice, it depends on the context of the code around it. As an assembly language programmer, you are responsible for imbuing numbers with semantics, defining what each value means in context.

Zero is traditionally neither negative or positive. But the BPL and BMI branches treat a zero result as nonnegative, as if it were positive. To treat zero differently from positive numbers proper, you'll need to use both a BNE or BEQ and a BPL or BMI.


So there's an opcode where it let me define a numbers in favor for "Mirror-+" or "half -+" styles? Or what does 6502, in form if NES, support only?


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 5:43 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20870
Location: NE Indiana, USA (NTSC)
If you write lda #<-10, ca65 will treat that as a two's complement number and translate it into lda #246.

  1. The # means that lda will load an immediate value, as opposed to reading from a memory address.
  2. The < means "keep the low byte". An assembler on a 32-bit platform, such as a PC, will internally process all values as 32-bit values. In 32-bit two's complement, -10 is $FFFFFFF6, and the < operator tells the assembler to cut the value down to 8-bit.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 6:48 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
tepples wrote:
If you write lda #<-10, ca65 will treat that as a two's complement number and translate it into lda #246.

  1. The # means that lda will load an immediate value, as opposed to reading from a memory address.
  2. The < means "keep the low byte". An assembler on a 32-bit platform, such as a PC, will internally process all values as 32-bit values. In 32-bit two's complement, -10 is $FFFFFFF6, and the < operator tells the assembler to cut the value down to 8-bit.


...ca65 is part of Colecovision that Unregistered is part of, or the 6502?..

I'm starting to get confused on how it works, with your answer and Tokumaru answer.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 6:59 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20870
Location: NE Indiana, USA (NTSC)
ca65 is a 6502 assembler. It has nothing to do with Coleco.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 7:03 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
But what about the NESASM6 part? Or ca65 better choice?


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 7:27 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11012
Location: Rio de Janeiro - Brazil
There's no "NESASM6"... There's NESASM and ASM6, two separate assemblers. NESASM and ASM6 are much more newbie friendly, but ca65 has more features than both combined. Because NESASM has some weird quirks, I usually suggest ASM6 to beginners.

Keep in mind that any of them can be used to make any kind of NES game, the difference is that ca65 has some features that make larger projects easier to manage, if you know how to use said features.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 8:20 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 940
Location: cypress, texas
Note: I can't be part of Colecovision; I've never even touched a Colecovision. :lol:

DocWaluigean wrote:
tokumaru wrote:
All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.



The answer on this one? Or the answer about what I wrote earlier before the questioned about signed/unsigned numbers?

So it's like a mirror-mirror style of positive and negative where...............

255 is positive [unsigned]

and 1 is negative [signed]

-
Note: we will deal with #255 as the hardware (the 6502) sees it... in binary: #11111111b
11111111 is positive [unsigned]

and 11111111 is negative [signed]

because, like tepples said, bit7 is set and so the "signed" way of using 11111111 makes that represent a negative number (-1).

You can experiment with Windows 10's Calculator to better understand signed and unsigned. Open Calculator, click the three horizontal lines in the upper left, click "Programmer's Mode". Click on the QWORD until it reads BYTE. Click on BIN. Type or click 11111111. Notice that the signed decimal value, next to DEC, reads -1. Now click BYTE again and it will goto QWORD. Then click the C to clear the calculator. Next type or click 11111111 again. Now the value next to DEC will read 255 (that's the unsigned version of #11111111b).

Windows 10's Calculator's Programmer's Mode always switches the decimal version (next to DEC) to signed when the left most bit of the value is set. Have to go... sorry.


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 8:32 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
tokumaru wrote:
There's no "NESASM6"... There's NESASM and ASM6, two separate assemblers. NESASM and ASM6 are much more newbie friendly, but ca65 has more features than both combined. Because NESASM has some weird quirks, I usually suggest ASM6 to beginners.

Keep in mind that any of them can be used to make any kind of NES game, the difference is that ca65 has some features that make larger projects easier to manage, if you know how to use said features.


Ooooh. What features does ca65 have that ASM6 doesn't?


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 8:34 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
unregistered wrote:
Note: I can't be part of Colecovision; I've never even touched a Colecovision. :lol:

DocWaluigean wrote:
tokumaru wrote:
All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.



The answer on this one? Or the answer about what I wrote earlier before the questioned about signed/unsigned numbers?

So it's like a mirror-mirror style of positive and negative where...............

255 is positive [unsigned]

and 1 is negative [signed]

-
Note: we will deal with #255 as the hardware (the 6502) sees it... in binary: #11111111b
11111111 is positive [unsigned]

and 11111111 is negative [signed]

because, like tepples said, bit7 is set and so the "signed" way of using 11111111 makes that represent a negative number (-1).

You can experiment with Windows 10's Calculator to better understand signed and unsigned. Open Calculator, click the three horizontal lines in the upper left, click "Programmer's Mode". Click on the QWORD until it reads BYTE. Click on BIN. Type or click 11111111. Notice that the signed decimal value, next to DEC, reads -1. Now click BYTE again and it will goto QWORD. Then click the C to clear the calculator. Next type or click 11111111 again. Now the value next to DEC will read 255 (that's the unsigned version of #11111111b).

Windows 10's Calculator's Programmer's Mode always switches the decimal version (next to DEC) to signed when the left most bit of the value is set. Have to go... sorry.


It's alright.. I'm a little confused though.

So...

00000000 is unsigned

00100000 is unsigned

01000000 is signed

10000000 is signed

11000000 is signed

11010101 is signed

Is this what it means?...


Top
 Profile  
 
PostPosted: Wed Oct 03, 2018 8:39 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 152
I got to ask even extremely ridiculous question even if there's chance I got right or not so I can find and understand in the most simplest or elementary explanation even toddler can understand. Just a reminder if I said this before?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 347 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 2 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:  
Powered by phpBB® Forum Software © phpBB Group