Given a byte string S of length l, obtain the string D of length l-1 as D(i) = S(i) * S(i+1) (each element of D is the product of two consecutive elements of S).
here is my code.
bits 32
global start
extern exit
import exit msvcrt.dll
segment data use32 class=data
s db 1, -3, 4, 7 ; declaring the string of bytes s
l equ $ - s - 1 ; compute the length of the string l - 1
d times l dw 0 ; reserve l bytes for the destination string and initialize it
segment code use32 class=code
start:
mov ecx, l
mov esi, 0
jecxz end_prog
repeat_this:
mov al, [s + esi] ; in al - the element on the esi position
mov dh, [s + esi + 1] ; in dh - the element after the esi position
imul dh ; multiplying consecutive terms
mov [d + esi], ax; put the result in d
inc esi ; incrementing esi to go to the next position
loop repeat_this
end_prog:
push dword 0
call [exit]
my question is did I make a mistake by declaring d times l dw 0
since I know that a byte * byte = word? Is everything else okay or should I pay attention to some details that I'm missing?
d
is supposed to be declared withdw
element-size, but the quoted program-description doesn't clearly say, so as far as I can tell there's no way for us to know that. Was there originally a larger explanation or some additional context that contains such information? \$\endgroup\$