JmanxC
JmanxC

Reputation: 387

Indirect Addressing and Arrays

section .data
matrix dw 1,2,3,4,5
       dw 6,7,8,9,10
       dw 11,12,13,14,15
       dw 16,17,18,19,20
       dw 21,22,23,24,25
;defined as word in order to be used in stack as well as ASCII representing numbers in 2 bytes(1 byte for each digit)

msg db "The smallest value in this matrix is:",10
msgL equ $-msg



section .bss


smallVal resw 2

section .text
global _start
_start:

mov edi, 0 ;will be used in order to indicate when end of matrix has been reached
mov esi,0 ; will be used to indicate when end of row has been reached

mov ecx, [matrix + edi +esi*2]

I am working on a program which takes a matrix and tries to find the smallest value in the matrix. I am very new to programming,only having started programming java for about 4 months now and am now learning ASM as well. My question is regarding indirect addressing. What would the following statement actually do [eax + edx](given any arbitrary value stored in eax and edx). According to a website I found it effectively finds the effective address, but I am not sure what this means.

Thanks

Thanks for the quick responses. My problem really lies in how indirect addressing works for registers. I have attached a code snippet to the top of this thread. My problem lies on the line mov ecx,[matrix+edi+esi*2]. I am not sure effectively what this line does.

Upvotes: 1

Views: 1348

Answers (1)

Sep Roland
Sep Roland

Reputation: 39166

The line of code

mov ecx, [matrix + edi +esi*2]

fetches an element from the array but it is wrong! Since the array has been defined as words you have to use CX in stead of ECX.

To further understand the addressing mode.
EDI controls the outer loop and will evolve in steps of 10 from 0 to 40 (stopping at 50)
ESI controls the inner loop and will cycle from 0 to 4 (stopping at 5)

Upvotes: 0

Related Questions