View Single Post
Old Nov 30th, 2006, 11:38 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
What do you suppose a 'normal number input' is? Your system deals in binary. The keyboard could put out anything (but it will be binary). Your driver will no doubt put it in a common (but binary) representation. Whether your mechanism provides an integer or coded integer is unknown to me. Here's an example: your keyboard give you 0x31 when you press the '1' key. That happens to be an ASCII representation for the digit, 1, since the binary value, 1, is generally used for something else that isn't printable.

ASCII '1' = 0x31 = 00110001b. See those bits?

Perhaps, as The Dark mentions, your machine takes care of that and gives you the 00000001 directly, already converted. Less to do for you.

Two binary values, say 01011010 and 01100101, can be XORed, which produces a 1 in the position if one and only one 1 is present. Bits which are alike, therefore, will produce a zero in the position. Therefore, if you count the zeroes, you know how many bits are different. You can count the bits in several ways. One way would be to rotate through the carry bit and check the state of that bit. If you'd rather work with ones, just invert the value. If you make an AND mask with one bit set, and AND it with the value, the result will be zero if that bit is not present, non-zero if it is present. Then move the bit in the mask, test and count the next position. As I say, there are a number of ways. Get familiar with your instruction set.

EDIT. Sorry, this was posted before your most recent post. You will have to refer to your documentation to see if registers have some particularly specific purpose, or if they're general purpose.

A load immediate means the value to be loaded is directly in the instruction, not out in memory. Loading direct means you load directly from a particular memory address or other register. That address is contained in the instruction. An indirect means you find the address elsewhere, in another register, or possibly in memory.

Microprocessors of different kinds work in the same essential ways. Some have more powerful arithmetic or addressing methods, or more registers, or whatever. Again, you have to refer to the docs for the device you're using. A general purpose understanding of micros in general could be beneficial, however.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote