How to write
Programs in an
Assembly language?
Data Transfer Instructions
Opcode Operand Description
SHLD 16-bit address Store H-L registers direct
● The contents of register L are stored into memory
location specified by the 16-bit address.
● The contents of register H are stored into the next
memory location.
● Example: SHLD 2550 H
Logical Instructions
Opcode Operand Description
STC None Set carry
● The Carry flag is set to 1.
● No other flags are affected.
● Example: STC.
2000 37 STC Set the Cy flag i.e. set
Cy=1
Arithmetic Instructions
Opcode Operand Description
ADD R Add register or memory to accumulator
M
● The contents of register or memory are added to the contents of
accumulator.
● The result is stored in accumulator.
● If the operand is memory location, its address is specified by H-L pair.
● All flags are modified to reflect the result of the addition.
● Example: ADD B or ADD M
Arithmetic Instructions
Opcode Operand Description
DAD Reg. pair Add register pair to H-L pair
● The 16-bit contents of the register pair are added to the
contents of H-L pair.
● The result is stored in H-L pair.
● If the result is larger than 16 bits, then CY is set.
● No other flags are changed.
● Example: DAD B
1) Write assembly language program to subtract the number stored in memory
location 3601H from the number stored in 3600H. Store the positive result at
location 3602H.
In 8085, the SUB instruction is used 2’s complemented method for
subtraction.
When the first operand is larger, the result will be positive.
It will not enable the carry flag after completing the subtraction.
When the result is negative, then the result will be in 2’s
complemented form and carry flag will be enabled.
We are using two numbers at location 3600H and 3601H.
When the numbers are 78H and 5DH, then the result will be (78 –
5D = 1B) and when the numbers are 23H and CFH, then the result
will be (23 – CF = 154)
Here 1 indicates the number is negative.
The actual result is 54H. It is in 2’s complemented form.
Program
Address Labels Mnemonics Comments
C000 LXI H,3600H Load initial address to get operand
C003 MOV A,M Load Acc with memory element
C004 INX H Point to next location
C005 SUB M Subtract IInd no. from Ist ( A-M) A
C006 JP escape Escape if result is positive
C00A MOV A,M If result is negative then
C00B DCX H Subtract Ist no. from IInd
C00C escape SUB M Point to previous location
C00F STA 3602H Store the positive result in memory
HLT location
Stop
2) A series of numbers are stored in memory from D001H to D010H .Write an assembly language program
to find largest number along these numbers. Store the largest number in memory location D011H.
ddress Labels Mnemonics Comments
000 LXI H,D001H Set H-L pointer to D001H
003 MVI A,00H Largest = 00H
005 MVI C,10H Set Count = 01H
007 Loop CMP M Compare with previous [Link] it greater?
008 JNC AHEAD No larger is in Acc. Goto AHEAD
00B MOV A,M Get larger no. in Acc
00C AHEAD INX H Address of next memory
00D DCR C Count = Count - 1
00E JNZ Loop Repeat if count is not equal to 0
011 MOV M,A Store Largest no in M.L.D011
012 HLT Stop
3) Write an assembly language program that multiply two 8-bit hex numbers stored in memory location
C005H and C006H. Store ttwo byte result in consecutive memory locations starting from C000H.
Address Labels Mnemonics Comments
C000 LXI H,0000H Set H-L pointer to C000H
C003 LDA C005H Set Acc =N1
C006 MOV E, A Set[E]= N1
C007 LDA C006H Set Acc =N2
C00A MVI D,00H Set[D]= 00H
C00C Loop DAD D Product = Product + N1
C00D DCR A N2=N2-1
C00E JNZ Loop Repeat, if N2 is not equal to 0
C011 SHLD C00H Store product in C000 and C001
C014 HLT Stop
▪ C005H= 04
• C006H= 03
• 04* 03 =12
• 04+04+04=12
• So C005H will increament /increase 3 times
• And C006H will decreament/decrease 3 times
4)A block of data is stored in memory from D000H to [Link] an assembly language program to shift the
data contents of the block of in reverse order, in new memory location starting at D100H.
Address Labels Mnemonics Comments
C000
LXI H,D00FH Load initial address to get operand
C003
C006 LXI D,D100H Set up DE as a pointer to destination
C008 MVI B,10H Set up B to count 16 bytes
C009
Loop MOV A, M Get data byte from memory
C00A
C00B STAX D Store data byte at destination
C00C DCX H Decrement source pointer
C00D
INX D Increment destination pointer
C010
DCR B Decrement count
JNZ Loop If not zero , go back to location
HLT Stop