Hello,
I need to read a file line by line and each line to a diferent variable.
I have to do it using nasm in Linux 32bits OS.

I have this code, but this one read all the lines.



section .data
    MAX_LINE    equ  256
    file              db    "teste",0
    ReadFlag      dd    00q
    FileNum        dd    0
    bytesLenght dd    0

section .bss
    data    resb    MAX_LINE

section .text
    global  _start

_start:
; Open the file
    mov    ecx,
    mov    ebx,file
    mov    eax,5
    int    0x80
    mov     , eax

; Read File
    mov    edx,MAX_LINE
    mov    ecx,data
    mov    ebx,
    mov    eax,3
    int    0x80
    mov    ,eax

; Close File
    mov    ebx,
    mov    eax,6
    int    0x80
   
; Write the readed data to the screen
    mov    edx,
    mov    ecx,data
    mov    ebx,1
    mov    eax,4
    int    0x80

; End
    mov    ebx,0
    mov    eax,1
    int    0x80



I think I have to make a cicle and use the esi and use "cmp" to find the 0xA. But I don't know how.
Can you help me with this?
Thanks
Posted on 2008-02-09 10:30:17 by nmpsantos
%IDEFINE  PTR

  LEA    ESI , data
  MOV    EDI , CurrentLine
  MOV    EBX , 0x0000000A
  MOV    EDX , 0x000000FF
  .Loop:
    MOV    EAX , DWORD PTR
    AND    EAX , EDX
    INC    ESI
    CMP    EAX , EBX
    JE      .Loop
    MOV    DWORD PTR , EAX
    INC    EDI
    JMP    .Loop


Something like that. The above code will NOT put each line in a separate variable. It uses a single variable. You are going to have to handle that yourself. I suggest that you allocate a block of memory using a virtual or a heap memory block and then separate them into blocks of smaller strings with lengths up to, for example, 256 characters and treat them as separate string variables. You also need to check the length of the original data block and etc.
Posted on 2008-02-09 12:17:25 by XCHG
Thanks.... it's working very good!

I think I have only one more doubt.
I tried some ways to store the different lines I read in different variables but I'm not succeed!
I am a beginner and do not know what I am doing wrong...

I hold the lines in the variable "currentLine" at the end of each line I save what is in currentLine in the variable "line1, line2, ..." to do this
I this


mov  eax, currentLine
mov  line1, eax



I think it must be wrong! Who can help me?
Posted on 2008-02-09 21:30:46 by nmpsantos