I've tried to write a program that perform multiplications, using shl.
This code should multiply any numbers from 0 to 255 for n factors, but doesn't work: lcs is repeated twice and the result is wrong.
max TEXTEQU <100>
.data
p0 BYTE "Inserisci il primo fattore: ", 0
p1 BYTE "Inserisci l'altro fattore: ", 0
p2 BYTE "Vuoi inserire un altro fattore?[s/n]: ", 0
fattori BYTE max dup(0)
shift BYTE 7 dup(0)
.code
MAIN PROC
mov esi, offset fattori
mov edx, offset p0
call WriteString
call ReadInt
call Crlf
mov [esi], eax
inc esi
mov edx, offset p1
call WriteString
call ReadInt
call Crlf
mov [esi], eax
lr:
inc esi
mov edx, offset p2
call WriteString
call ReadInt
mov [esi], eax
call Crlf
cmp [fattori + lengthof fattori], 1
call MOL
cmp al, "s"
je lr
call MOL
mov eax, [esi]
call WriteInt
mov esi, offset fattori
mov ecx, 100
call DumpMem
exit
MAIN ENDP
MOL PROC
mov ecx, esi
sub ecx, offset fattori
dec ecx
mov esi, offset fattori
inc esi
l1:
push ecx
mov ecx, 7
mov al, [esi - 1]
mov bh, [esi]
shr bh, 1
jnc lcs
mov bl, 1
lcs:
mov bh, [esi]
cmp ecx, 0
je lal
dec ecx
shr bh, 1
jnc lcs
mov [shift + ecx], 1
inc ecx
loop lcs
lal:
call DumpRegs
mov ecx, 7
ls:
push ecx
mov cl, [shift + ecx]
shl al, cl
pop ecx
loop ls
mov [esi], al
inc esi
cmp bl, 1
jne lll
mov edx, [esi]
add edx, [esi - 1]
mov [esi], edx
lll:
pop ecx
loop l1
lret:
ret
MOL ENDP
END MAIN