|
HOW TO IMPLEMENT ''OR'' WITH ST6 |
or com a ;"a"register complement(the same as NOT on all bits of the byte)
ld x,a ;save "a" reg. in "x" reg.
ld a,b ;put in "a" the value of B
com a ;complements "a"
and a,x ;executes AND of
com a ;in "a" there is the OR of A and B
Exemple: SET 2,variable ;bit 2 of the variable is = 1
RES 0,variabile ;bit 0 of the variable is = 0
If No. is a register or a variable (with a value comprised between 0 and 7)
it is not possible to use directly:
To obtain this result use the following method:
The a register gives the number of the bit to be set, while the b variable indicates the byte in which the bit has to be set.
Set_ ld x,a ;in "x" the number of the bit to be set
ldi a,255 ;a = 11111111b
com a ;carry = 1 and a = 0
rcla rcl a ;move carry in the bit 0 and b7 in to carry
dec x ;count number of times
jrnz rcla ;with No. bit=5 you will have a = 00010000b
or com a ;a = 11101111b
ld x,a ;save "a" in "x"
ld a,b ;a = byte b where the bit 5 is to be set (ex: b=10001101b)
com a ;complement a = 01110010b
and a,x ;a = 01100010b
com a ;a = 10011101b
ld b,a ;in the byte "b" after the operation you will have b=10011101
The "a" register gives the number of the bit to be reset, while the "b" variable indicates the byte in which the bit has to be reset.
Res_ ld x,a ;in "x" the number of the bit to be reset
clr a ;carry = 0 and a=0
ldi a,255 ;a=11111111b
rcla rcl a ;move carry in the bit 0 and b7 in to carry
dec x ;cont namber of times
jrnz rcla ;with No. bit= 4 is a= 11110111b
ld x,a ;save "a" in "x"
ld a,b ;a = byte "b" where the bit 4 is to be reset (ex: b=10001101b)
and a,x ;a = 10000101b
ld b,a ;in the byte "b" after the operation you will have b= 10000101b