Re: A85: Accessing bits


[Prev][Next][Index][Thread]

Re: A85: Accessing bits




At 15:17 1998-05-12 -0400, you wrote:
>
>Thanks.  Could you explain what this is doing exactly?  I'd like to know
>how this stuff works when I implement it into my game.

Sure

>> ld a,(SomeByte)
>> ld hl,split
>> ld b,4
>>SplitByte:
>> rlca
>> rlca
>> push af
>> and 3
>> ld (hl),a
>> inc hl
>> pop af
>> djnz SplitByte

Assume (SomeByte)=%10011100:

A=10011100  => RLCA \ RLCA => A = 01110010    (rotate left two times)

'and 3' masks away all bits except the first two, so A = 00000010, which
is stored at (HL), and then HL is increased.
The next steps in the loop:

A=01110010  => RLCA \ RLCA => A = 11001001  => AND 3  =>  A = 00000001

A=11001001  => RLCA \ RLCA => A = 00100111  => AND 3  =>  A = 00000011

A=00100111  => RLCA \ RLCA => A = 10011100  => AND 3  =>  A = 00000000

--
Real name: Jimmy Mårdell                "can't go mucking with a 'void *'"
IRC......: Yarin                                // Apple's MPW C compiler
Email....: mailto:yarin@acc.umu.se        
Homepage.: http://www.algonet.se/~mja/


References: