The intel 80 x 86 CPUs View 8086















- Slides: 15

The intel 80 x 86 CPUs View

8086 Registers • All 8086 registers are 16 bits registers 1. General purpose registers AX(AH, AL), BX(BH, BL), CX(CH, CL), DX(DH, DL) 2. Segment registers CS, DS, SS, ES 3. Pointer register SI, DI, BX, BP, SP 4. Flag register

8086 Registers

Segment and offset • Segment on 80 x 86 can form 64 K byte to 4 gigabyte. – e. g. code segment, data segment, stack segment, etc. • Offset is used to point inside the segment.

Program Segments

Flag register

80 X 86 Instructions Instruction meaning Equivalent C code MOV x 1, x 2 copy form source to destination x 1=x 2 ADD x 1, x 2 add source to destination x 1 = x 1 + x 2 SUB x 1, x 2 subtraction source to destination x 1 = x 1 - x 2 AND x 1, x 2 bitwise AND x 1 = x 1 & x 2 OR x 1, x 2 bitwise OR x 1 = x 1 | x 2 XOR x 1, x 2 bitwise XOR x 1 = x 1 ^ x 2 INC x Increment x++ DEC x decrement x-- NOT x invert all bits x=!x SHR x, 1 shift to the right by one bit x = x >> 1 SHL x, 1 shift to the LEFT by one bit x = x << 1

MOV, ADD, SUB, AND, OR, XOR • MOV operand 1, operand 2 operand 1 = operand 2 • ADD operand 1, operand 2 operand 1 = operand 1 + operand 2 – Operand 1 can be register, memory location – Operand 2 can be register, memory location, constant value Illegal instructions: • add var 1, var 2 both operands cannot be memory locations • sub 12 h, al destination cannot be constant value • and al, dx operands must not have different sizes • mov ds, 12 h it cannot move a constant value to a segment register

INC, DEC, NOT • INC operand ++ • DEC operand - • NOT operand = ! operand – Operand can be register or memory location Illegal instructions: • not 12 h operand cannot be a constant value • not al, 1 it cannot take 2 operands

SHL, SHR • SHL operand 1, operand 2 – Operand 1 can be register or memory location – Operand 2 can be the register CL or a constant value Illegal instructions: • shl al, bl second operand can be the register CL or a constant value only

Your first assembly program • Write a program to calculate the following: W=x + y – z

Write a program to compute the result of D = ABC’ + ABC + A’B + B’A + C. model small. data A db 10 B db 3 C db 5 D db ? . code mov ax, @data mov ds, ax mov al, C ; C not al ; C' and al, A ; AC' and al, B ; ABC‘ mov bl, A ; A and bl, B ; AB and bl, C ; ABC mov cl, B ; B not cl ; B' and cl, A ; AB' or cl, C ; AB'+C or bl, cl ; ABC+AB'+C or al, bl ; ABC'+ABC+AB'+C

Questions Write a statement for each of the following tasks: a) Clear all bits of AX except nibble 2 AND AX, 0 F 00 h b) Change bit 0 and bit 7 of AH XOR AH, 10000001 b c) Set all bits of AH except bit 3 OR AH, 11110111 b Write the following expressions in assembly language using shifts, additions and subtraction only. CX * 7 MOV AX, CX SHL CX, 3 SUB CX, AX BX * 129 MOV AX, BX SHL BX, 7 ADD BX, AX * 512 AX / 8 BX * 5 SHL AX, 9 SHR AX, 3

Questions what is the value that is stored in AL after executing each statement in the following code. model small . data x db 10 y db 3 z db 5 w db ? . code main: mov ax, @data ah, al=@data mov ds, ax ah, al=@data mov al, x al=10 add al, y al=13 sub al, z al=8 mov w, al al=8

Questions Consider the following variables x db 10 y db 3 z db 5 w dw ? Correct the following statements mov ds, @data mov ds, ax and x add x, y mov ax, x sub 12, ax xor w, al or 10111110 b, x inc z, 1 not 0 Fh shl w, ax mov ax, @data; and x, dl mov al, x add al, y mov al, x sub ax, 12 xor w, ax or x, 10111110 b inc z mov dl, 0 Fh not dl shl w, cl