Hey people,

I'm new here to the forum and I'm new to assembly programming. First off all I want to excuse me for my 'bad' english, hopefully you all understand what I'm talking about  :).

My Question
Because I'm a beginner I had in my mind to program something in asm that can make a new file and write some lines in it.
This is my code:
section .data
fileName db "file.txt", 0

fileText db "This is a stringe on the first line <linebreak> This should be on the second line", 0x0a
fileTextLen equ $-fileText

section .text
global _start

_start:
mov eax, 8   ; system call create
mov ebx, fileName ; Filename
mov ecx, 00644Q ; Write/Read permission in octal
int 0x80     ; Execute

mov ebx, eax   ; filedescriptor from sys_create() in ebx

mov eax, 4   ; system call write
;           ebx allready exists
mov ecx, fileText   ; fileText in ecx
mov edx, fileTextLen ; length from fileText in edx
int 0x80       ; Execute

mov eax, 6     ; system call close
;           ebx bestaat al
int 0x80       ; Execute


mov eax, 1     ; system call exit
mov ebx, 0     ; Exit with error code 0
int 0x80       ; Execute


So this is my code and everything works perfect. The string i'm talking about is:

fileText db "This is a stringe on the first line <linebreak> This should be on the second line", 0x0a

Now I should replace <linebreak> in something that will give me a new line. I tried \r and \n (C++ linebreaks) but it didn't do anything.

Hopefully you guys can help me.
Posted on 2007-08-02 05:11:09 by Franchise
I found a solution to my problem.


fileText      db "This is my string at line 1", 0x0a, "This is my string at line 2", 0x0a, "This is my string at line 3"


Can you guys give me a yes if this is correct.

Thank you
Posted on 2007-08-02 05:44:53 by Franchise
Yes, that is correct. The character 0x0A is called Line Feed and it makes the cursor to go to the beginning of the next line in most modern operating systems. Under DOS, You also have 0x0D that is called Carriage Return. The original definition for these two is:

• Carriage Return: moves the cursor position to the beginning of the current line.
• Line Feed: moves the cursor to the next line, with the X position of where the cursor is in the current line.

Windows still uses the combination of CR (Carriage Return) and LF (Line Feed) in order to separate lines of texts and etc. So you have to attach 0x0D and 0x0A at the end of each line to start a new line (in Windows).
Posted on 2007-08-02 06:37:17 by XCHG
Oké, thanks for you explanation.
Posted on 2007-08-02 07:34:34 by Franchise