Module2 - 8051 Instruction Set - Updated
Module2 - 8051 Instruction Set - Updated
Module – 2
8051 Instruction Set
General syntax for 8051 assembly language is as follows.
LABEL: OPCODE OPERAND ; COMMENT
OPCODE: Opcode is the symbolic representation of the operation. The assembler converts the
opcode to a unique binary code (machine language).
OPERAND: While opcode specifies what operation to perform, operand specifies where to perform
that action. The operand field generally contains the source and destination of the data. In some cases
only source or destination will be available instead of both. The operand will be either address of the
data, or data itself.
COMMENT: Always comment will begin with ; or // symbol. To improve the program quality,
programmer may always use comments in the program.
Addressing Modes
The CPU can access data in various ways, which are called addressing modes
Immediate
addressing
Register Direct
modes
Register
Memory
indirect
Indexed
Direct addressing
mode
MOV A,4 ;is same as
MOV A,R4 ;which means copy R4 into A
Register addressing
mode
The SFR (Special Function Register) can be accessed by their names or by their addresses
Example 2-1
Write code to send 55H to ports P1 and P2, using (a) their names (b) their addresses
Solution :
(a) MOV A,#55H ;A=55H
MOV P1,A ;P1=55H
MOV P2,A ;P2=55H
Example 2-2
Show the code to push R5 and A onto the stack and then pop them back them into R2 and B,
where B = A and R2 = R5
Solution:
PUSH 05 ;push R5 onto stack
PUSH 0E0H ;push register A onto stack
POP 0F0H ;pop top of stack into B
;now register B = register A
POP 02 ;pop top of stack into R2
;now R2=R6
Example 2-3
Write a program to copy the value 55H into RAM memory locations 40H to 41H using
(a) direct addressing mode, (b) register indirect addressing mode without a loop, and (c) with a loop
Solution:
(a)
MOV A,#55H ;load A with value 55H
MOV 40H,A ;copy A to RAM location 40H
MOV 41H,A ;copy A to RAM location 41H
(b)
MOV A,#55H ;load A with value 55H
MOV R0,#40H ;load the pointer. R0=40H
MOV @R0,A ;copy A to RAM R0 points to
INC R0 ;increment pointer. Now R0=41h
MOV @R0,A ;copy A to RAM R0 points to
(c)
MOV A,#55H ;A=55H
MOV R0,#40H ;load pointer.R0=40H,
MOV R2,#02 ;load counter, R2=3
AGAIN: MOV @R0,A ;copy 55 to RAM R0 points to
INC R0 ;increment R0 pointer
DJNZ R2,AGAIN ;loop until counter = zero
22 DEPT. OF ELECTRONICS & COMMUNICATION E N G G . |M I T M Y S O R E
MICROCONTROLLER | MODULE2:8051 INSTRUCTION SET 18EC46
The advantage is that it makes accessing data dynamic rather than static as in direct
addressing mode
• Looping is not possible in direct addressing mode
Example 2-4
Write a program to clear 16 RAM locations starting at RAM address 60H
Solution:
CLR A ;A=0
MOV R1,#60H ;load pointer, R1=60H
MOV R7,#16 ;load counter, R7=16
AGAIN: MOV @R1,A ;clear RAM R1 points to
INC R1 ;increment R1 pointer
DJNZ R7,AGAIN ;loop until counter=zero
Example 2-5
Write a program to copy a block of 10 bytes of data from 35H to 60H
Solution:
MOV R0,#35H ;source pointer
MOV R1,#60H ;destination pointer
MOV R3,#10 ;counter
BACK: MOV A,@R0 ;get a byte from source
MOV @R1,A ;copy it to destination
INC R0 ;increment source pointer
INC R1 ;increment destination pointer
DJNZ R3,BACK ;keep doing for ten bytes
R0 and R1 are the only registers that can be used for pointers in register indirect
addressing mode
Since R0 and R1 are 8 bits wide, their use is limited to access any information in the
internal RAM
Whether accessing externally connected RAM or on-chip ROM, we need 16-bit pointer
In such case, the DPTR register is used.
Indexed addressing mode is widely used in accessing data elements of look-up table
entries located in the program ROM.
The look-up table allows access to elements of a frequently used table with minimum
operations
The instruction used for this purpose is MOVC A,@A+DPTR
• Use instruction MOVC, “C” means code
• The contents of A are added to the 16-bit register DPTR to form the 16-bit address
of the needed data
Example 2-6
Write a program to get the x value from P1 and send x2 to P2, continuously
Solution:
ORG 0
MOV DPTR,#300H ;LOAD TABLE ADDRESS
MOV A,#0FFH ;A=FF
MOV P1,A ;CONFIGURE P1 INPUT PORT
BACK: MOV A,P1 ;GET X
MOV A,@A+DPTR ;GET X SQAURE FROM TABLE
MOV P2,A ;ISSUE IT TO P2
SJMP BACK ;KEEP DOING IT
ORG 300H
XSQR_TABLE:
DB 0,1,4,9,16,25,36,49,64,81
END
A data MOV does not alter the contents of the data source address.
A copy of the data is made from the source and moved to the destination address.
The contents of the destination address are replaced by the source address contents.
Mnemonic Operation
MOV A,#0Flh Move the immediate data byte F1h to the A register
MOV A,R0 Copy the data in register R0 to register A
MOV DPTR,#0ABCDh Move the immediate data bytes ABCDh to the DPTR
MOV R5,A Copy the data in register A to register R5
MOV R3,#1Ch Move the immediate data byte 1Ch to register R3
Mnemonic Operation
MOV A, addr Copy data from direct address add to register A
MOV add, A Copy data from register A to direct address addr
MOV Rr, addr Copy data from direct address add to register Rr
MOV addr, Rr Copy data from register Rr to direct address addr
MOV addr, #n Copy immediate data byte n to direct address addr
MOV instructions that refer to direct addresses above 7Fh that are not SFRs will result in
errors.
The SFRs are physically on the chip; all other addresses above 7Fh do not physically exist.
Moving data to a port changes the port latch; moving data from a port gets data from the port
pins.
Moving data from a direct address to itself is not predictable and could lead to errors.
Mnemonic Operation
MOV A, 80h Copy data from the port 0 pins to register A
MOV 80h, A Copy data from register A to the port 0 latch
MOV 3Ah, #3Ah Copy immediate data byte 3Ah to RAM location 3Ah
MOV R0, 12h Copy data from RAM location 12h to register RO
MOV 8Ch,R7 Copy data from register R 7 to timer 0 high byte
MOV 5Ch,A Copy data from register A to RAM location 5Ch
MOV 0A8h,77h Copy data from RAM location 77h to IE register
The indirect addressing mode uses a register to hold the actual address that will finally be
used in the data move;
The register itself is not the address, but rather the number in the register.
Indirect addressing for MOV opcodes uses register R0 or R1, often called "data pointers," to
hold the address of one of the data locations, which could be a RAM or an SFR address.
The mnemonic symbol used for indirect addressing is the "at" sign, which is printed as @.
Mnemonic Operation
MOV @Rp, #n Copy the immediate byte n to the address in Rp
MOV @Rp, addr Copy the contents of add to the address in Rp
MOV @Rp, A Copy the data in A to the address in Rp
MOV addr, @Rp Copy the contents of the address in Rp to addr
MOV A, @Rp Copy the contents of the address in Rp to A
Mnemonic Operation
MOV A, @R0 Copy the contents of the address in RO to the A register
MOV @R1, #35h Copy the number 35h to the address in R1
MOV addr, @R0 Copy the contents of the address in RO to addr
MOV @R1, A Copy the contents of A to the address in R1
MOV @R0, 80h Copy the contents of the port 0 pins to the address in R0
Registers R0. R1, and the DPTR can be used to hold the address of the data byte in
external RAM.
R0 and R1 are limited to external RAM address ranges of 00h to 0FFh, while the DPTR
register can address the RAM space of 0000h to 0FFFFh.
An X is added to the MOV mnemonics to serve as a reminder that the data move is external to
the 8051
Mnemonic Operation
MOVX A, @Rp Copy the contents of the external address in Rp to A
MOVX A, @DPTR Copy the contents of the external address in DPTR to A
MOVX @Rp, A Copy data from A to the external address in Rp
MOVX @DPTR, A Copy data from A to the external address in DPTR
Mnemonic Operation
MOVX @DPTR, A Copy data from A to the 16-bit address in DPTR
MOVX@R0, A Copy data from A to the 8-bit address in R0
MOVXA, @R1 Copy data from the 8-bit address in R1 to A
MOVX A, @DPTR Copy data from the 16-bit address in DPTR to A
Data moves between RAM locations and 8051 registers are made by using MOV and MOVX
opcodes. The data is usually of a temporary or "scratch pad" nature and disappears when
the system is powered down.
There are times when access to a preprogrammed mass of data is needed, such as when
using tables of predefined bytes. This data must be permanent to be of repeated use and is
stored in the program ROM.
Access to this data is made possible by using indirect addressing and the A register in
conjunction with either the PC or the DPTR.
In both cases, the number in register A is added to the pointing register to form the address
in ROM where the desired data is to be found.
The data is then fetched from the ROM address so formed and placed in the A register.
The original data in A is lost, and the addressed data takes its place.
Mnemonic Operation
Copy the code byte, found at the ROM address formed
MOVC A, @A+DPTR
by adding A and the DPTR, to A
Copy the code byte, found at the ROM address formed
MOVC A, @A+PC
by adding A and the PC, to A
Mnemonic Operation
MOV DPTR, #1234h Copy the immediate number 1234h to the DPTR
MOV A, #56h Copy the immediate number 56h to A
MOVC A, @A+DPTR Copy the contents of address 128Ah to A
Copies the contents of address 4059h to A if the PC
MOVC A, @A+PC contained 4000h and A contained 58h when the opcode
is executed
The PC is incremented by one (to point to the next instruction) before it is added to A to form
the final address of the code byte.
All data is moved from the code memory to the A register.
MOVC is normally used with internal or external ROM and can address 4K of internal or 64K
bytes of external code.
28 DEPT. OF ELECTRONICS & COMMUNICATION E N G G . |M I T M Y S O R E
MICROCONTROLLER | MODULE2:8051 INSTRUCTION SET 18EC46
The PUSH and POP opcodes specify the direct address of the data.
The data moves between an area of internal RAM, known as the stack, and the specified direct
address.
The stack pointer special-function register (SP) contains the address in RAM where data from the
source address will be PUSHed, or where data to be POPed to the destination address is found.
The SP register actually is used in the indirect addressing made but is not named in the mnemonic.
It is implied that the SP holds the indirect address whenever PUSHing or POPing.
A PUSH opcode copies data from the source address to the stack.
SP is incremented by one before the data is copied to the internal RAM location contained in SP so
that the data is stored from low addresses to high addresses in the internal RAM.
The stack grows up in memory as it is PUSHed. Excessive PUSHing can make the stack exceed
7Fh (the top of internal RAM), after which point data is lost.
A POP opcode copies data from the stack to the destination address.
SP is decremented by one after data is copied from the stack RAM address to the direct destination
to ensure that data placed on the stack is retrieved in the same order as it was stored.
MOV, PUSH, and POP opcodes all involve copying the data found in the source address to the
destination address; the original data in the source is not changed.
Exchange instructions actually move data in two directions: from source to destination and
from destination to source.
All addressing modes except immediate may be used in the XCH (exchange) opcodes
Arithmetic instructions
The 8051 can perform addition, subtraction. Multiplication and division operations on 8 bit numbers.
The 24 arithmetic opcodes are grouped into as follows
Mnemonic Operation
Example 2-8
Assume that RAM locations 40 – 44H have the following values.
Write a program to find the sum of the values. At the end of the program, register A
should contain the low byte and R7 the high byte.
40 = (7D) | 41 = (EB) | 42 = (C5) | 43 = (5B) | 44 = (30)
Solution:
MOV R0,#40H ;load pointer
MOV R2,#5 ;load counter
CLR A ;A=0
MOV R7,A ;clear R7
AGAIN: ADD A,@R0 ;add the byte ptr to by R0
JNC NEXT ;if CY=0 don’t add carry
INC R7 ;keep track of carry
NEXT: INC R0 ;increment pointer
DJNZ R2,AGAIN ;repeat until R2 is zero
Example 2-9
Write a program to add two 16-bit numbers. Place the sum in R7 and R6;
R6 should have the lower byte.
Solution:
CLR C ;make CY=0
MOV A, #0E7H ;load the low byte now A=E7H
ADD A, #8DH ;add the low byte
MOV R6, A ;save the low byte sum in R6
MOV A, #3CH ;load the high byte
ADDC A, #3BH ;add with the carry
MOV R7, A ;save the high byte sum
The binary representation of the digits 0 to 9 is called BCD (Binary Coded Decimal)
Unpacked BCD
In unpacked BCD, the lower 4 bits of the number represent the BCD number, and the rest
of the bits are 0
• Ex. 00001001 and 00000101 are unpacked BCD for 9 and 5
Packed BCD
In packed BCD, a single byte has two BCD number in it, one in the lower 4 bits, and one in
the upper 4 bits
• Ex. 0101 1001 is packed BCD for 59H
32 DEPT. OF ELECTRONICS & COMMUNICATION E N G G . |M I T M Y S O R E
MICROCONTROLLER | MODULE2:8051 INSTRUCTION SET 18EC46
MOV A, #17H
ADD A, #28H
The result above should have been 17 + 28 = 45 (0100 0101).
To correct this problem, the programmer must add 6 (0110) to the
low digit: 3F + 06 = 45H.
DA Instruction
DA A ;decimal adjust for addition
The DA instruction is provided to correct the aforementioned problem associated with BCD
addition
The DA instruction will add 6 to the lower nibble or higher nibble if need
Example:
MOV A,#47H ;A=47H first BCD operand
MOV B,#25H ;B=25H second BCD operand
ADD A,B ;hex(binary) addition(A=6CH)
DA A ;adjust for BCD addition(A=72H)
Summary of DA instruction
After an ADD or ADDC instruction
If the lower nibble (4 bits) is greater than 9, or if AC=1, add 0110 to the lower 4 bits
If the upper nibble is greater than 9, or if CY=1, add 0110 to the upper 4 bits
Example 2-10
Assume that 5 BCD data items are stored in RAM locations starting at 40H, as shown below.
Write a program to find the sum of all the numbers. The result must be in BCD.
40=(71) | 41=(11) | 42=(65) | 43=(59) | 44=(37)
Solution:
MOV R0,#40H ;Load pointer
MOV R2,#5 ;Load counter
CLR A ;A=0
MOV R7,A ;Clear R7
AGAIN: ADD A,@R0 ;add the byte pointer to by R0
DA A ;adjust for BCD
JNC NEXT ;if CY=0 don’t accumulate carry
INC R7 ;keep track of carries
NEXT: INC R0 ;increment pointer
DJNZ R2,AGAIN ;repeat until R2 is 0
SUBB when CY = 0
Take the 2’s complement of the subtrahend (source operand)
Add it to the minuend (A)
Invert the carry
CLR C
MOV A,#4CH ;load A with value 4CH
SUBB A,#6EH ;subtract 6E from A
JNC NEXT ;if CY=0 jump to NEXT
CPL A ;if CY=1, take 1’s complement
INC A ;and increment to get 2’s comp
NEXT: MOV R1,A ;save A in R1
Solution:
4C 0100 1100 0100 1100
- 6E 0110 1110 1001 0010
-22 01101 1110
SUBB when CY = 1
This instruction is used for multi-byte numbers and will take care of the borrow of the lower operand
Example 2-11
Write a program to get hex data in the range of 00 – FFH from port 1 and convert it to
decimal. Save it in R7, R6 and R5.
Solution:
MOV A, #0FFH
MOV P1, A ;make P1 an input port
MOV A, P1 ;read data from P1
MOV B, #10 ;B=0A hex
DIV AB ;divide by 10
MOV R7, B ;save lower digit
MOV B, #10
DIV AB ;divide by 10 once more
MOV R6, B ;save the next digit
MOV R5, A ;save the last digit
Logical instructions
A large part of machine control concerns sensing the on-off states of external switches,
making decisions based on the switch states, and then turning external circuits on or off.
Sensing and control implies a need for byte and bit opcodes that operate on data using
Boolean operators.
All 8051 RAM areas, both data and SFRs, may be manipulated using byte opcodes.
Many of the SFRs, and a unique internal RAM area that is bit addressable, may be operated
upon at the individual bit level.
Bit operators are notably efficient when speed of response is needed.
Bit operators yield compact program code that enhances program execution speed.
The XRL instruction can be used to clear the contents of a register by XORing it with
itself.
Show how XRL A, A clears A, assuming that AH = 45H.
45H 0100 0101
45H 0100 0101
00H 0000 0000
Example 2:12
Read and test P1 to see whether it has the value 45H. If it does, send 99H to P2;
otherwise, it stays cleared.
Solution: XRL can be used to
MOV P2,#00 ;clear P2 see if two registers
MOV P1,#0FFH ;make P1 an input port have the same value
MOV R3,#45H ;R3=45H
MOV A,P1 ;read P1
XRL A,R3
JNZ EXIT ;jump if A is not 0 If both registers have
MOV P2,#99H the same value, 00 is
EXIT: ... placed in A. JNZ and
JZ test the contents of
the accumulator.
MOV A, #56H
CPL A ;now A=A9H
;0101 0110(56H)
;becomes 1010 1001(A9H)
To get the 2’s complement, all we have to do is to add 1 to the 1’s complement
Example 2 – 13
Write a program to read the temperature and test it for the value 75.
According to the test results, place the temperature value into the registers indicated by
the following.
If T = 75 then A = 75
If T < 75 then R1 = T
If T > 75 then R2 = T
Solution:
MOV P1,#0FFH ;make P1 an input port
MOV A,P1 ;read P1 port
CJNE A,#75,OVER;jump if A is not 75
SJMP EXIT ;A=75, exit
OVER: JNC NEXT ;if CY=0 then A>75
MOV R1,A ;CY=1, A<75, save in R1
SJMP EXIT ; and exit
NEXT: MOV R2,A ;A>75, save it in R2
EXIT: ...
RR A ; rotate right A
In rotate right
The 8 bits of the accumulator are rotated right one bit, and
Bit D0 exits from the LSB and enters into MSB, D7
RL A ; rotate left A
In rotate left
The 8 bits of the accumulator are rotated left one bit, and
Bit D7 exits from the MSB and enters into LSB, D0
CLR C ;make CY = 0
MOV A,#26H;A = 0010 0110
RRC A ;A = 0001 0011 CY = 0
RRC A ;A = 0000 1001 CY = 1
RRC A ;A = 1000 0100 CY = 1
Example 2- 14
Write a program that finds the number of 1s in a given byte.
MOV R1,#0
MOV R7,#8 ;count=08
MOV A,#97H
AGAIN: RLC A
JNC NEXT ;check for CY
INC R1 ;if CY=1 add to count
NEXT: DJNZ R7,AGAIN
SWAP A
It swaps the lower nibble and the higher nibble
In other words, the lower 4 bits are put into the higher 4 bits and the higher 4 bits are put into
the lower 4 bits
SWAP works only on the accumulator (A)
Example 2- 15
(a) Find the contents of register A in the following code.
(b) In the absence of a SWAP instruction, how would you exchange the nibbles?
Write a simple program to show the process.
Solution:
(a)
MOV A,#72H ;A = 72H
SWAP A ;A = 27H
(b)
MOV A,#72H ;A = 0111 0010
RL A ;A = 1110 0100
RL A ;A = 1100 1001
RL A ;A = 1001 0011
RL A ;A = 0010 0111
Example 2 - 16 Assume that register A has packed BCD, write a program to convert
packed BCD to two ASCII numbers and place them in R2 and R6.
Solution:
MOV A,#29H ;A=29H, packed BCD
MOV R2,A ;keep a copy of BCD data
ANL A,#0FH ;mask the upper nibble (A=09)
ORL A,#30H ;make it an ASCII, A=39H(‘9’)
MOV R6,A ;save it
MOV A,R2 ;A=29H, get the original data
ANL A,#0F0H ;mask the lower nibble
RR A ;rotate right
RR A ;rotate right
RR A ;rotate right SWAP A
RR A ;rotate right
ORL A,#30H ;A=32H, ASCII char. ’2’
MOV R2,A ;save ASCII char in R2
Branch instructions
Repeating a sequence of instructions a certain number of times is called a loop.
Loop action is performed by DJNZ reg, Label
• The register is decremented by one
• If it is not zero, it jumps to the target address referred to by the label
• Prior to the start of loop the register is loaded with the counter for the number of
repetitions
• Counter can be R0 – R7 or RAM location
Example 2 – 17
Write a program to
(a) load the accumulator with the value 55H, and
(b) complement the ACC 700 times
MOV A,#55H ;A=55H
MOV R3,#10 ;R3=10, outer loop count
NEXT: MOV R2,#70 ;R2=70, inner loop count
AGAIN: CPL A ;complement A register
DJNZ R2,AGAIN ;repeat it 70 times
DJNZ R3,NEXT
Conditional Jumps
Example 2 – 18
Find the sum of the values 79H, F5H, E2H. Put the sum in registers R0 (low byte) and
R5 (high byte).
MOV A,#0 ;A=0
MOV R5,A ;clear R5
ADD A,#79H ;A=0+79H=79H
JNC N_1 ;if CY=0, add next number
INC R5 ;if CY=1, increment R5
N_1: ADD A,#0F5H ;A=79+F5=6E and CY=1
JNC N_2 ;jump if CY=0
INC R5 ;if CY=1,increment R5 (R5=1)
N_2: ADD A,#0E2H ;A=6E+E2=50 and CY=1
JNC OVER ;jump if CY=0
INC R5 ;if CY=1, increment 5
OVER: MOV R0,A ;now R0=50H, and R5=02
Example 2 – 19
Program using JNB and JBC instructions.
LOOP: MOV A,#10h ; A = 10h
MOV R0,A ;RO = 10h
ADDA: ADD A,R0 ;add RO to A
JNC ADDA ;if the carry flag is 0, then ‘no
;carry’(NC) is true
;jump to address ADDA
;jump until A is F0h
;C flag is set on the next ADD & ‘no
;carry’(NC) is false
; do the next instruction
Unconditional Jumps
The unconditional jump is a jump in which control is transferred unconditionally to the target
location.
Unconditional jumps do not test any bit or byte to determine whether the jump should be taken.
The jump is always taken.
1. Write a program to add the values of locations 50H and 51H and store the result in locations
in 52h and 53H.
2. Write a program to store data FFH into RAM memory locations 50H to 58H using direct
addressing mode
3. Write a program to subtract a 16 bit number stored at locations 51H-52H from 55H-56H
and store the result in locations 40H and 41H. Assume that the least significant byte of data
or the result is stored in low address. If the result is positive, then store 00H, else store 01H
in 42H.
4. Write a program to add two 16 bit numbers stored at locations 51H-52H and 55H-56H and
store the result in locations 40H, 41H and 42H. Assume that the least significant byte of
data and the result is stored in low address and the most significant byte of data or the
result is stored in high address.
5. Write a program to store data FFH into RAM memory locations 50H to 58H using indirect
addressing mode.
6. Write a program to add two Binary Coded Decimal (BCD) numbers stored at locations
60H and 61H and store the result in BCD at memory locations 52H and 53H. Assume that
the least significant byte of the result is stored in low address.
8. Write a program to compute 1 + 2 + 3 + N (say N=15) and save the sum at70H
9. Write a program to multiply two 8 bit numbers stored at locations 70H and 71H and store
the result at memory locations 52H and 53H. Assume that the least significant byte of the
result is stored in low address.
10. Write a program to find the average of five 8 bit numbers. Store the result in 55H. (Assume
that after adding five 8 bit numbers, the result is 8 bit only).
ORG 0000H
MOV 40H,#05H
MOV 41H,#55H
MOV 42H,#06H
MOV 43H,#1AH
MOV 44H,#09H
MOV R0,#40H
MOV R5,#05H
MOV B,R5
CLR A
Loop: ADD A,@R0
INC R0
DJNZ R5,Loop
DIV A B
MOV 55H,A
END
11. Write a program to find the cube of an 8 bit number program is as follows
ORG 0000H
MOV R1,#N
MOV A,R1
MOV B,R1
MUL A B
MOV R2, B
MOV B, R1
MUL A B
MOV 50,A
MOV 51,B
MOV A,R2
MOV B, R1
MUL AB
ADD A, 51H
MOV 51H, A
MOV 52H, B
MOV A, #00H
ADDC A, 52H
MOV 52H, A
END
12. Write a program to exchange the lower nibble of data present in external memory 6000H
and 6001H
13. Write a program to count the number of and o's of 8 bit data stored in location 6000H.
15. Two 8 bit numbers are stored in location 1000h and 1001h of external data memory. Write
a program to find the GCD of the numbers and store the result in 2000h.
ALGORITHM
Step 1 :Initialize external data memory with data and DPTR with address
Step 2 :Load A and TEMP with the operands
Step 3 :Are the two operands equal? If yes, go to step 9
Step 4 :Is (A) greater than (TEMP) ? If yes, go to step 6
Step 5 :Exchange (A) with (TEMP) such that A contains the bigger number
Step 6 :Perform division operation (contents of A with contents of TEMP)
Step 7 :If the remainder is zero, go to step 9
Step 8 :Move the remainder into A and go to step 4
Step 9 :Save the contents 'of TEMP in memory and terminate the program
****************************************************************************************