Module 3 – Assembly Language
Label : opcode operand ; comment
Label – is optional, and is used as a forward reference & a possible jump instruction.
Ex :
MOV AX, #2;
MOV BX, #2;
SUB AX, BX;
JNE Exit;
Exit: MOV AX, BX;
Opcode – contains the mnemonic to describe the operation to be carried out.
Ex: MOV -> move, SUB -> subtract, ADD -> addition
Operands – contain the source and destination of the data operated on.
Ex: MOV AX, #5;
Source Destination
Comments – these are optional and used for the programmer’s convenience
Assembly Language Instruction – is a mnemonic which can be used instead of binary code
representing machine code.
Assembly Instructions:
1. DATA TRANSFER INSTRUCTIONS
MOV AX, BX; Move the contents of register BX into register AX
(ex : Before – AX = 5, BX = 9; After – AX = 9, BX = 9; )
PUSH AX; (ex: AX = 5)
STACK
Before – AX = 7; After – AX = 10
5 <- Stack Pointer
POP AX; STACK
10 <- SP
2. Arithmetical Instructions 66
43
ADD AX, BX; Add the contents of BX to the
contents of AX and store the results in AX.
(ex: before – AX = 5, BX = 3; after - AX = 8, BX = 3)
SUB AX, BX; Subtract the contents of BX from the contents of AX and
store the results in AX.
(ex: before – AX = 7, BX = 3; after – AX = 4, BX = 3)
INC AX; Increment the AX contents by 1.
DEC AX; Decrements the AX contents by 1.
CMP AX, BX; Compare AX and BX and flag if they are equal.
(ex: If AX = BX, Flag = 1; If AX != BX, Flag = 0; )
3. LOGICAL INSTRUCTIONS (Bytewise operations)
NOT AX; (Before: 01001100, After: 10110011)
OR AX, BX; (Before: AX = 01100110
BX = 10000110
After: AX = 11100110
BX = 10000110)
AND AX, BX; (Before: AX = 01100110
BX = 10000110
After: AX = 00000110
BX = 10000110) Status Flag register
10010000
(AND can be used for masking – mask certain bits to check their status)
AND
BX 1 0 0 1 0 0 0 1 =
AX 1 0 0 1 0 0 0 0
XOR AX, BX; (Exclusive OR) A B C
(Same inputs = 0, Different inputs = 1) 0 0 0
Before AX = 01100110 0 1 1
BX = 01111110 1 0 1
After AX = 00011000 1 1 0
BX = 01111110
4. TRANSFER INSTRUCTIONS
All Jump Instructions:
i. Unconditional Jump Instructions
1. JMP Start(Label); (jump to label ‘Start’ unconditionally)
ii. Conditional Jump Instructions
1. JE Label; (jump if equal to, to label)
2. JNE Label; (Jump if not equal to, to label)
3. JL Label; (Jump if less than to label)
4. JLE Label; (Jump if less thane or equal to label)
5. JG Label; (Jump if greater than to label)
6. JGE Label; (Jump if greater or equal to Label)
7. JC Label; (Jump if carry to Label)
8. JNC Label; (Jump if no carry to Label)
9. JZ Label; (Jump if zero to Label)
10. JNZ Label; (Jump if not zero to Label)
5. SHIFT AND ROTATE INSTRUCTIONS
Logical Shift Instructions
o SHL AX, 1; (Logical shift left AX by 1) (*2^1)
(Before: AX = 001000012 = 33; After: AX = 010000102 = 66)
o SHR AX, 1; (Logical shift AX by 1) (/2^1)
(Before: AX = 110010012 = 201; After: AX = 011001002 = 100 (Carry flag = 1))
Arithmetical Shift Instructions (signed number) (Two’s Compliment)
o SAL AX, 1; Shift arithmetical left by AX by 1
(Before: AX = 00100001; After: AX = 01000010)
(Before: AX = 01000001; After: AX = 010000010 (becomes 9-bit reg.))
(Before: AX = 11100000; After: AX = 111000000 (becomes 9 bits))
o SAR AX, 1; Shift arithmetical right AX by 1
(Before: AX = 01000010; After: AX = 00100001 CARRY FLAG = 0)
(Before: AX = 11100000 After: AX = 11110000 CARRY FLAG = 0)
(because when -ve, leading values become 1)
6. CYCLE SHIFT INSTRUCTIONS or ROTATE INSTRUCTIONS
RCL AX, 1; Rotate/cyclic shift left AX by 1 place. (unsigned)
(Before: AX = 10000001; After: AX = 00000011 CARRY FLAG = 0;
Ex: 2 RCL AX, 4;
(Before: AX = 1001 0101; (9 5) After: 0101 1001;)
RCR AX, 1; Rotate/cyclic shift right AX by 1 place. (unsigned)
(Before: AX = 10010001; After = 11001000; CARRY FLAG = 1)
7. FLAG MANIPULATION
CLC; Clear Carry
STC; Set Carry
8. PSEUDO-DIRECTIVES – These aren’t program instructions. They are instructions to the
ASSEMBLER & they don’t need to be translated.
HLT;
END;
Addressing Modes
These are related to physical attributes like registers.
1. Register Addressing
ex: MOV AX(destination register), BX(source register); Move contents of AX to BX
Data is transferred from the source register(BX) into the destination register(AX). MEMORY IS
NOT ACCESSED.
(other examples: INC AX; DEC AX;)
2. Immediate Addressing
Ex: MOV AX, #20; OR MOV AX, 20; Move the no. 20 inside AX
The data appears IMMEDIATELY after the OPCODE. MEMORY IS NOT ACCESSED
3. Direct Addressing
Ex: MOV AX, MyData; OR MOV AX, (1010H); Move the contents of
register AX to the memory address ‘MyData’ or to the memory address ‘(1010H)’
This refers DIRECTLY to a memory location (in first case, address = MyData, which is specified
by a LABEL). MEMORY IS ACCESSED.
4. Indirect Addressing
Ex: MOV AX, [BX]; A number found in register BX points to the memory
location where the actual data is to be found. (ex: in reg. BX, the memory address 100H is
stored.) MEMORY IS ACCESSED.
5. Indexed Addressing
Ex: MOV CX, [BX(base address register) + DI(displacement register (OFFSET) ) ]
(ex : CX = 67, BX = 100, DI = 4 ; Data stored in mem address 104(100+4) is stored in
CX)
A number contained in one register (BX) is usually combined with another number
found in another register (DI). This results in a number pointing to the required
memory location.
Execution: the data found in this memory location is stored in the CX register.
6. Symbolic Addressing
An addressing scheme where reference to a LABEL is made.
Ex: START(LABEL) : MOV AX, 0; (FORWARD REFERENCE)
JMP LABEL; (used with jump instructions)