News:

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

Dealing with standard C streams

Started by Vortex, June 20, 2007, 08:45:30 PM

Previous topic - Next topic

Vortex

Here is a quick example to use standart C streams with Masm :

.386
.model flat, stdcall
option casemap:none

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

include     Streams.inc

.data

msg     db 'stdout = %X',0

.data?

stdout  dd ?
stdin   dd ?
stderr  dd ?

.code

start:

    call    crt___p__iob
    mov     stdin,eax           ; #define stdin  (&__iob_func()[0])
    add     eax,SIZEOF(FILE)
    mov     stdout,eax          ; #define stdout (&__iob_func()[1])
    add     eax,SIZEOF(FILE)
    mov     stderr,eax          ; #define stderr (&__iob_func()[2])
    invoke  crt_fprintf,stdout,ADDR msg,stdout       
    invoke  ExitProcess,0

END start


__iob_func is redirected to __p__iob

[attachment deleted by admin]