UMBC CMSC 313 -- Assembly Language Segment Previous | Next

Data Types


OK, what did you learn about variables? A quick review says: NOTE: When doing assembly language programming, there is not implied conversion. It takes completely different instructions to process floating point data as opposed to integer data.

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.

The Intel manual documents the numeric data types as:

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:

67 45 23 01 where 67h is stored at the lowest address. This is called "little-endian" -- littlest part comes first! All Intel chips are little-endian. Even though it is stored in memory in little-endian format, it is stored correctly in the registers and is automatically converted when it is moved from memory to the register! The hardware automatically converts it for. The only reason you the programmer care about the order is when you look at a display of memory, things are different than you might expect and it also determines what is stored at what address. A four-byte variable occupies four different addresses! This gets even more fun when you have to work with arrays. An array of ten four-byte variables occupies 40 addresses!

Previous | Next

©2004, Gary L. Burt