Define arrays and variables in assembly

Source: Internet
Author: User

Compilation can directly read and write memoryProgramVariables are also required. However, unlike other advanced languages, it divides variables into many types, which are differentiated by the length of variables. Therefore, when defining (define) variables, five different keywords are used: DB, DW, DD, DQ, DT (in fact, only DB, DW are commonly used)
DB (define byte) means that the defined variable occupies the length of one byte (you can also say that the defined variable value is put into the memory space of one byte)
For example:
A DB 7 h means to put 7 h in a certain byte (Space) of the memory, and then let variable a point to this byte
You can also do this:
A DB 'H'; although 'H' is a character, it is saved into the memory but it has the corresponding ASCII code 48 h

You can also use dB to define arrays, such:
A DB 48 h, 65 h, 6ch, 6ch, 6fh, 00 h
B dB 'hello', 0
In this way, the elements in A and B are exactly the same.
It can be referenced as follows:
MoV Al, a [3]

You can also use the pointer and address change register (BX, Si, Di, bp ):
MoV Si, 3
MoV Al, a [Si]

If you want to define an array with the same elements, you can use the DUP keyword, for example:
C DB 5 DUP (9)
The effect is the same as the following:
C dB 9, 9, 9, 9, 9

D DB 5 DUP (1, 2)
Same:
D dB 1, 2, 1, 2, 1, 2, 1, 2, 2

If you want to define a value larger than 1 byte in dB, the compiler will report an error, for example:
A DB 1234 h; it fails during compilation. The error message is cannot convert Word to byte!
In addition, the first operand of DUP is 5 in the example and cannot exceed 1020. Otherwise, an error is returned: DUP expansion is over 1020 chars!

The preceding figure shows the remaining DW, DD, DQ, and dt values in dB usage. Except that they cannot define character arrays (because the ASCII value is 0 .. 255, one byte can certainly put the ASCII value of the next character)
DW (define word) defines the length of a word (two bytes)
Dd (define double word) defines the length of a double character (4 bytes ).
DQ (define Quartet word) defines the length of four words (8 bytes)
DT (define ten byte) defines the length of ten bytes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.