Sie sind auf Seite 1von 35

Instructions

Instructions

• Each instruction does something relatively


simple.
• move some bits around
• treat some bits as base 2 numbers and apply
arithmetic operations.
• send/read some bits to/from I/O devices.
• select the group of bits that will make up the
next instruction

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

• instruction dest, src


• instruction dest
• instruction src
Instruction Groups

Data Movement Instructions


Arithmetic / Logic Instructions
Program Control Instructions
Special Instructions
Fundamental instructions
• In all of the following examples, let:
K equ 12  a constant (doesn’t use memory)
a dword 52  a variable (uses memory)
Fundamental instructions

MOV (MOVE)
Memory Access Forms

• moves data from one location to another.


MOV
destination source example
• Format register register mov ax,bx

register immediate mov ax,10h

mov dest, src register memory mov ax,es:[bx]

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

mov al, [num1]

?-bit Move

mov ax, [num1]


Limitations
• an immediate value cannot be moved into a
segment register directly (i.e. mov ds,10)
• segment registers cannot be copied directly (i.e.
mov es,ds)
• a memory location cannot be copied into
another memory location (i.e. mov
aNumber,aDigit)
• CS cannot be copied to (i.e. mov cs,ax)
Memory Access Forms
Problem ????

mov ax, bl
mov [num1],[num2]
size mismatch
mem to mem move
Memory Access Forms
Ambiguous Move

mov [num1], 5 ;5 is byte or;word?


mov byte[num1], 5 ;move 5 as byte
mov word[num1], 5 ;move 5 as word
Remember …!!!!
• All names that are used in the program are
converted into memory locations during the
assembly process. Thus, any name is generally
considered to be analogous to a memory
location while writing assembly code.
Input Output Program
.model small
.stack
.data

.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

Move 5 to AX mov ax,5


Move 10 to BX mov bx,10
ADD BX to AX add ax,bx
Move 15 to BX mov bx,15
ADD BX to AX add ax,bx
Arithmetic and Logic Instructions

and ax,1234 ; AND 1234 with ax

add bx,0534 ; ADD 0534 to bx

add bx,[1200] ; ADD data at address 1200 to


bx

add ax,[1234] ; ADD data from address 1234


to ax
Program Control Instructions

cmp ax,0 ; Compare ax with 0

jne 1234 ; Jump if not equal to the instruction


; at address 1234
Special Instructions

cli ; Clear the interrupt flag

sti ; Set the interrupt flag

Das könnte Ihnen auch gefallen