The Art of Assembly Language
|
2.5 Arithmetic Operations on Binary and Hexadecimal Numbers
There are several operations we can perform on binary and hexadecimal numbers. For example, we can add, subtract, multiply, divide, and perform other arithmetic operations. Although you needn't become an expert at it, you should be able to, in a pinch, perform these operations manually using a piece of paper and a pencil. Having just said that you should be able to perform these operations manually, the correct way to perform such arithmetic operations is to have a calculator that does them for you. There are several such calculators on the market; following is a list.
Some manufacturers of hexadecimal calculators (in 2002):
-
Casio
-
Hewlett-Packard
-
Sharp
-
Texas Instruments
This list is by no means exhaustive. Other calculator manufacturers probably produce these devices as well. The Hewlett-Packard devices are arguably the best of the bunch. However, they are more expensive than the others. Sharp and Casio produce units that sell for well under $50. If you plan on doing any assembly language programming at all, owning one of these calculators is essential.
To understand why you should spend the money on a calculator, consider the following arithmetic problem:
$9 +$1 ----
You're probably tempted to write in the answer "$10" as the solution to this problem. But that is not correct! The correct answer is ten, which is "$A", not 16 which, is "$10." A similar problem exists with the subtraction problem:
$10 - $1 ----
You're probably tempted to answer "$9" even though the true answer is "$F." Remember, this problem is asking "what is the difference between sixteen and 1?" The answer, of course, is 15, which is "$F."
Even if the two problems above don't bother you, in a stressful situation your brain will switch back into decimal mode while you're thinking about something else and you'll produce the incorrect result. Moral of the story: If you must do an arithmetic computation using hexadecimal numbers by hand, take your time and be careful about it. Either that, or convert the numbers to decimal, perform the operation in decimal, and convert them back to hexadecimal.
|