Hi! I'm doing my class notes at home and I can't get it to work-out the following:
I want to output the integer result of the dot product. The code is:
;; This program calculates the dot product of two vectors
segment .data ; the data part declares initialized variables
v1 db 1,2,3,4,5,6
v2 db 5,6,7,8,9,0
msg dw 'The value of the dot product is:',0xA
len equ $-msg
segment .bss
dotprod resw 1
segment .text
global _start
_start:
mov ecx,6 ; here we initialize the count to the number of elements
sub esi,esi ; basically sets esi to 0
sub dx,dx
cont: mov al,[esi+v1] ; esi is 0 and v1 refers tot he first index of v1
mov bl,[esi+v2] ; we do the same thing to bl, we'll multiply the two
imul bl ; 8 bit multiplication consists of multiplying the argument of
;; imul and al. The result goes to ax which is 16 bits, hence 2x the size of either factor
add dx,ax ; dx holds the dot product, hence adding ax will to it adds
;; the result of the ith product
inc esi ; increments esi
loop cont ; will do it ecx times, hence 6 times
mov [dotprod],dx ; assigns the dot product to its space in memory
;; and now for output
mov eax,4
mov ebx,1
mov ecx,msg
mov edx,len ; helps end properly and avoids extra characters
int 0x80
mov eax,4
mov ebx,1
mov dword ecx,[dotprod]
mov edx, 1
int 0x80
exit:
mov eax,1
int 0x80
I only get the text message as output, the value itself doesn't show up at all.