i'm a beginner at assembly, and i need to know how to do something pretty basic...

when you've defined an array of bytes (like with db) how do you refer to and manipulate a specific byte in it? Need to know how to move a specific byte in one "db" thing to overwrite a specific byte in another "db" thing... knowing how to edit individual bits inside one of these bytes would also be useful...
hopefully a method that will also work with words, as in "dw"...

please help!!!
Posted on 2003-05-04 21:24:42 by KaS_m
I will have to "assume" here that you will be using 32-bit coding. If not, you should probably switch immediately since 16-bit coding will not be of much use to you for your learning curve.

There is a variety of ways to achieve the result you want. The easiest to start will be to put the address of the first byte of the array in a register and use a displacement to refer to the other bytes of the array. Remember that the first byte has a displacement of 0, the 10th byte has a displacement of 9, etc.
mov edi,offset array_name ;EDI points to the array

mov al,[edi+6] ;copies the 7th byte into AL
mov [edi+15],al ;copies the content of AL to the 16th byte
If you have an array of words, each one has 2 bytes. Since the given displacement is ALWAYS in bytes, remember to multiply the word's position by 2 for the displacement. Ex.:

mov ax, ;moves the content of the 5th word into AX

After you have mastered this basic technique, you can learn other ways to access elements of arrays.

Raymond
Posted on 2003-05-04 21:59:53 by Raymond