0

So, i've tried calculating the average of an array and it's all good with calculating the sum, but when I go on to dividing it, the EAX register doesn't change. Here is the code:

> .386 .model flat, stdcall
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> includelib msvcrt.lib extern exit: proc
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> ;declaram simbolul start ca public - de acolo incepe executia public
> start
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> ;declararea datelor .data
> 
> array db 5,21,4,6,7,11 lengtharray dw $-array sum db 0 q db 0 r db 0  
> .code start: 
> mov eax, 0 
> mov ebx,0  
> mov esi, 0 
> mov ecx, 0 
> mov al,0 
> mov cx, lengtharray
> 
> et_loop: add al, array[esi] 
> inc esi 
> loop et_loop
> 
> mov bx,lengtharray 
> div bx
> 
> 
> push 0    
> call exit
> end start
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Please tag the processor and/or the instruction set you are using – Mister Jojo Mar 21 '21 at 13:27
  • Your formatting is a mess; redo your copy/paste and put triple backticks around it instead of `>`. But it looks like you never set DX before `div`, so the upper half of the DX:AX dividend is some random garbage. It's odd that EAX doesn't change, but that could maybe be explained by it faulting? Also, you'd normally use an `equ` constant instead of a `dw`, so `mov ebx, lengtharray` didn't have to load from memory. – Peter Cordes Mar 21 '21 at 13:29

0 Answers0