Microprocessor and Microcontroller
Microprocessor and Microcontroller
MICROCONTROLLER SYSTEM
IBB20204
INSTRUCTION SETS
ASSEMBLY LANGUAGE PROGRAMMING
The Instruction Set
1. Data transfer instructions (move: MOV, exchange: XCHG,
translate: XLAT, load register: LEA, LDS, LES)
2. Arithmetic instructions (addition: ADD, subtraction: SUB,
multiplication: MUL)
3. Logic instructions
4. String manipulation instructions (SHIFT and ROTATE)
DATA TRANSFER INSTRUCTION
DATA TRANSFER
Provide the ability to MOVE data either between its internal
registers or between an internal register and a storage location
in memory.
Instruction: XLAT
This means “replace the contents of AL by the contents of the
accessed look-up table location”.
DATA TRANSFER - TRANSLATE
((AL)+(BX)+(DS)0) AL
PA = 12000H+0200H=12200H
[12200-12201] SI = 0020H
Sum Carry
Rule 1 0 + 0=0 0
Rule 2 0 + 1=1 0
Rule 3 1 + 0=1 0
Rule 4 1 + 1=0 1
ADDITION OF BINARY NUMBERS
The binary add operation is described in general as:
A+B = S + Co
Where Co = carry-out.
That is, the contents of the source operand are added to those of
the destination operand and the sum that results is put into the
location of the destination operand.
The carry-out that may occur from the addition of the MSB of
the destination is reflected in the carry flag (CF).
ADD INSTRUCTION
Example:
Assume that the AX and BX registers contain 110016 and 0ABC16,
respectively.What is the result of executing the instruction:
ADD AX, BX
ADD INSTRUCTION
Solution:
1B BC
AX
ADD INSTRUCTION
Solution: ADD instruction before/after fetch and execution.
ADC INSTRUCTION
ADC = Add byte or word with carry
Works similarly to ADD, except, the content of the carry flag is
also added.
ADC is generally expressed as:
1st instruction – Adds the word in the accumulator and the word
in the memory location pointed to by address SUM. The result is
placed in the accumulator.
That is,
2nd instruction – Adds to the lower byte of the base register (BL)
the immediate operand 5H and the carry flag, which is 0H.
This gives,
That is,
(SUM) (SUM) + 116 = 00CD16 + 116 = 00CE16
CF remains 0.
INSTRUCTION (AX) (BL) (SUM) (CF)
Initial State 1234H ABH 00CDH 0H
ADD AX, [SUM] 1301H ABH 00CDH 0H
ADC BL, 05H 1301H B0H 00CDH 0H
INC [SUM] 1301H B0H 00CEH 0H
SUBTRACTION
SUBTRACTION OF BINARY NUMBERS
Recall Chapter 1: Rules of subtraction
Rule 1 0 - 0 = 0
Rule 2 0 - 1 = 1 with a borrow of 1
Rule 3 1 - 0 = 1
Rule 4 1 - 1 = 0
To perform Rule 2 you have to borrow 1 from the next column. The
weight of the binary you borrow will be 2.
SUBTRACTION OF BINARY NUMBERS
The binary subtraction operation is described in general as:
A – B = D + Bri
Where Bri = borrow-in.There will also be a borrow-out (Bro).
That is, the contents of the source operand are being subtracted
by those of the destination operand and the sum that results is
put into the location of the destination operand.
The borrow-in (Bri) and borrow-out (Bro) that may occur from
the subtraction of the MSB of the destination is reflected in the
carry flag (CF).
SUB INSTRUCTION
Example:
Assume that the AL and BX registers contain AF16 and A316,
respectively.What is the result of executing the instruction:
SUB AL, BX
SUB INSTRUCTION
Solution:
XX 0C
AX
SBB INSTRUCTION
SBB = Subtract byte or word with borrow.
Works similarly to SUB, except, it also subtracts the contents of
the carry flag from the destination.
SBB is generally expressed as:
Therefore,
(BX) = 123416 – 012316 – 016
(BX) = 111116
0x0=0
0x1=0
1x0=0
1x1=1
MULTIPLICATION & DIVISION
SUBGROUPS
Multiplication subgroups are:
SHR AX, CL
ROTATE INSTRUCTIONS
ROTATE INSTRUCTIONS
ROL – Rotate left
ROR – Rotate right
RCL – Rotate left through carry
RCR – Rotate right through carry
Their difference from the shift instructions lies in the fact that
the bits moved out at either the MSB or LSB end are not lost;
instead, they are reloaded at the other end.
ROTATE INSTRUCTIONS
Rotate instructions:
ROTATE INSTRUCTIONS
Allowed operands:
ROTATE INSTRUCTIONS
ROL – Execution of this instruction causes the contents of the
selected operand to be rotated left the specified number of bit
positions. Each bit shifted out at the MSB end is reloaded at the
LSB end. Moreover, the content of CF reflects the state of the
last bit that was shifted out.
ROTATE INSTRUCTIONS
Example 1: ROL AX, 1 (take AX = 123416)
This instruction causes a 1-bit rotate to the left.
Note: The original value of bit 15 is 0.
This value has been rotated into both CF and bit 0 of AX.
All other bits have been rotated one bit position to the left.
ROTATE INSTRUCTIONS
ROR – Operates the same way as ROL, except that it causes
data to be rotated to the right, instead of to the left.
ROL AX, CL
Thank You