Motorola Axiom CMD11E1 Guide de l'utilisateur Page 34

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 101
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 33
34 CHAPTER 3. FUNCTIONS AND BIT MANIPULATIONS
the registers the way they were before the functions used them
1
.
Here are the basic rules for writing functions
1. Decide on its functionality. Don’t try to create a Swiss army knife that has
multiple functionalities built in. Your function must do only one thing, and
it must do it well. Your documentation for the function must clearly state
the functionality
2. Decide on its name. Pick a meaningful name but keep the name to 8 char-
acters or less
3. Decide on the registers that will be used to pass information to the function.
8-bit values can be sent using A or B registers. 16-bit values can be sent
using X or Y registers
2
.
4. Decide what registers will be used to return values back to the caller. 8-bit
values can be returned using A or B registers. 16-bit values can be returned
using X or Y registers.
5. Decide what registers the function will use and which of these will be restored
back at the end. Clearly document which registers will be used and not
restored back as the registers that are modified by the function.
6. Write the function. Avoid the temptation of writing the function first and
then worrying about the other items!
As an example, we will write a simple function called RAND that will return a
random value every time it is called. How does this function work? The function
starts with a seed. We use an 8-bit number as a seed. The seed is used to calculate
a random number using some formula. To make sure we get a different number
every time the function is called, the seed value is changed. Typically, the random
number that is generated is used as the seed for the next random number. Thus,
we are actually generating a random sequence starting with some initial seed. The
formula
3
it uses is simple: It shifts the seed value left, and adds with carry the
value 20. The function needs one byte of storage to keep track of the seed. This
storage will be allocated in the data section using the FCB directive as
SEED FCB 0
1
The only exception is the register that is used to return a value to the user. Clearly, these
registers should not be restored to their original value!
2
For example, OUTA expects the data in theA register, while OUT1BYT expects the information
in the X register.
3
I use this as a quick and dirty 8 bit random number generator. It is not the best, but the
code is only 5 line long!
Vue de la page 33
1 2 ... 29 30 31 32 33 34 35 36 37 38 39 ... 100 101

Commentaires sur ces manuels

Pas de commentaire