Logo del sito i2viu

HOW TO IMPLEMENT ''OR'' WITH ST6
by Vittorio Crapella - i2viu

In the ST6 microcontroller instruction set ST6 the OR instruction is not supported.
The logical function of this instruction is the following:

which however can be traced back to the following:

In fact from the Bolean algebra it derives that U(or) = A + B is equivalent to
What above said is confirmed also by the truth table given below.

It derives that the OR function can be implemented by using the COM and AND instructions supported by the ST6

Therefore OR of A and B (where A and B can be registers or variables) will be:


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

SET/RESET THE BIT No. OF A BYTE

Where Nr. is a register or a variable.
The ST6 instruction SET supports the SET and RESET of No. bit, of the "a register" or "a variable" but only in the immediate mode, that is N has to be on EQU value or a value given in the software as a digit comprised between 0 and 7.

 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:

SET Register, Variable.

To obtain this result use the following method:

SET:

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

As you can notice, the bit No. 5 has been set while before the operation the bit was reset= 0.

RESET:

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

As you can notice, the bit No. 5 has been reset while before the operation the bit was set= 1.

XOR on the ST6       [ Ham Radio ] [Return]