8086 Assembly Language - Microprocessor And Interfacing
Theory
- Basic

- Conversion of Binary & Hexadecimal
- Registers
- General purpose registers
- All are 16-bit

- Segment registers
- CS, DS, ES, SS

- Memory
- Represented in square brackets -=>
[BX]
- Combination of BX,SI,DI,BP Registers
MOV AX, @DATA -=> Loads starting address of data segment into AX register
- Immediate
- Declaration
DataType
- Basic
- DB (DEFINE BYTE)
- 1 byte memory allocation
- Example
A DB 9
MESSAGE DB 'HELLOWORLD'
- DW (DEFINE WORD)
- Memory allocation based on system architecture
- Example
- DD (DEFINE DOUBLEWORD)
- DQ (DEFINE QUADWORD)
- String
STR DB "HELLO WORLD"
STR DB "HELLO WORLD", '$'
STR DB 10, 13, "HELLO WORLD", '$'
- Array
- Basic
a DB 1h,2h,3Fh,7Fh
a DW 1111h,2222h,3333h
- Declaring using Duplicate
X DB 3DUP(7) ≈ X DB 7,7,7
X DB 3DUP(5,6) ≈ X DB 5,6,5,6,5,6
X DB 10DUP(?) -=> Equivalent to int var[10]={0}
- Accessing values
MOV AL, a[N]
MOV SI, N > MOV AL, a[SI]
Operations
MOV
- Copy second operand/source to first operand/destination

- Processor status Register or Flags

- Carry Flag -=> Set to 1 when there is unsigned overflow
- Parity Flag
- Auxillary Flag
- Zero Flag -=> Set to 1 when result is 0
- Sign Flag -=> Set to 1 when result is negative
- Trap Flag
- Interrupt Enable Flag
- Direction Flag
- Overflow
Instructions
- Arithmetic
- Addition
- Subtraction
- Multiplication
MUL source
- Assumes one of the operand in AX (16-bit) or AL (8-bit) for storing result
- Immediate multiplication is not allowed
- Two 8-bit numbers multiplied generate 16-bit product
- Two 16-bit numbers multiplied generate 32-bit product which appears in DX-AX
IMUL source
- Used for signed numbers, Preserves sign
- Division
DIV source
- Immediate division is not available
- Interrupt is generated when an error occurs
- Divide by zero
- Divide overflow
IDIV source
- Logical Instructions
- AND
AND destination, source
- Clear higher order bits to zero
- Identify even/odd numbers
- OR
OR destination, source
- Set lower bits as 1
- XOR
XOR destination, source
- Clear a register by performing XOR with itself
- TEST
TEST destination, source
- Performs bitwise AND operation, doesn't change the first operand but only affects the Flag
- Used to check even/odd numbers
- NOT
- JUMP
- Jump
- Unconditional
- It transfers control to another point in the program
JMP Label
- Label is any specific set of code -=>
Label:
- Conditional
- Jump only when some condition is satisfied
JE/JZ Label
- Jump when zero flag is equal to 1
JNE/JNZ Label
- Jump when zero flag is equal to 0
- "JE" & "JNE" are mostly used after "CMP" instruction
- "JZ" & "JNZ" are used when you just check whether something is zero or not
JA/JG Label
- "JA" -=> Jump if above, if CF=0 & ZF=0
- "JG" -=> Jump is greater, if SF=O & ZF=0
JB/JC Label
JCXZ Label
- Others
- Comparison
CMP source, destination
- Subtract source from destination and set the flags
- Increment/Decrement
INC source
DEC source
- Subtract 1 from any register
- Shift
SHL source, N
- Shifts bits of bytes to left
- 0 comes in LSB & MSB goes into CarryFlag
- Use "CL" if "N" is more than 1otherwise use "CX"
- Value multiplied by 2
SHR
- It puts zero in the MSB and LSB is shifted into "CF"
- Value divided by zero
- Rotate
ROL
- Shift MSB to LSB, LSB will also go into "CF"
ROR
- Negation
Others
- Interrupt
- Basic
- It is an input signal to the processor indicating an event which needs immediate attention
- There are 256 Interrupts
- Interrupts are handles using Interrupt Vector Table
- It is a data structure that associates a list of interrupt handler with a list of Interrupt requests in a table of Interrupt vectors
- Input Will Be stored in AL/AX register, Output to be stored in DL/DX
- Types
- Software Interrupt
- Hardware Interrupt
- Macros
- Copy and Pasts exactly the same defined code wherever used, takes more memory space
- Procedure
- A group of instructions that usually performs one task, it is reusable section that is stored in memory once, but used often
- Uses less memory but takes more time as compared to macros
- "CALL" instruction links to the procedure and "RET" instruction returns from the procedure