BIT assignments in HCS08 assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BIT assignments in HCS08 assembly

2,801 Views
baddad
Contributor I
I need to assign a name to each bit in a byte variable.  I know how to do this in "C", but what about HC08 assembly?
 
ie,
 
Flags (variable byte)
flagbit0
flagbit1
flagbit2
.
.
flagbit7
 
Any suggestions would be greatly appreciated.
 
Thanks,
Brian
Labels (1)
0 Kudos
4 Replies

413 Views
rocco
Senior Contributor II
Hi, Brian:

In assembler, you sonetimes need the bit-number and you sometimes need a bit-mask. So I always define both. Here is an example from one of my source files:
;
; Definitions of Host-Bus Control and Status registers in the FPGA.
;
;
ELMO:        equ    $8        ;Control and Status register for Motor Amplifier and DSP
;
;
; The ELMO and DSP status register bit definitions:
;
DSPtio:      equ    7         ;ELMO status: DSP Timer TIO status bit
DSPlock:     equ    6         ;ELMO status: DSP PLL LOCK status bit
DSPhack:     equ    5         ;ELMO status: DSP Host Acknowledge (~HACK)
DSPhreq:     equ    4         ;ELMO status: DSP Host Request (~HREQ)
ElmoAOK:     equ    3         ;ELMO status: amplifier status bit AOK
ElmoSO1:     equ    2         ;ELMO status: amplifier status bit SO1
ElmoSO2:     equ    1         ;ELMO status: amplifier status bit SO2
ElmoSO3:     equ    0         ;ELMO status: amplifier status bit SO3
;
;
DSPtio_m:    equ    %10000000 ;ELMO status: DSP Timer TIO status mask
DSPlock_m:   equ    %01000000 ;ELMO status: DSP PLL LOCK status mask
DSPhack_m:   equ    %00100000 ;ELMO status: DSP Host Acknowledge (~HACK) mask
DSPhreq_m:   equ    %00010000 ;ELMO status: DSP Host Request (~HREQ) mask
;
AmpOK_m:     equ    $07       ;Elmo code for "Amplifier OK"
;
;

The bit numbers (0 through 7) are used in BSET, BCLR, BRSET and BRCLR instructions, and the masks are used in the arithmetic and logical instructions, like AND, EOR, BIT and ORA.

An example of clearing a bit would be:
        bclr    DSPtio,ELMO     ;clear the timer flag

I always use a "_m" on the mask, so that I can have macros append it automatically, and just use the name without the "_m" in the macro call.
0 Kudos

413 Views
bigmac
Specialist III
Hello,
 
Here is a slightly different way of defining the mask values - shown for CW assembler.
 
DSPtio_m:    equ    1<<DSPtio   ; ELMO status: DSP Timer TIO status mask
DSPlock_m:   equ    1<<DSPlock  ; ELMO status: DSP PLL LOCK status mask
DSPhack_m:   equ    1<<DSPhack  ; ELMO status: DSP Host Acknowledge (~HACK) mask
DSPhreq_m:   equ    1<<DSPhreq  ; ELMO status: DSP Host Request (~HREQ) mask


rocco wrote:
 

I always use a "_m" on the mask, so that I can have macros append it automatically, and just use the name without the "_m" in the macro call.

Rocco, would you please give an example of what you mean.
 
Regards,
Mac

 
0 Kudos

413 Views
rocco
Senior Contributor II

bigmac wrote:
Here is a slightly different way of defining the mask values - shown for CW assembler.
Thanks, Mac, I like that. I may have to stay up all night changing 400 source files to that syntax. :smileywink:

My programming is very macro-centric (is that a word?). I use them to build tables, define new instructions, or just to amuse myself. My entire I2C library is built on macros.

One application for the "_m" that I mentioned is to circumvent the problem that BSET and BCLR only work on page-zero locations. So here are some home-rolled versions, that work anywhere in memory:
;
; Macros for Bitset and Bitclr outside of page zero
;
; Syntax:     BitClr   bitname,location
;
BitSet:  macro
           lda     #\1_m
           ora     \2
           sta     \2
         endm
;
;
BitClr:  macro
           lda     #~\1_m
           and     \2
           sta     \2
         endm
;
;
Appending the "_m" to the macro-parameter allows me to call out the bit, but the instruction uses the mask. From what I learned today, I could now do it that way (which I tried to post, but the shift operation gave me HTML errors).
0 Kudos

413 Views
bigmac
Specialist III
Hello Rocco,
 
I would never have thought of appending text to a macro variable to change the variable name.  Presumably prepended text would also work - I have previously used mVAR notation to signify a mask value.
 
However, I tend not to use pre-defined mask variables very often because I can generate them "on the fly", using the shift operator, when required.  I, like you, also tend to use plenty of macros, to make my code more readable, and where use of a sub-routine would be quite inefficient.
 
I had done a similar thing to you, for manipulation of single bits, but had restricted the manipulation to the accumulator (see the attached file).
 
Regards,
Mac
 

Message Edited by bigmac on 2006-09-09 01:44 AM

0 Kudos