.model small .stack 64 .DATA number1 db 20 dup(55h) number2 db 20 dup (55h) result_with_mul db 20 dup (55h) result_without_mul db 20 dup (55h) msg1 db 'pls enter the first number with 2 digits: $ ',0ah,0dh msg2 db 0ah,0dh,'pls enter the second number with 2 digits: $ ',0ah,0dh msg3 db 'conclusion: results with and without mul are equal $' msg4 db ' conclusion: results with and without mul are not equal $' ;msg5 db 'error you have enter not what u need to pls try again $'
.CODE
begin proc far mov ax,@data mov ds,ax mov es,ax lea di,number1 push di lea di,number2 lea dx,msg1 push dx call disp_msg call get_2_digits lea dx,msg2 push dx call disp_msg call get_2_digits call with_mul call without_mul cmp al,dl je msg_equal jne msg_not_equal msg_equal: lea cx,msg3 push cx
&nbs p;
&n bsp;
call disp_msg msg_not_equal: lea cx,msg4 push cx call disp_msg mov ax,4c00h int 21h begin endp ;-------------------------------------
disp_msg proc push bp mov bp,sp push dx mov dx,[bp+4] call print pop dx pop bp ret 2
disp_msg endp ;------------------------------------------ print proc mov ah,09h int 21h ret print endp ;-------------------------------------------- get_1_digit proc near again: call get_char cmp al,'0' ; check if digit jl again
cmp al,'9' ;filter 4 digits jg again sub al,30h ;de-ascii ret get_1_digit endp ;--------------------------------------------- get_2_digits proc near ;convert 2 ascii digits into number -->bl push ax call get_1_digit shl al,1 ;*2 mov bl,al ;save shl al,1 ;*4 shl al,1 ;*8 add bl,al ;10 call get_1_digit add bl,al pop ax ret get_2_digits endp ;------------------------ get_char proc ; mov ah,1 int 21h ret get_char endp ;------------------------ ;_____________________________
with_mul proc
push bp
mov & nbsp; bp, sp
&n bsp;
;Another stack pointer besides sp
push dx ;Saving the current values
of the registers push si
xor & nbsp; bx,
bx ;Prepering place for the result
mov & nbsp; si,
[bp+4] ;Reading data from the stack
mov & nbsp; al,
[si] ;The value of the multiplicant inc si
mov & nbsp; dh,
al ;Copy of the multiplicant
mov & nbsp; ah,
[si] ;The value of the multiplier
mov & nbsp; dl,
-1 ;In dl the place of each bit is been saved
mov & nbsp; cx,
8 ;The length of one byte
next_bit:
shr & nbsp;
al, &n bsp; 1 ;Saving the
place of each bit in order to know the "weight" of it
inc & nbsp;
dl ;Pl ace 0 = weight 1, place 1 = weight 2,
place 2 = weight 4 etc
jc &n bsp; &nbs p;
multi ;If the carry fleg is '1' binary we have to add the
bit's weight to the result
loop next_bit
jmp & nbsp; skip ;Reaching to this
line only when the loop ends
multi: ;Result=(weight*multiplier)+re sult
push ax; Saving the current
value of ax
mov & nbsp; al,
ah ;Duplicate of the multiplier xor ah, ah
push cx ;Saving the counter of
the external loop
mov cl, dl
shl & nbsp;
ax, &n bsp; cl ;Temporary result
=(weight*multiplier)!!!
add & nbsp; bx, ax
;In the end of the loop the result will be saved in bx pop cx pop ax
loop next_bit
skip: ;This part calculate the result by using the mul function
mov & nbsp; al,
dh ;dh=the value of the multiplier
mul & nbsp; ah ;The multiplier
is already exist at al (result=al*ah=ax)!!!
pop si
pop & nbsp;
dx ;Cl eaning the stack pop bp ret with_mul endp
;----------------------------------
without_mul proc ;Building the tens digit by multiplying – (origin digit)*10
mov & nbsp; bl,
al ;duplicating the origin digit
shl & nbsp;
bl, &n bsp; 1 ;(The origin digit)*2
push cx ;saving the current value of
the external loop mov cl, 3 shl al, cl ;(The origin digit)*8
add & nbsp; bl,
al ;The result saved in bl pop cx ret without_mul endp ;-----------------------------------
end
|