News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Output to Console?

Started by Jeaton, March 13, 2005, 02:50:00 AM

Previous topic - Next topic

Jeaton

How do I output text to a console app, but not by using the "print" macro feature masm32 contains?

hutch--

Go backwards from the "print" macro and you will find a procedure in the MASM32 library that it uses. In the procedure you will find one of the ways to output data to the console using standard Windows API calls. It is a good idea to know how these macros work as you are not dependent on them once you understand how its done.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

James Ladd

Try this ....


.data
    stdout dd 0
    count dd 0
    message db "hello",13,10,0
.code   
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov stdout, eax
    invoke WriteFile, stdout, offset message, 7, addr count, NULL

Jeaton


MichaelW

Probably not what you had in mind, but here are a few additional methods.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\msvcrt.inc

    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\msvcrt.lib

    include \masm32\macros\macros.asm
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke _cputs,chr$("using _cputs",13,10)
    invoke _cprintf,chr$("using _cprintf",13,10)
    invoke printf,chr$("using printf",13,10)
    mov   esi,chr$("using _putch",13,10)
  @@:
    movzx ebx,BYTE PTR[esi]
    invoke _putch,ebx
    inc   esi
    test  ebx,ebx
    jnz   @B
    invoke printf,chr$(13,10,"Press any key to exit...")
  @@:
    call  _kbhit
    test  eax,eax
    jz    @B
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


eschew obfuscation

Jeaton

#5
I'm willing to learn any and all methods, however masm32 seems to be lacking the msvcrt .inc and .lib files.  Would you happen to know where I can download them?

Mark Jones

Hi Jeaton, try this:  http://www.masmforum.com/simple/index.php?topic=480.21 - there is a .zip in there somewhere with all the msvcrt prototypes properly defined. I think its in that thread, if not then do a search. There was a discussion about this recently.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Vortex

Hi Jeaton,

The simplest method is to use the StdOut function from masm32.lib:

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\masm32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\masm32.lib


.data
msg db 'Hello world!',0

.code

start:

invoke StdOut,ADDR msg
invoke ExitProcess,0

END start

pbrennick

And don't forget to build it as a console app. :thumbu

Paul

AeroASM

msvcrt is the Microsoft Visual C runtime library; you need msvcrt.dll to use it. there is no point though becuase the C printf() is exactly the same as the print macro.

Xor Stance

I remember I got a reply from Hutch before that the macros work or something like that. It uses full macros. But I don't remember where is the topic? I guess this is a better build macros with horrible words.

macros

.const db "string it works!",13,11
.data
print const

.code
start:

invoke db,NULL

endm

MichaelW

Quote from: AeroASM on March 13, 2005, 09:03:32 PM
msvcrt is the Microsoft Visual C runtime library; you need msvcrt.dll to use it. there is no point though becuase the C printf() is exactly the same as the print macro.

AFAIK msvcrt.dll is included with all versions of Windows. The MASM32 print macro is limited to displaying strings. The CRTL printf function (and the _cprintf function), in addition to displaying strings, can take a variable number of arguments, convert the commonly used numeric data types to strings, and format the output in a variety of ways.

MSDN: CRTL Reference, printf and wprintf
eschew obfuscation

pbrennick

Char,
I think you had better stop posting examples.  I fear you are no good at it.  :bg

Paul

Jeaton

Wow, thanks for all the help you guys.  I'm just going to use the StdOut method, but atleast now I know many other ways of doing it.

Vortex

An aother opportunity : You can use crtdll.dll instead of msvcrt.dll