Sei sulla pagina 1di 4

ASSIGNMENT 8 Title: Multiplications using shift &.

Add and successive addition


Method. LIST OF MACROS USED: 1. Msg macro m : It is used to display a message. Input : Parameter m. Output : It displays a message m using function 09H. LIST OF PROCEDURES USED : 1. Accept proc. : It is used to accet 4-digit number from the user. Input : 4 digit number. Output : 4 digit number stored in register DX. 2. Print proc : It is used to display 4-digit number. Input : 4 digit number is stored in variable ANS. Output : 4 digit number is displayed on the screen. 3. Successive proc. : - It is used to multiply two 16-bit no.s by successive addition method. Input : 2 16-bit no.s stored in variables multiplier & multiplicand. Output : Resultant product stored in variable ANS. 4. Shift add proc. : It is used to mulily two 16-bit no.s by shift and add techniques. Input : Two 16 bit no.s stored in multiplier & multiplicand. Output : Resultant product stored in ANS. ALGORITHM FOR MAIN PROCEDURE . 1. Physical initialization of data segment. 2. display menu. 3. accept choice from the user. 4. if choice = 1, jump to step 8. 5. if choice = 2, jump to step 9. 6. if choice = 3, jump to step 10. 7. display wrong option and jump to step 2. 8. call successive procedure and jump to step 2. 9. Call shiftadd procedure & jump to step 2. 10. terminate program and exit to DOS. 1) 2) 3) 4) 5) 6) 7) 8) ALGORITHM FOR MAIN PROCEDURE . initialize counter to 4 & DX to 0000. Accept a number from user. Convert ASCII to hex (if valid). Shift left DX by 4-bit places. Add the number to the register DX. Decrement counter. If count = 0, then jump to step 2. Return.

ALGORITHM FOR PRINT PROCEDURE . 1) 2) 3) 4) 5) 6) 7) 8) Initialize the variables and counters. Move the 4-digit no into some register. Rotate the register to the left by 4 bit places. Get the MSD and convert it into ASCII value. Display the digit using 02H function. Decrement the counter. If count 0, jump to step2 return

ALGORITHM FOR SUCCESSIVE PROCEDURE . 1) Call accept procedure 2) Store the 4-digit no in variable multiplier. 3) Call accept procedure. 4) Store the 4-digit number in the variable multiplicand. 5) Initialize result to 0000. 6) Add multiplicand to the result. 7) Decrement multiplier count. 8) If multiplier count 0, jump to step2 9) Pass the higher 4 digits of result to print procedure.. 10)Pass the lower 4-digits of result to print procedure/ 11)Return

ALGORITHM FOR SHIFTADD PROCEDURE . 1) 2) 3) 4) 5) 6) 7) 8) 9) Initialize variables and counters. Call accept to accept multiplier Store it in variable multiplier. Call accept procedure. Store it in some variable multiplicand. Shift left result by 1-bit. Add carry to the result. Shift left one of the numbers by 1-bit. Check if carry is present. If carry is present, add the other number to the result and also the carry. 10)If carry is not present, decrement count. 11)If count jump to step 6. 12)Pass the higher 4 digits of result to print procedure. 13)Pass the lower 4 digits of result to print procedure. 14)Return.

FLOWCHART FOR SHIFT ADD PROC

START

Initialise Variables and counter = 16

Call accept procedure

Store the no. in var multiplicand

Call accept procedure

Store the no. in var multiplier

Shift left the result by 1 bit. Add multiplier and carry to the result

Shift left multiplier by 1 bit

Is carry ?

Add multiplicand carry to the result

Decrement the counter by 1 bit

Is count = 0?

RETURN

Call print procedure (higher 4 digits)

Call print procedure (lower 4 digits)

FLOWCHART FOR SUCCESSIVE ADDITION

START

GET 1ST NUM

INIT. 2ND NUM AS COUNTER

INIT. RES=0

RES=RES+1ST

DEC COUNTER

No

IS COUNTER= 0 ?

Yes

DISPLAY RES

STOP

Potrebbero piacerti anche