6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Sep 25, 2024 7:30 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Jun 17, 2017 6:07 pm 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I was wondering if there is a loosely agreed upon "best practice" for when to use a particular number base when coding in 6502 (among other) assembly.

I basically ind myself using hex for everything. For instance, I would never use anything but base 10 for loop indexing in C (seems silly to even consider otherwise), yet in assembly I use hex. In fact I never use base ten anywhere. Just sort became a habit that came from who knows where. I do use binary when specific bits are being dealt with (same as I do in C).

Is there a kinda standard that folks use? Mostly just curious.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 17, 2017 6:37 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8517
Location: Southern California
Use whatever is most clear for the situation. For example, if you're ANDing out one or more particular bits, binary is most preferable. Next is hex if you really don't have room for binary, like when the line is getting too long. When there's an implication about the address decoding, you'll probably want hex—definitely not decimal! Use decimal in other situations where it's not particularly related to the machine. Even that's not an "always" case though, for example when handling angles and you represent the 360° circle with 0-$FFFF, and hex makes it clear which quadrant you're in, and the four quadrants start at 0, $4000, $8000, and $C000, nice round numbers.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 17, 2017 6:44 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
I think I tend to use hex too. It's an easy source of error to read 10 as $10, or vice versa. So consistency helps, and as Garth says, hex is natural for addresses and for many constants too. I don't use binary - I've used enough hex that I know what $80 means.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 17, 2017 7:51 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
Dan Moos wrote:
I was wondering if there is a loosely agreed upon "best practice" for when to use a particular number base when coding in 6502 (among other) assembly.

I basically ind myself using hex for everything. For instance, I would never use anything but base 10 for loop indexing in C (seems silly to even consider otherwise), yet in assembly I use hex. In fact I never use base ten anywhere. Just sort became a habit that came from who knows where. I do use binary when specific bits are being dealt with (same as I do in C).

Is there a kinda standard that folks use? Mostly just curious.

In most of my programs I use decimal for "values," such as the number of interrupts per second or the X-Y coordinates on the screen. I use binary for anything that involves bitwise manipulation, such as performing a Boolean operation,configuring device registers or extracting a flag from a bit field. I most often use hexadecimal when accessing memory or I/O devices is involved.

As Ed and Garth said, use what is most natural to you. As your 6502 assembly language skills improve you will develop a sixth sense for when each base is appropriate.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 17, 2017 9:29 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
I don't use binary notation at all. I use hexadecimal for addresses and bit masks. I use decimal for loop counters and their kin.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 18, 2017 5:30 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
barrym95838 wrote:
I don't use binary notation at all.

Whaddya got against all those ones and zeros? :roll:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 18, 2017 6:17 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
You can also do bit definitions in a symbolic way instead of defining them as binaries.

enable_bit equ 4
start_bit equ 0
some_IO_register equ $B000

LDA #(1<<enable_bit)|(1<<start_bit)
STA some_IO_register

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 18, 2017 6:29 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
BigDumbDinosaur wrote:
barrym95838 wrote:
I don't use binary notation at all.

Whaddya got against all those ones and zeros? :roll:

Too dang many of them. :) My brain can instantly translate hex to binary, and hex is easier to read and less typo-prone, at least for me.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 18, 2017 7:18 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
barrym95838 wrote:
BigDumbDinosaur wrote:
barrym95838 wrote:
I don't use binary notation at all.

Whaddya got against all those ones and zeros? :roll:

Too dang many of them. :)

I know what you mean. After a while, one one looks just like another one. :lol:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


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

All times are UTC


Who is online

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