Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/03/09 18:06
Read: times


 
#168725 - Code: Addressing bit memory indirectly
Responding to: ???'s previous message
;********************** set bit indirect pointed by acc *****************
;Attention: bit address must be below 80h !
;Input: ACC = bit number 00 ... 7F
;Output: nothing
;Used: R0, ACC
;Cycle: 16
setibit:
        call getibit            ;get mask and address
        orl a, @r0
        mov @r0, a
        ret

clribit:
        call getibit
        cpl a
        anl a, @r0
        mov @r0, a
        ret

cplibit:
        call getibit
        xrl a, @r0
        mov @r0, a
        ret

tstibit:
        call getibit
        anl a, @r0
        add a, #0FFh
        ret

getibit:                        ;get byte address and bit mask
        mov r0, a
        anl a, #78h             ;byte number
        rl a                    ; * 2
        swap a                  ;     / 16  = / 8
        add a, #20h             ;start data bit addressable
        xch a, r0
        anl a, #7               ;bit number
        inc a
        movc a, @a+pc           ;bit mask
        ret
        db 1, 2, 4, 8, 10h, 20h, 40h, 80h
;------------------------------------------------------------------------

 


And following the same in C:


/************************************************************************/
/*									*/
/*			Bit Pointer Implementation			*/
/*									*/
/*			SFR bits can not be accessed !			*/
/*									*/
/*		Author: Peter Dannegger					*/
/*									*/
/************************************************************************/
#pragma cd

typedef unsigned char uchar;
typedef unsigned int uint;


#define	BIT_START	0x20


static uint getibit( uchar bitptr )
{
  uchar code bitmask[] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
  return (uint)bitmask[bitptr & 7] << 8 |	// high byte = bit mask
	 (uchar) (bitptr / 8 + BIT_START);	// low  byte = byte address
}


void setibit( uchar bitptr )			// *bitptr = 1;
{
  uint mask_addr = getibit( bitptr );
  *(uchar idata *)mask_addr |= mask_addr >> 8;
}


void clribit( uchar bitptr )			// *bitptr = 0;
{
  uint mask_addr = getibit( bitptr );
  *(uchar idata *)mask_addr &= ~(mask_addr >> 8);
}


void cplibit( uchar bitptr )			// *bitptr ^= 1;
{
  uint mask_addr = getibit( bitptr );
  *(uchar idata *)mask_addr ^= mask_addr >> 8;
}


void movibit( uchar bitptr, bit inbit )		// *bitptr = inbit;
{
  inbit ? setibit( bitptr ) : clribit( bitptr );
}


bit tstibit( uchar bitptr )			// return *bitptr;
{
  uint mask_addr = getibit( bitptr );
  return *(uchar idata *)mask_addr & mask_addr >> 8;
}

 



Peter


List of 23 messages in thread
TopicAuthorDate
Addressing bit memory indirectly            01/01/70 00:00      
   Not possible.            01/01/70 00:00      
      so why Bit addressable memory?            01/01/70 00:00      
         sure you can and THINK            01/01/70 00:00      
            Fast and saves code and RAM space            01/01/70 00:00      
   No such instruction...            01/01/70 00:00      
      Thanks so much            01/01/70 00:00      
         That's _too_ limited...            01/01/70 00:00      
      Not vast - actually quite small.            01/01/70 00:00      
   bible time            01/01/70 00:00      
   store bit address...            01/01/70 00:00      
      Thanks            01/01/70 00:00      
         if '2051' is the Atmel, then            01/01/70 00:00      
            "cable" only for the "S"            01/01/70 00:00      
               I second the motion and add            01/01/70 00:00      
               I have...            01/01/70 00:00      
                  Smoking bad for the health            01/01/70 00:00      
                  an issue many newbies are not aware of is ...            01/01/70 00:00      
                     NXP???            01/01/70 00:00      
                        Design flaw?            01/01/70 00:00      
                           a feature            01/01/70 00:00      
                  cheap            01/01/70 00:00      
   Code: Addressing bit memory indirectly            01/01/70 00:00      

Back to Subject List