Beruflich Dokumente
Kultur Dokumente
Instructions
2
Fundamental instructions
1. mov - move
2. add - addition
3. sub - subtraction
4. call - call a function
5. ret - return from a function to caller
General Instruction Format
MOV (MOVE)
Memory Access Forms
mov
memory immediate
aNumber,10h
The data can be either a byte or a word.
memory register mov aDigit,ax
Memory Access Forms
?-bit Move
?-bit Move
mov ax, bl
mov [num1],[num2]
size mismatch
mem to mem move
Memory Access Forms
Ambiguous Move
.code
main proc
mov ah,01h ; input command
int 21h ;
mov dl,al ;output from DX REGISTER
mov dh,0h ;CLEARING high part
mov ah,02h ; loading output instr
int 21h // int21
mov ax,4c00h
int 21h
main endp
end main
• Run this program 6 times Atleast
; Clear screen
Add following instructions in start
mov ah, 0
mov al, 12h
int 10h
Modified Program
.model small
.stack
.data
.code
main proc
mov ah, 0
mov al, 12h ; Clear screen
int 10h
mov ah,01h
int 21h
mov dl,al
mov dh,0h
mov ah,02h
int 21h
mov ax,4c00h
int 21h
main endp
end main
Addressing Modes
1. Immediate Addressing
2. Register Addressing
3. Direct Memory Addressing
4. Register Indirect Addressing
5. Base Relative Addressing
6. Base Indexed Addressing
1. Immediate Addressing
• This is when a constant value is moved into a
register or memory location.
• It is not really an address since it does not point
to any location within the memory or CPU.
• immediate values are not themselves stored
anywhere; during assembly of the program, the
immediate value becomes part of the machine
code instruction.
• example: mov ax,10h
2-Register Addressing
• A register can be used as both the source and
destination of the instruction.
• Registers are very fast for most operations so
maximum use must be made thereof.
• examples:
mov ax,bx
mov si,es:[bx]
3- Direct Memory Addressing
• A memory location can be used by using its
address as the operand in an instruction.
example: mov ax,aDigit
4-Register Indirect Addressing
Instead of specifying the memory location as an operand,
the memory location can be stored in a register.
Then this register must be specified to access the memory.
For indirect addressing, the 8086 can only use the BX, BP,
SI and DI registers.
example: mov ax,[bx]
Note that the difference between this and Register
Addressing is the use of the square brackets ([]) which
distinguish a normal register from a memory location.
5- Base Relative Addressing
•
A possible combination of direct and indirect addressing techniques could
be when an indirect address is specified as well as an offset from that
value.
• To specify base relative addressing, the programmer must indicate the
base register and displacement/offset as a sum.
examples:
mov ax,[bx+4]
mov ax,[bx]+4
mov ax,4[bx]
• All these instructions will use the same address, which is 4 more than the
address stored in the bx register.
• The only registers allowed are BX and BP (the so-called "base" registers).
This technique can also called Direct Indexed Addressing, when it utilises
the SI and DI registers (the so-called "index" registers).
6-Base Indexed Addressing
•
This is a combination of base register and direct indexed addressing.
Instead of specifying the address as being stored in one register, the CPU
can add the values stored in two registers to get the effective address.
• Of course, an offset can also be specified. Since this technique uses a base
register and an index register, there are only four allowed combinations of
registers.
example:
mov ax,[bx+si+4]
mov ax,[bx][si]+4
mov ax,[bx][si+4]
• All these instructions will use the same address. If BX=4 and SI=8, then the
address will be 4+8+4 =16 (decimal) = 10h.
• Base indexed addressing is useful for indexing two-dimensional arrays,
whereas the other methods are used for the simpler one-dimensional
cases.
Segment Over-riding
• Instead of all references to memory being taken from the DATA
segment, the programmer can explicitly tell the assembler to read a
memory location using a different segment.
• the name of the segment must be prepended with a ':' to the
address.
• example: mov ax,ex:[bx]
• This calculates the effective address using the ES register instead of
the DS register which is normally used.
• Similarly, the CS register can be overridden when required.
• This is normally used when a memory location in another segment
needs to be accessed. Rather than change the DS register
unnecessarily, ES could be used for that purpose.
•
LEA(Load Effective Address) instruction
• loads the specified register with the offset of a
memory location.
• format:
LEA register,memory
Arithmetic and Logic Instructions