Basically, I've written assembly code which allows a text file to be copied from it's current location through the Com cable onto a destination on another computer. This is the code for the transmitter part ONLY.

#include
<stdio.h> #include <conio.h> #define FEND 0x40
	
int main (void) {
char wtmode[]= "wb";
char rdmode[]= "rb";
char fname []= "C:\MoveThis.txt";
char pname []= "COM2";
char error1 []= "data file failed to open";
char error2 []= "com port failed to open";

FILE * fileptr;
FILE * portprt;

__asm {
lea eax, rdmode
push eax
lea eax, fname
push eax
call DWORD PTR (fopen) ; open data file for reading
add esp,8
or eax,eax
jnz fileOK
lea eax,error1
push eax
call printf ; fail to open file
add esp,4
jmp endit

fileOK: mov DWORD PTR (fileptr), eax
lea eax,wtmode
push eax
lea eax,pname
push eax
call DWORD PTR (fopen) ; open COM port for writing
add esp,8
or eax, eax
jnz portOK

lea eax, error2
push eax
call DWORD PTR (printf) ; faile to open port
add esp, 4
mov eax, DWORD PTR(fileptr)
push eax
call DWORD PTR (fclose)
add esp,4
jmp endit

portOK: mov DWORD PTR (portptr), eax
more: mov eax, DWORD PTR(fileptr)
push eax
call DWORD PTR (fgetc) ; get next char from data file
add esp,4
cmp eax, EOF ; check for end of data
jz nomore
mov ebx, eax

mov eax, DWORD PTR(portptr)
push eax
push eax
call DWORD PTR (fputc) ; send char to COM port
add esp,8
jmp more

nomore: mov eax, DWORD PTR (fileptr)
push eax ; end of data so
mov eax,FEND ; send terminating sentinal
push eax
call DWORD PTR (fputc)
add esp,8

mov eax, DWORD PTR (fileptr)
push eax
call DWORD PTR (fclose) ; close data file
add esp,4

mov eax, DWORD PTR(portptr)
push eax
call DWORD PTR (fclose) ; flush and close COM port
add esp,4

endit:
} //asm
return 0;
} // main

When I try to debug the file in VC++ 2008, I'm greeted with the following errors:

------ Build started: Project: filetransmit, Configuration: Debug Win32 ------
Compiling...
Filetransmit.c
c:\users\parent\documents\visual studio 2008\projects\filetransmit\filetransmit\filetransmit.c(1) : error C2006: '#include' : expected a filename, found 'newline'
c:\users\parent\documents\visual studio 2008\projects\filetransmit\filetransmit\filetransmit.c(1) : fatal error C1083: Cannot open include file: '': No such file or directory
Build log was saved at "file://c:\Users\Parent\Documents\Visual Studio 2008\Projects\filetransmit\filetransmit\Debug\BuildLog.htm"
filetransmit - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can someone correct these errors for me as after various attempts I've just hit a dead end. :'(

When you say "Basically, I've written assembly code...", do you mean you have or I, Dr. Rob Williams?

commented: NO I AM DR ~RWILLIAM +2

Dude that was an epic fail attempt, thanks for the giggles though!

PS Errors aren't hard to fix.

haha, anytime^^ assembly's so tedious and such a useless thing to learn which i doubt would be needed by me in the future.

i've re-done everything myself though and it works! "learn from your mistakes" they say ;)

#include
<stdio.h> #include <conio.h> #define FEND 0x40

Can't you see any syntax errors there?

haha, anytime^^ assembly's so tedious and such a useless thing to learn which i doubt would be needed by me in the future.

i've re-done everything myself though and it works! "learn from your mistakes" they say ;)

Assembly is not tedious, and certainly is useful to learn... A lot of low-level stuff NEEDS to be written in asm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.