Shop OBEX P1 Docs P2 Docs Learn Events
SETB problem — Parallax Forums

SETB problem

Sens-a-DatSens-a-Dat Posts: 44
edited 2008-02-27 14:51 in General Discussion
Gents,

I am trying to use a variable to help me set select bits within another variable. The bits set will vary, and thus the desire to use a variable. What I think should work does not. So, I know I must not be understanding something. Can someone help me on this?

Here is an example code to illustrate how I am trying to manipulate bits in TestByte by using the variable BitLocation as a bit positioner. The counter will go from 7 to 0, so that all bits will be set for this example.

I am using the SXSim to monitor the process. The BitLocation does get smaller, but the use of it in the SETB command is not reflected.

DEVICE SX28, TURBO, STACKX, OSC4MHZ
IRC_CAL IRC_4MHZ
FREQ 4_000_000


RESET   Start

;************************ Program Variables *****************************

org     $08                          ;First register address in main memory
                                     ;bank
TestByte        ds      1            ;Temporary storage
BitLocation     ds      1            ;Bit location within TestByte


org $100
Start
break

mov BitLocation,#$07           ;location of bit to be set in TestByte
mov TestByte,#$00              ;Initial value = 0

Main
    SETB TestByte.BitLocation
    DEC BitLocation
JMP Main

Comments

  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-02-27 05:52
    I don't think you can ue a variable to do that -- you need to convert the bit position to a mask and then OR the two values together.
  • BeanBean Posts: 8,129
    edited 2008-02-27 13:40
    Jon is correct. The bit position must be a constant when using the SETB instruction.

    Here is how I would do it using a mask value and "OR":

    DEVICE SX28, TURBO, STACKX, OPTIONX, OSC4MHZ
    IRC_CAL IRC_4MHZ
    FREQ 4_000_000
    
    
    RESET   Start
    
    ;************************ Program Variables *****************************
    
    ORG     $08                          ;First register address in main memory
                                         ;bank
    testByte        ds      1            ;Temporary storage
    bitLocation     ds      1            ;Bit location within TestByte
    
    
    ORG $100
    Start:
    BREAK
    
    MOV bitLocation,#$80           ; mask value of bit to be set in TestByte
    MOV testByte,#$00              ; Initial value = 0
    
    CLC                            ; clear carry so we shift a zero on the first shift
     
    Main:
    
      OR TestByte,BitLocation      ; Set the bit
      RR BitLocation               ; Adjust so next bit is a "1"
    JNC Main                       ; Quit when the "1" bit gets shifted out to the carry bit
     
    JMP $                          ; Stop here
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 2/27/2008 1:45:38 PM GMT
  • Sens-a-DatSens-a-Dat Posts: 44
    edited 2008-02-27 14:51
    Thank you, Bean. Your code helped me in better understanding how to look at and consider things.
Sign In or Register to comment.