News:

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

Assembler Code Check

Started by DaaaN, December 04, 2009, 03:12:28 AM

Previous topic - Next topic

DaaaN

Hi, I've just started learning assembler and just wondering if any of you can spot any errors within this program. Thanks alot. :)



#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;
}                        

hutch--

DaaaN,

It would help if youy told everyone what errors you are getting and what you expect out of the code as a result.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

i would also recommend installing the masm32 package and writing the code completely in assembler
it will take a little getting used to
there are many example programs in the package, as well as here in the forum
they will help you get started
i can almost work out what you are trying to do - lol