Higher dimensions Assume that we want to remember the multiplication table in memory.. Multiplication table Declaring the table: Filling in the table: mov esi,mul_tbl ; cell ptr
Trang 1Memory Ideas
Assembly language programming
Trang 3The memory is not just bytes
Don’t let it limit your thinking
little bytes
Trang 4section '.bss' readable writeable
my_dogs db NUM_DOGS*sizeof.DOG dup (?)
section '.text' code readable executable
start:
; Access dog number ecx mov esi,my_dogs lea esi,[esi + ecx*sizeof.DOG]
mov eax, dword [esi + DOG.color] mov edx, dword [esi + DOG.age]
Trang 5Higher dimensions
Assume that we want to remember the multiplication table in memory
How can we store a two dimensional object in our one
dimensional memory landscape?
We use our imagination!
Trang 6Higher Dimensions (Cont.)
The cell in row 3 and column 1 is in location 7
Trang 7Higher Dimensions (Cont.)
The cell in row 3 and column 1 is in location 13
Trang 8Higher Dimensions (Cont.)
Trang 9Multiplication table
Declaring the table:
mul_tbl dd WIDTH*HEIGHT dup (?)
Trang 10Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 11Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 12Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 13Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 14Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 15Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
ebx
Trang 16Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 17Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 18Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 19Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
ebx
Trang 20Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 21Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 22Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 23Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
ebx
Trang 24Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 25Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 26Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 27Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
ebx
Trang 28Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 29Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 30Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 31Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 32Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 33Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 34Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 35Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
ebx
Trang 36Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 37Multiplication table
Declaring the table:
Filling in the table:
mov esi,mul_tbl ; cell ptr
mov ecx,0 ; row counter
Trang 38More dimensions
The same techniques apply to more than 2 dimensions
Think about how to translate (x,y,z)
coordinates into a linear memory location
Trang 39Binary tree
How to represent it using linear memory?
Trang 40Binary tree (Cont.)
Let’s number the nodes:
1
Trang 41Binary tree (Cont.)
Finally we flatten the tree into linear memory:
Trang 42Binary tree (Cont.)
Traversing the tree
5
Trang 43Binary tree (Cont.)
Traversing the tree
5
Trang 44 Use your imagination
Trang 45Exercises
Code reading
Code writing
Have fun :)