0% found this document useful (0 votes)
311 views37 pages

Assembly Language Programming (ALP) 8086: Presented by M.Suma Kgrcet

The document discusses Assembly Language Programming (ALP) using the 8086 processor. It presents 14 programs demonstrating various operations like incrementing, decrementing, complementing 8-bit and 16-bit numbers, adding, subtracting, multiplying and dividing two numbers. It also discusses procedures, macros, stack operations and string manipulation in assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
311 views37 pages

Assembly Language Programming (ALP) 8086: Presented by M.Suma Kgrcet

The document discusses Assembly Language Programming (ALP) using the 8086 processor. It presents 14 programs demonstrating various operations like incrementing, decrementing, complementing 8-bit and 16-bit numbers, adding, subtracting, multiplying and dividing two numbers. It also discusses procedures, macros, stack operations and string manipulation in assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Assembly

Language
Programming(ALP)
Presented

8086
by
M.Suma
kgrcet
Program 1: Increment an 8-bit
number
• MOV AL, Move 8-bit data to
05H AL. Increment AL.
• INC AL
Program 2: Increment an 16-bit
number
• MOV AX, Move 16-bit data to
0005H AX. Increment AX.
• INC AX
Program 3: Decrement an 8-bit
number
• MOV AL, Move 8-bit data to
05H AL. Decrement AL.
• DEC AL
Program 4: Decrement an 16-bit
number
• MOV AX, Move 16-bit data to
0005H AX. Decrement AX.
• DEC AX
Program 5: 1’s complement of an 8-bit
number.
• MOV AL, Move 8-bit data to
05H AL. Complement AL.
• NOT AL
Program 6: 1’s complement of a 16-
bit number.
• MOV AX, Move 16-bit data to
0005H AX. Complement
• NOT AX AX.
Program 7: 2’s complement of an 8-bit
•number.
MOV AL, Move 8-bit data to
05H AL. Complement AL.
• NOT AL Increment AL
• INC AL
Program 8: 2’s complement of a 16-
bit number.
• MOV AX, Move 16-bit data to
0005H AX. Complement
• NOT AX AX. Increment AX
• INC AX
Program 9: Add two 8-bit
numbers
MOV AL, Move 1 8-bit number to
st

05H MOV AL. Move 2 8-bit number


nd

BL, 03H ADD to BL. Add BL with AL.


AL, BL
Program 10: Add two 16-bit
numbers
MOV AX, Move 1 16-bit number to
st

0005H MOV AX. Move 2 16-bit number


nd

BX, 0003H ADD to BX. Add BX with AX.


AX, BX
Program 11: subtract two 8-bit
numbers
MOV AL, Move 1 8-bit number to
st

05H MOV AL. Move 2 8-bit number


nd

BL, 03H SUB to BL. subtract BL from


AL, BL AL.
Program 12: subtract two 16-bit
numbers
MOV AX, Move 1 16-bit number to
st

0005H MOV AX. Move 2 16-bit number


nd

BX, 0003H SUB to BX.


AX, BX subtract BX from AX.
Program 13: Multiply two 8-bit unsigned
numbers.
MOV AL, Move 1st 8-bit number to
04H MOV Move AL. 8-bit number
BL, 02H MUL 2nd
Multiply BLtowith
BL. AL and the result
BL will
be in AX.
Program 14: Multiply two 8-bit
signed numbers.
MOV AL, Move 1st 8-bit number to
04H MOV Move 2nd AL. 8-bit number
BL, 02H to BL.BL with AL and the
Integer Multiply
IMUL BL result will be in AX.
Program 15: Multiply two 16-bit
unsigned numbers.
MOV AX, Move 1st 16-bit number to
0004H MOV Move AL. 16-bit number
BX, 0002H MUL 2nd
Multiply to with
BX BL. AX and the result
BX will
be in DX:AX {4*2=0008=> 08=> AX , 00=>
DX}
Program 16: Divide two 16-bit
unsigned
MOV AX, numbers.
Move 1 16-bit number to
st

0004H MOV Move 2nd AL. 16-bit number


BX, 0002H DIV Divide BX from to and the result will be in AX &
AXBL.
BX DX
{4/2=0002=> 02=> AX ,00=>DX}
(ie: Quotient => AX , Reminder =>
DX )
Detailed coding
16 BIT
ADDITION
Detailed coding
16 BIT
SUBTRACTION
16 BIT
MULTIPLICATION
16 BIT
DIVISION
SUM of N-numbers
MOV
AX,0000
MOV SI,1100
DI,1200
MOV CX,0005 5 NUMBERSTO BE TAKEN as SUM
MOV
DX,0000
L1: ADD AX,
[SI] INC SI
INC DX CMP
CX,DX JNZ
L1
MOV [1200],AX HLT
Average
MOV
of N-numbers
AX,0000
MOV SI,1100
DI,1200
MOV CX,0005 5 NUMBERSTO BE TAKEN
asAVERAGE
MOV
DX,0000
L1: ADD AX,
[SI] INC SI
INC DX CMP
CX,DX JNZ
L1 AX=AX/5(AVERAGE OF 5
DIV CX NUMBERS)
MOV [1200],AX HLT
FACTORIAL of
N MOV Factorial=5*4*3*2*1=120
MOV CX,0005 5

DX,0000
MOV
AX,0001
L1: MUL CX
DEC DX
CMP CX,DX
JNZ L1
MOV [1200],AX HLT
ASCENDING
ORDER
DECENDING
ORDER

Note: change the coding JNB into JB in the LINE


L1 L1 10
LARGEST, smallest NUMBER IN AN
ARRAY
LARGEST
NUMBER
SMALLEST
NUMBER
Byte Manipulation(Using Logical
Instructions ){ex:
AND,OR,NOT,XOR}
Example 1: Example 3:
MOV AX, MOV AX,[1000]
[1000] MOV
MOV BX,
BX,[1002]
[1002] XOR
AND AX,BX
MOV AX,BX MOV
[2000],AX HLT [2000],AX HLT
Example 2: Example 4:
MOV AX, MOV AX,[1000]
[1000] MOV
NOT AX
BX,[1002] OR
AX,BX MOV
MOV [2000],AX
[2000],AX HLT HLT
STRING
1.MANIPULATION
Copying a string (MOV
)
SBMOV copy 3 memory
CX,0003 locations
MOV SI,1000
MOV DI,2000
L1 CLD
MOV decrement
SB DEC CX
CX JNZ
Presented by C.GOKUL,AP/EEE, Velalar College of Engg &
2. Find &
Replace
Procedure
s
• Procedure is a part of code that can be called
from your program in order to make some
specific task. Procedures make program more
structural and easier to understand.
• syntax for procedure
declaration:
name PROC
……… ; here goes the
…. code
RET ……… ; of the
…. procedure ...
name ENDP
here PROC is the procedure name.(used in top &
bottom) RET - used to return from OS. CALL-call a
procedure PROC & ENDP – complier directives
CALL & RET - instructions
EXAMPLE 1 (call a
ORGprocedure)
100h
CALL m1
MOV AX,
2
RET ;
m1 PROC
return
MOV BX,to
operating
5 RET ; return to
system. caller.
m1
ENDP
• The
END above example calls procedure m1, does
MOV BX, 5 & returns to the next
instruction after CALL: MOV AX, 2.
Example 2 : several ways to pass
parameters to procedure
ORG 100h
MOV AL, 1
MOV BL,
2 CALL
m2
CALL m2
CALL
m2
CALL
m2
RET PROC ; AX = AL * BL.
MUL BL ; return to
; return to caller.
RET
operating value of AL register is update every time
m2
system. the procedure is called.
ENDP final result in AX register is 16 (or 10h)
• Stack is an area of memory for keeping
temporary data.
• STACK is used by CALL & RET
instructions. PUSH -stores 16 bit value
in the stack. POP -gets 16 bit value
from the stack.
• PUSH and POP instruction are especially useful
because we don't have too much registers to
operate
1. Store original value of the register in stack
(using PUSH).
2. Use the register for any purpose.
3. Restore the original value of the register from
stack (using POP).
Example-1 (store value in STACK
using PUSH & POP)
ORG 100h
MOV AX,
1234h
PUSH AX ; store value of AX in
MOV AX, stack.
5678h
POP ; restore; modify the AX
the original value.
value of
AX RET AX.
END

Presented by
Example 2: use of the stack is
for exchanging the values
ORG
MOV
100h AX, ; store 1212h in AX.
1212h MOV ; store 3434h in BX
BX, 3434h ; store value of AX in
PUSH AX stack.
PUSH BX ; store value of BX in
POP stack.
AX ; set AX to original value of BX.
POPBX ; set BX to original value of AX.
RET
push 1212h and then 3434h, on pop we will
END first get 3434h and only after it 1212h
MACRO
S
• Macros are just like procedures, but not
really.
• Macros exist only until your code is compiled
• After compilation all macros are replaced
with real instructions
• several macros to make coding
easier(Reduce large & complex programs)
Example (Macro definition)
name MACRO [parameters,...]
<instructions
> ENDM
Example1 : Macro
SAVDefinitions
MACRO definition of MACRO name
SAVE
E PUSH
AX
PUSH
BX
PUSH
RETREI MACRO
CX Another definition of MACRO name
RETREIVE
VE POP
ENDM
CX POP
BX POP
AX
ENDM
MACROS with
Parameters
Example:
COPY ; macro named COPY
MACRO x, y with 2 parameters{x,
y}
PUSH

AX MOV

AX, x
MOV

You might also like