Addition Subtraction
Total Page:16
File Type:pdf, Size:1020Kb
EXPT NO: DATE:
ADDITION & SUBTRACTION
AIM To write assembly language program for performing addition and subtraction operation of two byte numbers.
APPARATUS REQUIRED: SL.NO ITEM SPECIFICATION QUANTITY
1. Microprocessor kit 8086 kit 1 2. Power Supply +5 V dc 1 3. Keyboard 1
ALGORITHM: (i ) 16 - b i t a dd i t i o n h) Initialize the MSBs of sum to 0 i) Get the first number. j) Add the second number to the first number. k) If there is any carry, increment MSBs of sum by 1. l) Store LSBs of sum. m) Store MSBs of sum. (ii ) 16 - b i t s ub t r a ctio n f) Initialize the MSBs of difference to 0 g) Get the first number h) Subtract the second number from the first number. i) If there is any borrow, increment MSBs of difference by 1. j) Store LSBs of difference k) Store MSBs of difference. (i) Mu lti p lic a ti o n o f 16 - b i t n umb ers : a) Get the multiplier. b) Get the multiplicand c) Initialize the product to 0. d) Product = product + multiplicand e) Decrement the multiplier by 1 f) If multiplicand is not equal to 0, repeat from step (d) otherwise store the product. (ii) D i v i s io n o f 1 6 - b i t n u m b e r s . a) Get the dividend b) Get the divisor c) Initialize the quotient to 0. d) Dividend = dividend – divisor e) If the divisor is greater, store the quotient. Go to step g. f) If dividend is greater, quotient = quotient + 1. Repeat from step (d) g) Store the dividend value as remainder. FLOWCHART ADDITION SUBTRACTION
START START
SET UP COUNTER (CY) SET UP COUNTER (CARRY)
GET FIRST OPERAND GET FIRST OPERAND TO A
GET SECOND OPERAND SUBTRACT TO A SECOND OPERAND FROM MEMORY
YES A = A + B IS THERE ANY CY YES NO IS THERE COUNTER = ANY CARRY COUNTER + 1 COUNTER = COUNTER + 1 STORE THE DIFFERENCE NO
STORE THE SUM STORE THE CARRY
STORE THE CARRY STOP
STOP MULTIPLICATION DIVISION
Start Start
Load Divisor & Dividend Get Multiplier & Multiplicand
REGISTER=00 QUOTIENT = 0
DIVIDEND = DIVIDEND - DIVISOR REGISTER = REGISTER + MULTIPLICAND
QUOTIENT = QUOTIENT + 1 Multiplier=MULTIPLIER – 1
IS IS NO NO MULTIPLIER DIVIDEND < =0? DIVISIOR?
YES STORE THE RESULT YES
STORE QUOTIENT STORE REMAINDER = DIVIDEND NOW STOP STOP ADDITION PROGRAM COMMENTS
MOV CX, 0000H Reset counter CX
MOV AX,[1200] Get the first data in AX reg
MOV BX, [1202] Get the second data in BX reg
ADD AX,BX Add the contents of both the regs AX & BX and store the result in AX JNC L1 Check for carry
INC CX If carry exists, increment the CX by 1
L1 MOV [1206],CX Store the carry in CX
MOV [1204], AX Store the sum in AX
INT 3 Stop the program
SUBTRACTION PROGRAM COMMENTS
MOV CX, 0000H Reset counter CX
MOV AX,[1200] Get the first data in AX reg
MOV BX, [1202] Get the second data in BX reg
SUB AX,BX Subtract the contents of BX from AX and store the result in AX JNC L1 Check for borrow
INC CX If borrow exists, increment the CX
L1 MOV [1206],CX Store the borrow
MOV [1204], AX Store the difference
INT 3 Stop the program MULTIPLICATION
PROGRAM COMMENTS
MOV AX,[1200] Get the first data
MOV BX, [1202] Get the second data
MUL BX Multiply both
MOV [1206],AX Store the lower order product
MOV [1208],DX Store the higher order product
INT 3 Stop the program
DIVISION
PROGRAM COMMENTS
MOV AX,[1200] Get the first data (Dividend)
MOV DX, [1202] Initialize DX register with 0000h
MOV BX, [1204] Get the second data(Divisor)
DIV BX Divide the dividend by divisor
MOV [1206],AX Store the Quotient
MOV [1208],DX Store the remainder
INT 3 Stop the program OUTPUT:
ADDITION- With carry/without carry
input output
MEMORY
DATA
SUBTRACTION-with borrow/without borrow
MEMORY
DATA
MULTIPLICATION
MEMORY
DATA
DIVISON
MEMORY
DATA
RESULT: