Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Good Style: Register Names in Assembly?

Status
Not open for further replies.

jpanhalt

Well-Known Member
Most Helpful Member
Over the past several months, I have developed several subroutines for such operations as 32-bit by 16-bit division and 17-bit BIN2BCD. Each routine stood alone with its own register labels. For example, the division routine used T0..T3 for the dividend, B0..B3 for the divisor, and R0..R3 for the quotient. Similarly, the BIN2BCD used binU, binH, binL, ones, tens, hund, thou, and tenK. As I integrate those routines into a larger program the number of labels grows. Within each individual subroutine, the label has meaning and improves readability; however, a lot of registers get used that could be reused, but aren't. Most important, Common RAM is quickly exhausted and using General Purpose RAM means more bank shifting.

1) As one option, I could simply use generic labels, such a reg1, reg2, etc. and modify all of the subroutines.
2) As another option, I could keep my descriptive names and re-assign those names to registers in Common RAM (if desirable) using the #define directive.

I understand that reusing registers can be a problem if a register is used in another routine and its value changes as a result of a subroutine.

Assuming I carefully avoid such "re-entry" problems, is there a widely accepted good style for naming such registers?

John

Language= MPASM
Chip= 16F1829
IDE= MPLab 8.92
 
Now that I have had lunch and gotten away form the question, here's what I plan to do:

1) For labels/register names for which banking is an issue, I will retain the descriptive names and use the #define directive and an include file ultimately to handle the changes in Common RAM.
2) Where that is not an issue, I will just use General Purpose RAM.

John
 
As my library of math routines has grown, I've standardized on a common set of registers:
- ACC0 through ACC7 for "accumulator" which holds one operand and the final result of the operation.
- R0 through R7 which holds the second operand of the operation.
I originally started with two registers per operand, then expanded to 4 and then finally 8, as the need increased to handle larger numbers and/or increased precision.
 
To add to the standardization of ACC0 to ACC7 , etc.... You can treat them as reserved variables, and assign an Alias name to them within the actual function so that they are more "human readable"
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top