Status: Tags: #cards/cmpt295/assembly Links: x86-64 Assembly - Arrays
x86-64 Assembly Arrays
Principles
1D Arrays
? Remember differences of array cells differ by size of data, not just 1!
- No arrays, just access by displacement of main pointer
- `A[i] => A + i * L
A
is base memory/address of first pointi
is index of arrayL
is sizeof(T)
Accessing memory address ?
- these operations give you the same memory address:
x + 1
,&x[1]
Accessing a value ?
- these operations give you the same value:
x[4]
,*(x+4)
Allow for quick indexing with memory address indexing via movq (%array start, index, char size), %register you want to save to
How to only let loop iterate while i<n ?
|
|
Adding all elements of a char array (version 1):
- Storage
%rdi
contains starting address%esi
contains size (N)%ecx
contains array index%al or %ax
contains running sum
- Jump if end of array via top jmp
Jump to end, have condition at the end to jump back if not end of array
2D Arrays
Access row i of a 2d array
?
A + (R * C * L)
Access row i col j of a 2d array ?
A + (i * C + j) * L
or can distributeL
- C is number of columns
A[R][C]
- i is row index
- j is col ind
References:
Created:: 2022-03-19 04:01