Each 8 bits of memory is called a byte, and this is the fundamental unit of memory on a 32 bit machine. Of course our computers have many megabytes or even gigabytes of memory.
We can access each of the bytes of memory in the machine by specifying an address. This is a 32 bit number which represents the location of the byte of memory we are interested in.
Of course, when we are writing an assembly language program, we have no idea which locations of memory our program code will be loaded into, when the program is run. Nor do we have any idea which memory locations will be allocated for data.
Fortunately for us, the assembler and the operating system deal with these issues for us. Thus we rarely need to work with explicit addresses as such.top
Here we describe how to tell the assembler that we want to allocate small chunks of memory for storing data. This is somewhat like declaring variables in a higher level language, in that we give names to the chunks of space that we set aside for data.
Here are some examples of declaring and initialising some variables.
myvar1 DB 3 anothervar DW 03FAh someval DD 721099 repeatvar DB 7 dup(12,28) string1 DB 'This is a string'
The first line sets aside a single byte of memory and initialises it to the value 3. This byte of memory can then be referred to in the program by the name myvar1. Essentially the word myvar1 represents the address of the memory location. If we want to refer to the actual value stored at that address (i.e. the value 3 until something changes it), we must write[myvar1].
The second line sets aside a word of data (two consecutive bytes) containing the value corresponding to the given hexadecimal number.
The third line declares and initialises a double word (four bytes of data).
The next line makes use of the dup operator to set aside 14 bytes of data and to initialise it to seven copies of the two bytes 12, 28. This operator is quite useful for declaring arrays of bytes or words, etc, that are initialised to zero, e.g:
myarr DD 100 dup 0
The next line above sets aside 16 bytes of data and sets their contents to be equal to the ASCII values corresponding to the letters of the given string. This is how we can declare strings in assembly language.