SETB problem
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.
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
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 hereBean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
Post Edited (Bean (Hitt Consulting)) : 2/27/2008 1:45:38 PM GMT