UMBC | CMSC 313 -- Assembly Language Segment | Previous | Next |
The NASM manual says:
3.2.1 DB and friends: Declaring Initialized Data DB, DW, DD, DQ and DT are used, much as in MASM, to declare initialized data in the output file. They can be invoked in a wide range of ways: db 0x55 ; just the byte 0x55 db 0x55,0x56,0x57 ; three bytes in succession db 'a',0x55 ; character constants are OK db 'hello',13,10,'$' ; so are string constants dw 0x1234 ; 0x34 0x12 dw 'a' ; 0x61 0x00 (it's just a number) dw 'ab' ; 0x61 0x62 (character constant) dw 'abc' ; 0x61 0x62 0x63 0x00 (string) dd 0x12345678 ; 0x78 0x56 0x34 0x12 dd 1.234567e20 ; floating-point constant dq 1.234567e20 ; double-precision float dt 1.234567e20 ; extended-precision float DQ and DT do not accept numeric constants or string constants as operands.
OK, back to the NASM manual
3.2.2 RESB and friends: Declaring Uninitialized Data RESB, RESW, RESD, RESQ and REST are designed to be used in the BSS section of a module: they declare uninitialized storage space. Each takes a single operand, which is the number of bytes, words, double-words or whatever to reserve. As stated in section 2.2.7, NASM does not support the MASM/TASM syntax of reserving uninitialized space by writing DW ? or similar things: this is what it does instead. The operand to a RESB-type pseudo-instruction is a critical expression: see section 3.8. For example: buffer: resb 64 ; reserve 64 bytes wordvar: resw 1 ; reserve a word realarray resq 10 ; array of ten reals
Gee, seems simple enough. It is! Simple enough to screw up when you are not focusing on what you are doing! Student come in for help every semester because they can not understand why things just are not doing what they are suppose to....the computer did exactly what it was told to do!
To clarify one item about the above example, we need to review what is a buffer or an array (in this case, they are the same thing.) An array is a collection of variables that are of the same data type, same name, and are stored contiguously!
Whenever a data item is more than one byte long, how does it get stored in memory? If we have a hex value of 01234567h, it will be stored as: