Win32 compilation [6]: pseudo-command DUP and array

Source: Internet
Author: User
Declare an array instance:
 
; Test6_1.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data; declare and initialize a DWORD array with three elements. Each element of the array is 4-byte Val DD, 22, 33. codestart: mov eax, Val printdec eax; 11 mov eax, Val [4] printdec eax; 22 mov eax, Val [8] printdec eax; 33 retend start

  

The preceding example can also be written as follows:

 
; Test6_2.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val DD 11 dd 22, 33. codestart: mov eax, Val [4*0] printdec eax; 11 mov eax, Val [4*1] printdec eax; 22 mov eax, Val [4*2] printdec eax; 33 retend start

  

Use the pseudo command DUP:

 
; Test6_3.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data; declare a DWORD array with three elements, and initialize each element to 6 V1 DD 3 DUP (6); declare a DWORD array with three elements without initialization; for global variables, if not initialized, V2 DD 3 DUP (?) will be filled with 0 (?). Data? Declare the DWORD array V3 DD 3 DUP (?) with three elements (?). Codestart: dumpmem offset V1, 12; 06 00 00 00-06 00 00-06 00 00 00 00 dumpmem offset V2, 12; 00 00 00 00-00 00 00 00 00 00 00 dumpmem offset V3, 12; 00 00 00 00 00-00 00 00-00 00 00 00 00 retend start

  

Now we can distinguish uninitialized variables in the. Data Segment From. Data? Differences:

; ‑Flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude Debug. incincludelib kernel32.libincludelib masm32.libincludelib Debug. Lib. Data V1 dd 4096 DUP (?) ; The uninitialized variable is in the. Data segment. The generated EXE file will allocate the memory according to the size. codestart: printtext 'Hi' retend start; ------------------------------------------; The aboveProgramThe EXE of the program is 18944 bytes, And the EXE of the program below is 2560 bytes. The difference is exactly 4096*4 bytes. Conclusion: variables that do not need to be initialized should be declared in. Data? Segment; break; kernel flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude Debug. incincludelib kernel32.libincludelib masm32.libincludelib Debug. Lib. Data? V1 dd 4096 DUP (?) ; The variable is not initialized in. Data? Segment. codestart: printtext 'Hi' retend start

  

Example of continued DUP:

; Test6_6.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val DD 2 DUP (1, 2, 3 ). codestart: dumpmem offset Val, 24; 01000000-02000000-03000000-01000000-02000000-03000000 retend start

  

Nested array:

 
; Test6_7.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val DD 2 DUP (3 DUP (1, 2 )). codestart: dumpmem offset Val, 48; 1 2 1 2 1 2 1 2 2 2 1 2 2 retend start

  

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.