signed vs unsigned naming conventions

All aspects of programming on the Commander X16.
Post Reply
encw
Posts: 25
Joined: Sat Oct 28, 2023 7:06 am

signed vs unsigned naming conventions

Post by encw »

So, I'm new to the 65C02 scene, and I'm writing some procedures in assembly.

When a procedure has both a signed integer and unsigned integer version, is it idiomatic in the 65C02 or X16 communities to prefer one over the other in naming?

One procedure I'm writing is itop_8 (8-bit integer to petscii). Should I prefer for example itop_8 and sitop_8, or itop_8 and uitop_8? Should I label both of them?

Thoughts?
DragWx
Posts: 345
Joined: Tue Mar 07, 2023 9:07 pm

Re: signed vs unsigned naming conventions

Post by DragWx »

This is going to vary from person to person.

My personal notation is "u8" for unsigned byte, "s8" for signed byte, and then u16, s16, etc, so something like "itop_u8", "itop_s8".
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: signed vs unsigned naming conventions

Post by TomXP411 »

Generally speaking, the industry seems to expect signed numbers as "normal" and unsigned as the exception.

Consider C++, the cornerstone of the software industry: the standard int type is a signed, 16-bit or 32-bit number (depending on your CPU's word size.) You have to explicitly ask for it if you want an unsigned int.

In c#: int is signed, and you have to use the uint type if you want unsigned.

In Java: int is signed, and you have to use special functions to do unsigned math.

Based on these examples, I'd suggest: itop_8 for signed numbers and uitop_8 for unsigned.

As a side note: are you rolling your own algorithm for that, or are you using Butterfield's solution that leverages decimal mode?
encw
Posts: 25
Joined: Sat Oct 28, 2023 7:06 am

Re: signed vs unsigned naming conventions

Post by encw »

I'm using my own, but I figured I'd use decimal mode too. I haven't seen his, but mine is likely extremely similar.

I like to try my own hand at doing something before checking google to see what the widely accepted algorithm is. It's much more fun that way. I find once I look at a problem one way, it is harder to think about it in a completely different way. Not impossible, but harder.

Because this is all written in assembly language I think I might go with labeling both.

Having a lot of fun learning 6502 assembly and the CX16! It's a great system to explore and have fun with.

Thank you both for the help.
Post Reply