Question: i have this code is code in assembly but when I debug its giving me this error in this line: mov r 9 w ,

i have this code is code in assembly but when I debug its giving me this error in this line: mov r9w,[rdx + r8*2]
here is the code:
average_volume PROTO
.data
.code
average_volume PROC
; RCX is the pointer to the block
; RDX is the size of the block
; Setting rax to 0 for clearer readibility when viewing process
mov rax, 0
; Exchanging value so that I can use the loop instruction
xchg rdx, rcx
; RDX is know the pointer to the block and RCX the size, to begin a loop instruction
; R8 is an index of the position being modified or used in the traversal of the array
; starts at 0 and ends at n -1
mov r8,0
; The size of each block is limited to 65536, for the purpose of this code it is more
; than enough, since each block is of size 2205 or less
mov r10, rcx
; Summing the absolutes values of the entire block
L1:
; Grabbing the value at the [r8]th positon from memory
mov r9,0
; this line is giving an error of access violation!!!!!!
mov r9w,[rdx + r8*2]
; Checking if the value is negative, we only want positive values
cmp r9w,0
jl abs
end_abs:
; R9 should now have the absolute values of the entire block
add rax, r9
inc r8
loop L1
; Computing average of block, separating the dividend into dx:ax for proper use of division function
; This is done since eax, contains the result of the sum of the absolute values of all values
; in the block, and we need the average
mov cx, ax
shr rax, 16
mov dx, ax
mov ax, cx
div r10w
ret
; If it is negative convert to a positive value
abs:
neg r9w
jmp end_abs
average_volume ENDP
END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!