In the process of familiarizing yourself with commands, pseudo commands, and assembly syntax, the first thing you need is the means of output display.
I used console output when I first started learning, and finally found that it is better to use debug output for Win32 compilation.
The following are several methods of console output:
1. Use the stdout function provided by MASM;
2. Use System APIs:
3. Use the printf function in msvcrt. dll of Microsoft C standard library.
Use the stdout function of MASM:
; Test3_1.asm; TestCodeCreate a console project: file-> new project-> console app... 386. Model flat, stdcallinclude masm32.incinclude extends masm32.libincludelib kernel32.lib. Data sztext DB "Hello world! ", 0. codestart: invoke stdout, ADDR sztext ret; RET is used for sub-ProgramThe returned command, which is used to replace exitprocess (this is acceptable when the Win32 window is not generated) end start
Use System API functions:
; Test3_2.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incincludelib kernel32.lib. Data sztext dB 'Hello world! ', 0; defines two DWORD type variables, which are used for output handle and string length. Data? Hout dd? Len dd ?. Codestart:; get the handle of the output device on the console. The returned values will be placed in the eax register invoke getstdhandle, std_output_handle; give the obtained handle to the variable Hout mov Hout and eax; the lstrlen function is used to obtain the string length. The returned values are eax invoke lstrlen and ADDR sztext. The obtained string length is given to the variables Len mov Len and eax. The parameters are output to the console: handle, string address, and string length. The following two pointers do not currently use invoke writefile, Hout, ADDR sztext, Len, null, null retend start; in addition, the previously used stdout is basically implemented in this way. The source code is: masm32 \ m32lib \ stdout. ASM
Use the printf function in the Microsoft C standard library; msvscrt. inc declares it as crt_printf
; Test3_3.asm.386.model flat, stdcallinclude msvcrt. incincludelib msvcrt. Lib. Data sztext dB 'Hello world! ', 0. codestart: invoke crt_printf, ADDR sztext retend start
C Function crt_printf should be recommended in comparison to the three methods, because it can easily output more data types, such:
; Test3_4.asm.386.model flat, stdcallinclude msvcrt. incincludelib msvcrt. lib. data szfmt dB 'eax = % d; ECx = % d; edX = % d', 0. codestart: mov eax, 11 mov ECx, 22 mov edX, 33 invoke crt_printf, ADDR szfmt, eax, ECx, EDX retend start