A83: Bit tutorial...


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

A83: Bit tutorial...




Here's my tutorial on bit level instructions.

James.

------
Introduction.
Those of you familiar with C++ know about the >>, <<, &, ~ etc. commands. 
These are referred to as bit-level instructions.  Those of you not familiar
with C++ — bit-level operators change numbers by changing the binary
equivalents.

SLA, SRA.
Check this out…
Given:

00000001	= 1
Shift all bits left:
	00000010	= 2
Shift all bits left:
	00000100	= 4
Shift all bits left:
	00001000	= 8
Shift all bits left:
	00010000	= 16

Notice a pattern?  Yes, by shifting the bits left, you double the number! 
As you can imagine, the opposite is also true, if you shift to the right,
you half the number (
somewhat).  The instructions that do this operation are called SLA and SRA
— Shift Left/Right Arimetric.

RLC,RRC.

The only difference with these guys is that they are circular.  In SLA and
SRA, the bit are merely shifted, with a 0 added to the appropriate side…RLC
and RRC actually takes the first bit and moves it to the last, or vice
versa.  Here's an example for try to clarify this:

SLA:		RLC:
01001000	01001000
10010000	10010000
00100000	00100001
01000000	01000010
10000000	10000100
00000000	00001001


RLC/RRC stand for Rotate Left/Right Circular.

CPL

This is merely returns the complement of the acc…if you have ld
a,%01010101, then cpl, will return 10101010 in the acc.

Conclusion.

Bit level instructions can be a lot quicker than rom calls, or alternative
methods, thus use them when you can!

 Related Topics.

All tutorials Copyright (c) James Matthews 1998, unless specified.