The console output is like a DOS output, not a graphical interface. Such orders as ping/ipconfig/ftp are such procedures.
Recall the past, in a DOS file operation, commonly used to "file handle" concept, the use of file handle operation, very convenient, when the operation, as long as you know the handle number can, without worrying about the location of the file. DOS, the equipment also has its own special handles, these handles are:
0000H standard input device (stdin)
0001H Standard output equipment (stdout)
0002H standard error Device (STDERR)
0003H Standard auxiliary equipment (Stdaux)
0004H Standard printing equipment (STDPRN)
StdIn and stdout can be redirected, which is the meaning of the commonly used "input redirection" and "output redirection" under DOS.
The following DOS feature calls will output information to the screen:
mov ah,40h; Writing to a file or device
MOV bx,1 standard output device
Lea Dx,outdata;D s:dx-> The data to be exported
MOV cx,count; number of characters to output
int 21h; DOS function call
By the same token, you can also output information to the screen under Windows. This takes two API functions, one is GetStdHandle, the other is WriteFile, which is defined in the Win32 developer ' references:
------------------------------------------------------------
HANDLE GetStdHandle (
DWORD nstdhandle//input, output, or error device
);
The GetStdHandle function returns a handle for the standard input, standard output, or standard error device.
Nstdhandle->specifies the device for which to return the handle. This parameter can have one of the following values:
Value | Meaning
--------------------+---------------------------
Std_input_handle | Standard input Handle
Std_output_handle | Standard output Handle
Std_error_handle | Standard Error Handle
If The function succeeds, the return value is a handle of the specified device.
------------------------------------------------------------
BOOL WriteFile (
HANDLE hfile,//HANDLE to file to write to
Lpcvoid lpbuffer,//pointer to data to write to file
DWORD Nnumberofbytestowrite,//number of bytes to write
Lpdword Lpnumberofbyteswritten,//Pointer to number of bytes written
lpoverlapped lpoverlapped//Pointer to structure needed for overlapped I/O
);
=============================================================
Below, we look at a program that displays a string message!
.386
. Model Flat,stdcall
Option Casemap:none
Include Windows.inc
Include Kernel32.inc
Include User32.inc
Includelib Kernel32.lib
Includelib User32.lib
. Data
Mess db ' How are you! ', 0; to display the information
. Data?
StdOut DD?; storage handles for standard output
Charout DD?; record the number of characters actually exported
. Code
Start
Invoke Getstdhandle,std_output_handle; Get handle on standard output
mov stdout,eax; save handle number
Lea Eax,mess
Invoke Lstrlen,eax; Find the length of the string
Lea Ecx,charout
Invoke Writefile,stdout,addr mess,eax,ecx,null; write a file
Invoke Exitprocess,null; end of program
End Start
--------------------------------------------------------------
Compile the link, give detailed information below, for analysis reference:
D:\masm7>dir/ad
Volume in Drive D has no label
Volume Serial number is 18f0-186b
Directory of D:\MASM7
. 〈dir〉02-12-03 17:36.
.. 〈dir〉02-12-03 17:36.
lib〈dir〉02-12-03 17:38 LIB
include〈dir〉02-12-03 17:38 INCLUDE
0 file (s) 0 bytes
4 dir (s) 2,411,925,504 bytes free
d:\masm7>ml/coff/i include 4.asm/link/subsystem:console/libpath:lib
Microsoft (R) Macro assembler Version 6.14.8444└─ Console Program
Copyright (C) Microsoft Corp. 1981-1997. All rights reserved.
Assembling:4.asm
Microsoft (R) incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp. 1992-1998. All rights reserved.
/subsystem:console/libpath:lib
"4.obj"
"/out:4.exe"
D:\masm7>4
How to Are you!
D:\masm7>
--------------------------------------------------------------
In addition, in the Masm32.inc has the function stdout the declaration, may use for the direct output information, the above example modifies is the following appearance, visible comes more conciseness, for everybody reference:
.386
. Model Flat,stdcall
option Casemap:none; case sensitive
Include Windows.inc
Include Kernel32.inc
Include Masm32.inc
Includelib Kernel32.lib
Includelib Masm32.lib
. Data
Mess db ' How are you! ', 0
. Code
Start
Invoke STDOUT,ADDR Mess
Invoke Exitprocess,null
End Start