REAL NUMBER MULTIPLICATION
(ASM program)

This assembly language program accepts two floating point number and produce its product. There is no option to input a negative number. If you want to find product of a negative number, you can remember this "The product of two number is negative if and only if only one of the number is negative.
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@; ;# Floating point multiplication. #; ;# Tested in Turbo Assembler, version 3.0. #; ;#--------------------------------------------------------#; ;# Note: Parameter passing through registers. #; ;!!!!!!!!!!!!!!!!!!!!!!!!12/08/2008!!!!!!!!!!!!!!!!!!!!!!!!; .8086 .MODEL SMALL .STACK .DATA CR equ 13 ; Carriage return. LF equ 10 ; Line feed. NL equ LF , CR ; New line. BS equ 8 ; Backspace. EOL equ '$' ; DOS End Of Line. WS equ ' ' ; White space. DOT equ '.' ; Period. EK equ 27 ; Escape. B equ byte ptr; O equ offset ; MAXNULEN equ 79 ; Maximum length of each number. titleMsg db NL , " FLOATING POINT MULTIPLICATION PROGRAM" db NL , " http://programs.on.googlepages.com" , EOL enterNo1 db NL , LF , "_first number_" , LF , NL , EOL enterNo2 db NL , LF , "_second number_" , LF , NL , EOL outputMsg db NL , LF , "_The product_" , LF , NL , EOL waitMsg db NL , LF , "Press any key except ESC to continue." db 3 dup(LF) , EOL ten db 10 num1Len dw ? num2Len dw ? produLen dw ? dotPosit dw 0 n1 db MAXNULEN dup(?) n2 db MAXNULEN dup(?) product db 2*MAXNULEN dup(0) db 2 dup(?) ; For dot and EOL of the product. .CODE START: Main PROC ;;;;;;;;;;;;;;; mov ax , 03h ; int 10h ; Set 25 X 80 text mode. mov ax , @DATA ; mov ds , ax ; mov es , ax ; Set data and extra segment. mov dx , O titleMsg ; call PutStr ; Display site address. mainLoop: mov dx , O enterNo1 ; call PutStr ; mov bx , O n1 ; call GetNumber ; mov num1Len , si ; Read the first number. cmp cx , 0FFFFh ; je noDotInN1 ; Check for period in the first number. ;; The number string contains period. dec num1Len ; Remove period from the number string. call DelDot ; Adjust the number length. mov dotPosit , ax ; Adjust dot position for the result. noDotInN1: ; mov cx , num1Len ; call Conv2Bin ; Convert the number string into binary string. mov dx , O enterNo2 ; call PutStr ; mov bx , O n2 ; call GetNumber ; mov num2Len , si ; Read the second number. cmp cx , 0FFFFh ; je noDotInN2 ; Check for period in the second number. ;; The number string contains period. call DelDot ; Remove period from the number string. dec num2Len ; Adjust the number length. add dotPosit , ax ; Adjust dot position for the result. noDotInN2: ; mov cx , num2Len ; call Conv2Bin ; Convert the number string into binary string. mov ax , num1Len ; add ax , num2Len ; mov produLen , ax ; Compute the maximum length of the product. call Multiply ; mov bx , O product ; xor si , si ; mov al , '0' ; mov cx , produLen ; nextChar: ; add [bx+si] , al ; inc si ; Convert the Product from loop nextChar ; binary string into character string. mov cx , dotPosit ; test cx , cx ; je intResult ; Check the result is integer or not. ;; The result is a floating point number. mov di , O product ; add di , produLen ; mov si , di ; std ; dec si ; rep movsb ; cld ; mov B[di] , DOT ; Insert the period into product. ; mov di , O product ; mov al , '0' ; mov cx , produLen ; add di , cx ; std ; repe scasb ; cld ; mov produLen , cx ; inc produLen ; inc di ; cmp B[di] , DOT ; Remove the unnecessary zeroes and period je intResult ; from the right side of the product inc produLen ; and adjust the product length. intResult: ; mov di , O product ; mov al , '0' ; mov cx , produLen ; repe scasb ; dec di ; mov si , di ; mov di , O product ; inc cx ; Remove the unnecessary zeroes from rep movsb ; the left side of the product. mov B[di] , EOL ; Set the EOL for Display. mov dx , O outputMsg; call PutStr ; mov dx , O product ; call PutStr ; Display the product. mov dx , O waitMsg ; call PutStr ; xor ah , ah ; int 16h ; cmp al , EK ; je stop ; Check user wants to coninue or stop. mov cx , 2*MAXNULEN ; mov al , 0 ; mov di , O product ; rep stosb ; xor ax , ax ; mov dotPosit , ax ; Initilize. jmp mainLoop ; Continue the multiplication. stop: mov ax , 4C00h ; int 21h ; Terminate the process normally. Main ENDP ;;;;;;;;;;;;;;; ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Convert each character of the number string to ; its corresponding binary value. ; 2. The offset of the number string is at BX (parameter1). ; . The length of the number string is at CX (parameter2). ; 3. There is no return value. ; 4. AL, CX and SI must be changed. ;----------------------------------------------------------- Conv2Bin PROC ;;;;;;;;;;; xor si , si ; mov al , '0' ; nextChar_: ; sub B[bx+si] , al ; inc si ; loop nextChar_ ; Convert character to binary. ret ; Conv2Bin ENDP ;;;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Multiply the two binary number; n1 and n2. ; 2. There is no parameter. ; 3. There is no return value. ; 4. AX, BX, CX, DX, SI and DI must be changed. ;----------------------------------------------------------- ; The main concept of the multiplication goes here. ; I am not ready to describe these concept. ; My Documentaion skill fails here. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Multiply PROC ;;;;;;;;;;; mov di , num2Len ; mov cx , produLen ; newN2Digit: ; dec di ; dec cx ; mov bx , cx ; mov dl , n2[di] ; mov si , num1Len ; xor dh , dh ; newN1Digit: ; dec si ; mov al , n1[si] ; mul dl ; add al , dh ; add al , product[bx]; div ten ; mov dh , al ; mov product[bx] , ah; dec bx ; cmp si , 0 ; jg newN1Digit ; add product[bx] , dh; cmp di , 0 ; jg newN2Digit ; ret ; Multiply ENDP ;;;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Delete the dot from the number string. ; 2. Offset of the number is at BX (parameter1). ; . Length of the number is at SI (parameter2). ; 3. Dot position is at AX (return value). ; 4. AX, CX, DI and SI must be changed. ;----------------------------------------------------------- DelDot PROC ;;;;;;;;; mov al , DOT ; mov cx , si ; mov di , bx ; repne scasb ; Searching for period. mov si , di ; mov ax , cx ; dec di ; Shift the characters rep movsb ; so that dot is removed. ret ; DelDot ENDP ;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Read a number string ( chars: 0 to 9 and a period). ; 2. Offset of the number string is at BX (parameter). ; 3. Length of the number string at SI (return value1). ; . Position of the dot is at CX (return value2). ; 4. AX, CX, DL and SI must be changed. ;----------------------------------------------------------- GetNumber PROC ;;;;;;;;;; xor si , si ; Length of the number, initialy zero. mov cx , 0FFFFh ; If CX is FFFF then there is no period. ; Otherwise CX is position of the period. nextKey: xor ah , ah ; int 16h ; read a key. cmp al , CR ; jne notCR ; Check the key is carriage return. ;; The key is a carriage return. test si , si ; je nextKey ; If the length of the number is zero cmp B[bx+si-1] , DOT; or the last char is '.', then je nextKey ; don't accept the CR key. jmp stopRead ; Otherewise stop the key reading. notCR: cmp al , BS ; jne chars ; Check the key is backspace. ;; The key is a backspace. test si , si ; If the length of the number is zero, je nextKey ; don't accept the BS key. dec si ; decrease number length by one. cmp B[bx+si] , DOT ; Check the erased character is period or not. jne dotNot ; If so, set CX is equal to FFFF to indicate that mov cx , 0FFFFh ; there is no period in the number. dotNot: ;; Erase the character and set the cursor. mov dl , al ; call PutChar ; move the cursor one step back. mov dl , WS ; call PutChar ; erase the last char with space. mov dl , BS ; call PutChar ; move the cursor one step back again. jmp nextKey ; chars: cmp si, MAXNULEN ; Check the number is at maximum length. je nextKey ; If so, Don't accept keys except BS and CR. cmp al , DOT ; jne number ; Chech the char is dot or digits. ;; The char is period. cmp cx , 0FFFFh ; Check the period is already in the number. jne nextKey ; If so, don't accept the period. mov cx , si ; Set the period flag. mov B[bx+si] , al ; Add the period to the number. inc si ; increase the length of the number. jmp print ; Go to print the period. number: cmp al , '0' ; jb nextKey ; cmp al , '9' ; Check the character is digit or not. ja nextKey ; If not, don't accept the char at all. ;; The character is a digit. mov [bx+si] , al ; Add the character to the number. inc si ; increase the length of the number. print: mov dl , al ; call PutChar ; print the character. jmp nextKey ; stopRead: ; ret ; GetNumber ENDP ;;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Display a string which ending with '$'. ; 2. The offset of the string is at DX (parameter1). ; 3. There is no return value. ; 4. The AH register must be changed. ;----------------------------------------------------------- PutStr PROC ;;;;;;;;;;;;; mov ah , 9h ; int 21h ; ret ; PutStr ENDP ;;;;;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; 1. Display a character. ; 2. The character is at DL (parameter1). ; 3. There is no return value. ; 4. The AH register must be changed. ;----------------------------------------------------------- PutChar PROC ;;;;;;;;;;;; mov ah , 02h ; int 21h ; ret ; PutChar ENDP ;;;;;;;;;;;; ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" END START ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;@ More programs: http://programs.on.googlepages.com @ ;@ Please report bugs to: programs.on@gmail.com @ ;@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!419 lines!!!@
Click here to download the executable file of this program.

Desclaimer

I am not responsible for this exe file if it causes any damages.