And computing an array of assembly language string length

When using arrays, often you want to know its size. The following example uses a constant size ListSize declared list:

 

list BYTE 10,20,30,40
ListSize = 4

Explicitly declare an array of size will lead to programming errors, especially if the follow-up will insert or delete array elements. Declared array size better approach is to let the assembler to calculate this value.

$ Operator (current address counter) Returns the current offset program statements. In the following example, the offset is subtracted from the current list address counter ($), the calculated ListSize:

list BYTE 10,20,30,40
ListSize = ($ – list)

ListSize must immediately follow the list. The following examples, listsize value (24) computed on the large, because the storage space var2 use, affect the distance between the current list and the offset address counter:

list BYTE 10,20,30,40
var2 BYTE 20 DUP(?)
ListSize = ($ – list)

Do not manually calculate the length of the string, so that the assembler to complete this work:

myString BYTE "This is a long string, containing"
                BYTE "any number of characters"
myString_len = ($ – myString)

Word and double word group

When the number of bytes to be calculated is not contained in the array of elements, with the size of the array should be a total size (in bytes) divided by the individual elements. For example, the following embodiment, since each word in the array to 2 bytes (16 bits), the address range to be divided by 2:

list WORD 1000h,2000h,3000h,4000h
ListSize = ($ – list) / 2

Similarly, each element of the double word length of 4 bytes, and therefore, the total length divided by the number of array elements 4 to produce:

list DWORD l0000000h,20000000h,30000000h,40000000h
ListSize = ($ -list) / 4

Next: EQU directive

Highly recommended reading articles

40 + annual salary of big data development [W] tutorial, all here!

Guess you like

Origin blog.csdn.net/Javaxuxuexi/article/details/93312883