AX
/----------------\
1 0 0 1 1 1 0 1
\-------/\------/
AH AL
Load up D86 and look at the list of registers in the bottom left of the
screen. Notice that the values are given in hexadecimal.
The 'DB' command is used to allocate a byte sized variable. It is used as
follows:name DB initial_value
The name statement is used to specify the name by which the variable
will be referred to later in the program. The initial_value is
used to specify an optional value with which the variable will be
initialised. If it doesn't matter, use a '?' instead. The 'DW' command is used to
allocate a word sized variable, and it is used the same as the 'DB' command.
Similarly, the 'DD' command allocates two words of space.
The instruction MOV AX,BX then,
would copy the value in the BX register and place it in the AX register.
The source and destination parts are called the operands.
Note:It should be noted that the order of the source and
destination is the opposite to what would be expected in ordinary english.
MOV AX,BX does NOT mean "move AX to BX", but "move AX
with/from BX".
The operands to the MOV command do not have to be registers. The destination and source can be any combination of registers, memory variables, and constant numbers(immediate values), except for two memory variables or two constants. They do have to be the same size (i.e. the instruction MOV AX,BL would not be allowed). Here are some examples:
The source will be added to the destination and the result will be stored in the destination. Some examples are:
204: 1 1 0 0 1 1 0 0
+ 72: 0 1 0 0 1 0 0 0
-----------------
=276: 1 0 0 0 1 0 1 0 0
When we try to store this in AL we have a problem. AL is an 8-bit register,
but our result is 9-bits in size! The processor will handle this as follows:
the lower 8 bits will be stored in AL, and the 9th bit will be stored in
the 'carry flag'. The carry flag is a 1-bit location in the processor
which is set with the 9th bit after every addition (or the 17th bit after
an addition involving two 16-bit numbers).There are other flags, the most important being the 'zero flag'. After any operation, if the result was zero, the 'zero flag' will be set. If the result was non-zero, the flag will be cleared.
In D86, the flags appear as a row of letters above the registers. The carry flag is a 'c' and the zero flag is a 'z'. If the letter is visible the flag is set.
The SBC instruction stands for subtracting with carry. The instructions we would use to subtract two 32-bit numbers stored in AX and BX, and the other in CX and DX.
mov ax,174 ; stores 174 into the ax register
add ax,52 ; now adds 52 to this, so we have 226 in ax
mov tempvar,ax ; store this in the tempvar memory variable
mov bh,10xH ; these two instructions together
mov bl,f3xH ; store 10f3xH into the bx register
add tempvar,bx ; adds this value to the memory variable
mov ax,b4d2xH ; now a 32-bit addition using the carry flag
mov bx,75c2xH
mov cx,9e83xH
mov dx,432cxH
add bx,dx
adc ax,cx
int 20h ; this line is necessary to let the computer
; know the program has finished
tempvar DW ?
After the program has been entered, save it as 'example1.asm', and if you
are using A86 assemble it using the command line
'a86 example1.asm'. If you run the program now, hopefully it will do nothing!
At this stage, you will need to use