#include <stdio.h>
#include <conio.h>
#define CNTRLZ 0x1A
int main (void) {
char wtmode[] = "w";
char rdmode[] = "r";
char fname[] = "H:\\text.dat";
char pname[] = "COM1";
char error1[] = "fail to open data file\n";
char error2[] = "fail to open COM port\n";
/*if ((fp = fopen ("H:\\text.dat", "w")) == NULL) */
FILE * fp;
FILE * dp;
int c;
_asm{
lea eax, wtmode
push eax
lea eax, fname
push eax
call DWORD PTR (fopen)
add esp, 8
or eax,eax
jnz fileOK
lea eax, error1
push eax
call DWORD PTR printf
add esp,4
jmp endit
/*return 1;*/
fileOK: mov DWORD PTR (fp), eax
lea eax, rdmode
push eax
lea eax, pname
push eax
call DWORD PTR (fopen)
add esp, 8
or eax, eax
jnz portOK
lea eax, error2
push eax
call DWORD PTR printf
add esp,4
mov eax, DWORD PTR (fp)
push eax
call DWORD PTR (fclose)
add esp, 4
jmp endit
portOK: mov DWORD PTR (dp), eax
more: mov eax, DWORD PTR (dp)
push eax
call DWORD PTR (fgetc)
add esp,4
cmp eax, CNTRLZ
jz nomore
mov ebx,eax
mov eax, DWORD PTR (fp)
push eax
push ebx
call DWORD PTR (fputc)
add esp,8
jmp more
nomore: mov eax, DWORD PTR (fp)
push eax
call DWORD PTR (fclose)
add esp,4
mov eax, DWORD PTR (dp)
push eax
call DWORD PTR (fclose)
add esp,4
}
endit: return 0;
}