Now that I'm done with this, I'm adding here that you should make sure to read this whole
thing because it is very useful - and covers some computer science topics!

If I were you, I'd start by reading this and then look at the tutorials. If you feel like
testing your knowledge, make a program once you've learned some commands through the 
tutorials. To make a program, simply create a .asm file and type source in it. When you're 
ready to compile it, save it and type A86 *.asm (* stands for its name). At this point, I am
assuming that you have set A86's directory in your path file. This is explained in 
direction.txt.

SEGMENTATION and OFFSETS:

These are explained VERY poorly everwhere I see them, so I'll try to explain them in normal
terms...

The 8086 processor (which is emulated on a Pentium in your dos prompt AKA virtual 86 mode,
which has all of it's commands plus more) was designed to be 16 bit. and 2^16 = 65535. This
is true because every place in binary has two possibilities, 0 and 1, and it's just like the 
decimal Trig. probablility problems where it was 10^the_number_of_digits. Anyway, if 
the maximum value handled by the processor (although software could emulate more, but would 
calculate VERY slowly) is also 65535. This only allows the processor to use that many bytes,
which is only 64k :(. So they decided to create segmentation.

Segmentation was designed to allow the programmer to access more memory and segmentation
also uses 16 bit numbers, so you would think that the maximum amount of memory would be
2^(16+16) right? Not so. Instead they decided to use segments and offsets to make a 20 bit register = 2^20 = 1MB .... retarded! They do it like this:

1. Each digit the segement goes up, the address in memory goes up 16.
2. Each digit the offset goes up, the address in memory goes up 1.

In decimal, when you multiply a number by 10, it simply moves the decimal place. It's the
same way in binary, except it's true for  X 2. Here is how binary works, if you're wondering
If not, skip to ****

binary:		128	64	32	16	8	4	2	1
		1	0	1	1	0	0	0	1    

		= 128x1 + 64x0 + 32x1 + 16x1 +  8x0  + 4x0  +  2x0  +  1x1  = 177

decimal works the same way, but only with 10 digits (0-9):
example using 9,016

	1,000        100        10       1
  	9	      0         1        6

	= 9x1,000 + 0x100  +  1x10   +  6x1  = 9,016

As you see, just like binary, each place has a place value, just like decimal, only it's not
multiplying by ten each time, it's multiplying by 2 b/c it's a base 2 system.

****
Segments and offsets are represtented like:    segment:offset
If it is       10:343   then   10x16+343 = 503.  Remember that each number the segment goes
up, the address goes up 16. This is basicall multiplying it by 16, which is like multiplying
it by 2, 4 times. Which in binary is the equivalent of shifting the number one place, as
mentioned earlier.   Let's write that 10:343 in binary. By the way, the calculator in accessories, when in scientific mode, can convert from binary to hex to decimal to octal and 
any combination of the above. Back to converting 10:343 to binary...
10 = 0000000000001010   
(0x32768 + 0x16384 + 0x8192 + 0x4096 + 0x2048 + 0x1024 + 0x512 + 0x256 +0x128 + 0x64 + 0x32 
+ 0x16 + 1x8 + 0x4 + 1x2 + 0x1)
343 = 0000000101010111    &I'll skip all the initial zeroes in this one...
(1x256 + 0x128 + 1x64 + 0x32 + 1x16 + 0x8 + 1x4 + 1x2 + 1x1)

So we end up with :         0000000000001010:0000000101010111
As I mentioned, we multiply the seg by 16 = multiply it by 2, 4 times = shift number left 4 times and we get:
			0000000010100000
then we simply add the offset to it and get:
			0000000010100000
		     +  0000000101010111
			----------------
			0000000111110111 = 503 = (10x16 + 343)
NOTE: In binary, if there are 2 1's overtop of each other, you have to carry a one.
So:			010111
		      + 011111
			------
			110110   
Here, when a 1 was carried, often the next place already had two 1's in it, so there were a
total of 3 ones, 2 get carried as a 1 to the next spot and the remaining 1 stays...

Now that you hopefully understand segmentation and offsets, and binary, you should probably
get familiar with hex. I like this system best because it is the most compact. It works the
same way as the other two, only base 16 (digits 0 - F). So the places in a simple byte
would be:
		16	1
and for a word (16bits) would be:
		4096	   256	    16	      1
So 4AB7 = 	4x4096  + 10x256 + 11x16  +  7x1     =   19127 in binary
Notice how 4 digits in hex took the same as 16 digits in binary. This goes back to that
shift the number thing. Everytime you multiply a binary number by 16, you shift it four
places. Because every hex digit can hold the value of 4 binary ones, multiplying by 16
shifts it one place. There is no strong correspondance between decimal and either hex or
binary. For example, FFFF in binary takes 5 decimal digits (65535), while 1111 in hex
takes only four decimal digits (4369). So it isn't nearly as convenient to convert between
the two and you want to be careful you don't mix these up in your programs.

Finally, when writing numbers, do this:
hex numbers:    F734h   (add an h on the end)
bin numbers:    10101011xb (add a xb on the end)
	Some assemblers would accept 10101011b, but this could easily be confused for a hex
	number because B is a digit in hex
dec numbers:    1246    (you can usually just write them out, I haven't seen them any other
			 way)

Negative numbers:
	Sometimes it's necessary to use negative numbers in programs. In this case, make
sure to use the correct assembler commands. Some are designed just to add numbers and others
to add negatives numbers. (etc. for multiplication, div, subtraction) Negative numbers/
positive numbers are decided on the binary level. If it is a signed command (one that uses
positive and negative numbers), it will look to see what the first binary digit is. If it is
a zero, the number is positive, if it is a one, it's negative. Positive works the same as it
did for the unsigned stuff explained earlier, except you want to be careful that you don't
add too many positive signed numbers because it could give you a value too high, which
would cause the first digit in binary to become a one and suddenly your high positive number
has become negative!

Back to negative... If the first digit in the binary number is a 1, it is negative. Negative
1 represented in a byte is 11111111. Negative two would be 11111110. Negative three would
be 11111101. Negative four would be 11111100. Basically how it works is to right it in
normal numbers (instead of counting backwards) is this:
	1. Complement the number. In binary, this means switch 1's to 0's and vice versa.
	2. Add 1 to the number as if it is positive.
	3. Put a negative sign in front of it.
So, 10111010 in signed binary is -01000101 = -69   HA! I picked the binary number before
I knew it's decimal equivalent!

NOTE: If you are trying any neg. binary on the calculator, don't rely on it too much
because it's designed mainly to work with positives all the time, and therefore calculates
in unsigned. So one second a number will be negative and the next it will be a completely
different positive number, which will most likely confuse you unless you know what's going
on. So as a learning experience, you might want to try messing around with the calculator.


LOGIC COMMANDS:
There are three logic commands: AND, OR, NOT. These work on the binary level and you must
look at them on the binary level to understand them. These are, I believe, assumed that
you know them in many tutorial cases.

AND
If you and two numbers, let's say    10110110
				and  10000011    
It checks to see in each binary place if both digits are ones. If they are, then that spot
in the result is a one. If they aren't BOTH 1's then it is a zero. So....
	10110110
    AND 10000011
	--------
     is 10000010

OR
This checks to see if either digit in each place is a one, in order for that place in the
result to be a 0, both digits have to be a zero so...
	10110110
     OR 10000011
        --------
     is 10110111

NOT
This is the simplest of them, and not as common. The big difference is that it only uses
one operand (number). All it does is switches the digits. This, as you can imagine, can
come in handy when working with negative numbers. Remember, you simply switch the digits
(NOT them) and add one and then put a "-" on the front to make it so that it's not in
it's opposite form. So...
	NOT 10110110
	 is 01001001
NOTing can also be considered subtracting from the highest value (although this isn't how
the computer does it). But this method looks like:
(byte: 11111111 - 10110110 = 01001001) 
(word: 1111111111111111 - the_number = result)
(dword (doubleword (32 digits) ): 11111111111111111111111111111111 - the_number = result)

NOTE: In all arithmetic and logic operations, the processor sets things called flags, the
most basic of these being the zero flag. Programmers often use these logic operations to set
these flags. A basic example is this: The programmer wants to see if one number is
completely zero. If you OR that number with itself, it will only give you a zero result if
every digit is a zero. When the result is zero, the zero flag is set. This can be used to 
jump to a certain location if it is zero or even to jump to another location if it isn't,
or just observed as part of the program.

SUBTRACTION:
A computer can't subtract, it only adds. But then someone might ask, "how does it subtract
then?" It has it's own method. For a reason I won't explain, but that you could easily figure
out with a little observation, the following method works:
	1. Get the two numbers.
	2. NOT the top number in the problem.
	3. ADD the numbers together
	4. NOT the digits again.

Example1:	11111111  =>  00000000
	      - 00000000     +00000000
			      --------
			      00000000  =>  11111111
Example2:
		10101011  =>  01010100				
	      - 01111010     +01111010 
			      --------
			      11001110	=>  00110001    =    49

		In decimal    171 - 122 = 49
		or            (999 - 171) + 122 = 950 and 999 - 950 = 49   !!!!!!!
		
		If you look at this decimal method closely, you might figure out why it 
		works.

Brian
oconnellb@hotmail.com	    