Chapter 7
How to use the Data transfer instructions (MOV)
-----------------------------------------------

There are six different data-addressing modes used for data transfers with the 8088 CPU. A number enclosed in brackets is a memory location at the offset specified by the number. [150] is a memory cell at offset 150 in RAM that can hold 8 bits or one byte of data. If a register is enclosed with brackets [BX], then the CPU will go to the memory location specified by the register for the data.


1. MOV AX,BX

register,register Data is transferred from the BX reg. into the AX reg. (16 bit transfer)

MOV AH,BL

register,register Data is transferred from the BL reg. into the AH reg. (8 bit transfer)


2. MOV AX,5

immediate The hex value in the source (5) is moved directly into the AX reg.(16 bit transfer) 5 is really 0005

MOV AH,5

immediate The hex value in the source (5) is moved directly into the AH reg. (8 bit transfer) 5 is really 05

3. MOV AX,[200]

direct The brackets are used to enclose a memory location.The value stored at offset location 200 and 201 is moved into the into the AX reg. Each memory location is one byte and since this a 16 bit or two byte transfer it will use two memory locations. The Al reg. will get the value at 200 and the AH will get the value at 201.


MOV AL,[450]

direct The value stored at offset450 is moved into the AL reg. Since this is an 8 bit transfer it will only use one memory location.
4.MOV AX,[BX]

indirect The value stored at the location that the BX reg points to will be transferred into the AX reg.Suppose the BX reg has the value 345 in it. The AX reg would than get the value at location 345 and 346. (16 bits)

MOV CL,[BX]

indirect same as above but is an 8 bit transfer


5. MOV AX,[BX+5]

base+displacement Same as above but the number is added to BX to get the location of the data.(16 bit transfer)

MOV AH,[BX+5]

base+displacement Same as above but 8 bit transfer.


6. MOV AX,[BX+SI+8]

base+index+8 Here there are two reg.displacement used + a value. The CPU will calculate the location in memory using the values in the BX and SI reg. plus the value specified.(16 bit transfer)

MOV AL,[BX+SI+6]

base+index+6 same as above but 8 bit displacement transfer.

Note: We are only going to assemble programs using modes 1,2,3 and 4


How to use the PUSH and POP transfer instructions
-----------------------------------------------

PUSH AX
POP AX

There are four general purpose registers that can be used by our program to transfer data and preform arithmetic operations. This may seem like enough, but when writing a program you may find yourself looking for a few more registers to work with. The PUSH and POP instruction will allow us to save the contents of the registers being used into the stack area of memory. Once the contents are saved, we can re-use them for more operations and when finished, restore them to their original values they had before they were saved.
PUSH CX will cause the contents of the CX register to be saved in the stack area of memory. The stack area is located at the top of the segment our program is in at the time. The first location available in the stack is located at offset FFFE and will decrement downward in memory. The stack is what we call "First In and Last Out" and we must pay attention to how we use the PUSH and POP instructions. Think of the stack as a pile of dishes, The first dish we put in the shack will have to be the last dish we take off of the stack. If we try to take the dishes off in any other order the pile will most likely crash.If we do the same thing in our program, the computer will crash.



Example:

Look at the following program,

MOV CX,115F
MOV AX,BX
OUT DX,AL
INC CX
PUSH CX
PUSH AX
MOV DX,03BC
MOV AX,[120]
MOV CX,BX
OUT DX,AL
POP AX
POP CX
RET

The first 3 instructions are using the CX and AX registers to hold values needed in this part of the program. After the CX register is incremented, two push instructions are exetuted,.(PUSH CX and PUSH AX) that will save the current value of CX and AX on the stack. CX and AX can then be used for more instructions, then POP AX and POP CX in that order, will restore the values that were in them in the first part of the program.

When our program uses an INT instruction,the CPU will change the IP reg to point to a sub-routine program inside the ROM bios chip or the IBMDOS.SYS program in low memory. These sub-routines will use all of the general purpose registers that are program was using before the INT instruction was executed. IBM says all registers are preserved (saved) when an INT is executed except the AX register. I would suggest that you PUSH the AX register every time you use the INT instruction.


  • Chapter 8
  • Return to Home Page.