Originally Posted by

**matsp**
Lets start with the "octal" bit. First of all it's 1, 2, 3, 4, 5, 6, 7, 10, 11, ... there's no 8 OR 9 in the number system.

Second, in the computer, numbers are stored in binary. Octal and hex are popular ways to represent binary numbers so that they can be human readable and still easy to translate back to binary. This works because in octal, 3 bits (binary digits) are represented by one octal digit (0..7) and in hex 4 bits are represented by one hex digit. So it's very easy for a human to work out that 031 in octal is 000 011 001. We can also do the same the other way, using hex: 0 0001 1001 becomes 19.

Decimal is much harder to deal with because the only way to do it is to divide by 2 or 10 depending on which way we're going, until there is nothing more to divide. This is because 10 is not a "nice" number of bits - each multiple of ten is approximately 3.3 bits... It would have been MUCH easier if we humans were born like cartoon characters (e.g. the Simpsons), with one thumb and three fingers. Then we would have used octal as our number base in the first place, and we wouldn't have had this problem.

As to knowing if something is a number or not, you probably really want to put that into a function that resolves the symbols into numbers too, since you don't really care which they are when you see a particular instruction - you just want to translate it into a number, whcihever it is. Note that for labels that are forwards in the code, you will need a two-pass approach, so you read the entire file once, store away where each instruction belongs, and what the value of each label is, and then pass through it again and flll in any "gaps".

--

Mats