Professional Documents
Culture Documents
A memory address on the 8086 consists of two numbers the segment and the offset. This combination of segment and offset is referred to as a logical address. The segment number refers to a 64 KB block of memory and the offset is an index into the memory segment. e.g. the address AB10:1024 corresponds to the byte stored in segment 0xAB10 at offset 0x1024.
Illegal Addressing
mov al, [bl] ; Address cannot be 8-bit ; has to be 16-bit ; Registers cannot be ; subtracted ; Two bases cannot be ; used in one addressing ; Two indices cannot be ; used in one addressing
mov
mov
mov
Effective Address = EA = Base + Index + Offset EA = 0x0100 + 0x0200 + 0x0700 = 0x0A00 Physical Address = Segment * 0x10 + EA = 0x1000 * 0x10 + 0x0A00 = 0x10A00
BX = 0x9100 DS = 0x1500
Effective Address = An effective address is any operand to an instruction which references memory. EA = Base + Index + Offset = 0x9100 + 0x0000 + 0x07000 = 0x10100 ; 17-bits ! = 0x0100 ; Segment wrap ; around
Effective Address = EA = Base + Index + Offset = 0x0100 + 0x0000 + 0x0100 = 0x0200 Physical Address = Segment*0x10+EA = 0xFFF0*0x10+0x0200 = 0x100100 ; 21-bits ! = 0x00100 ; memory wrap ; around
CMP
Subtracts the source (src) from destination (dest) Does not change contents of src or dest. Affects AF,CF,OF,PF,SF and ZF. The relation is of destination to source.
Conditional Jumps
jz Jnz
[ZF=1] [ZF=0]
Conditional Jumps
je Jne ;jump if equal [same as jz] ;jump if not equal [same as jnz]
Conditional Jumps
jc Jnc ;jump if carry [CF=1] ;jump if not carry [CF=0]
Conditional Jumps
ja jb ;jump if above ;jump if below unsigned integers [ZF = 0 and CF=0] [CF=1]
jl jg
Conditional Jumps
jae ;jump if above or equal jbe ;jump if below or equal jge ;jump if greater or equal jle ;jump if less or equal jno ;Jump if not overflow jns ; Jump if not sign
Conditional Jumps
jcxz ;jump if the cx register is zero [cx=0]
[org 0x0100] jmp start data: swap: start: loop1: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0 db 0 mov bx, 0 mov byte [swap], 0 mov ax, [data+bx] cmp ax, [data+bx+2] jbe noswap mov dx, [data+bx+2] mov [data+bx+2], ax mov [data+bx], dx mov byte [swap], 1 add bx, 2 cmp bx, 18 jne loop1 cmp byte [swap], 1 je start ; initialize array index to zero ; rest swap flag to no swaps ; load number in ax ; compare with next number ; no swap if already in order ; load second element in dx ; store first number in second ; store second number in first ; flag that a swap has been done ; advance bx to next index ; are we at last index ; if not compare next two ; check if a swap has been done ; if yes make another pass
noswap: