6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 7:35 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: 6502 overflow question
PostPosted: Wed Aug 13, 2003 10:49 pm 
Offline

Joined: Wed Aug 13, 2003 10:41 pm
Posts: 1
I have a doubt about overflow.
When can we say there is an overflow?
I think there is one when a number dont fit in a 8bit register.
I mean:

lda #$FA
adc #$30

is there an overflow in that situation?

maybe this could be a fooly question but i dont know


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 14, 2003 2:46 pm 
Offline

Joined: Wed Sep 04, 2002 4:08 pm
Posts: 57
Location: Iowa
This is indeed a type of "overflow" but you must be careful about your terminology. If you have an 8-bit data type to receive your result, it is considered an overflow. If you are adding two 16-bits and during the first 8 bits you get an "overflow" it's actually referred to as a carry. When adding, the 6502 always sets the C flag on an overflow.

Subtraction is a little different. A borrow is represented (in the 6502) by a cleared C flag. If you're subtracting two 16-bit numbers and the lower 8 bits requires a borrow, the C flag will be cleared and the value 1 will be subtracted from the upper 8 bits. However, if you're subtracting two 8-bit numbers and the result is incorrect because it can't be represented by an 8 bit, then that is considered an overflow. For example, -100 - 100 will end up being +72 because -200 cannot fit in 8-bits. The 6502 detects the sign discrepancy of this operation and flags it as an overflow in the V flag.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Aug 15, 2003 2:25 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
The overflow flag tells if the sign bit of the result is wrong. You'll see the earlier discussion on this if you down, under "General Discussions", down to "Carry and Overflow flags..." The URL seems to be:
http://www.6502.org/forum/viewtopic.php?t=62
Welcome to the forum.

Garth


Top
 Profile  
Reply with quote  
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 7 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: