Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 885
  • Last Modified:

fscanf in inline assembly code

i have a method called readData(FILE* f, int[] x, int* arraysize)
i wanted to know how to you get data from the file ptr f and store it into the x array using inline assembly code
here is the part of code i am trying to fix

int hold;
    char format[] = "%d";
    _asm
      {
        mov  ebx,x
       mov  ecx,cursize
       mov  edx,f

      mov  dword ptr [ecx],0  ; cursize = 0
      ; call fscanf
      ; push fscanf parameters & call fscanf
        lea  ebx,hold
        push ebx
        lea  ebx,format
        push ebx      
        lea  ebx,f
        push ebx    
        call fscanf
        add  esp,12      


.....
0
majorlag
Asked:
majorlag
  • 2
2 Solutions
 
AlexFMCommented:
Why do you need this in Assembly?

Anyway, wtite this in C and read Assembly code generated by compiler. You can see Assembly code in compiler listings, or in debugger, selecting "View Assembly" options.
0
 
majorlagAuthor Commented:
I am using Visual Studios .net 2003 to do inline assembly and i dont think or know where the "View Assembly" options is.
I need to do this in Assembly because my project is to read  a list of data from a file and put them into an array.
And the only thing I am stuck on is how to get data from the file and saving it to a register so i can copy it to the array.
I heard it is almost the same as scanf command but I tried many different ways and couldnt get it to work with fscanf.
so it would be nice if you or somebody can show me how
thank you in advance
0
 
AlexFMCommented:
I still don't understand - is it possible to do what you want in C? I don't see anything special in reading data from file, to do this in Assembly. Can you write this in C?

For example, create C++ Console application with the following code:

int _tmain(int argc, _TCHAR* argv[])
{
    int n;
    scanf("%d", &n);

    return 0;
}

Set breakpoint on sscanf line and select Start command. When debugger stops on this lise, select: Debug - Windows - Disassembly. You can see how scanf code is translated to Assembly by C++ compiler:

    int n;
    scanf("%d", &n);

00411B1E  lea         eax,[n]
00411B21  push        eax  
00411B22  push        offset string "%d" (4270C8h)
00411B27  call        @ILT+980(_scanf) (4113D9h)
00411B2C  add         esp,8
0
 
meskiCommented:
I'm puzzled as to why you want to do it in assembly - if you want to write formatted data from a file into an array, and use scanf to transform it from ascii representation to integer, for example

<code fragment, no error checking, haven't tried compiling>  :)

int myArr[10] = {0};

for ( int i = 0; i < 10; i++ )
{
   scanf("%d", &myArr[i]);
}

myArr could be a lot more complex - say a class/struct with multiple data members

 scanf("%d %d %d", &myArr[i].m_a, &myArr[i].m_b, &myArr[i].m_c);
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now