flat assembler
Message board for the users of flat assembler.

Index > DOS > Tutorial: Creating text files with FASM

Author
Thread Post new topic Reply to topic
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 02 Jan 2013, 03:56
You don't have to write assembler programs in FASM; you can create any kind of file (e.g. text files).

Enter the following code in "MyText.asm":

Code:
; MyText.asm
db 'First line', 0Dh, 0Ah
db 'Second line'
    


Then run:
Code:
fasm MyText.asm MyText.txt    


At least you know what your line separators are Wink

But FASM can be seen as a text templating engine as well. Suppose you want to add a ruler to a document whereby you want to be able to determine the position of each letter in each paragraph:

Code:
times 7 db '         ', %+30h
db 0dh, 0ah
times 7 db '----+----+'
db 0dh, 0ah
db 'This is the first paragraph.', 0dh, 0ah
db 'This is the second one.'
    


The result will be:

Code:
         1         2         3         4         5         6         7
----+----+----+----+----+----+----+----+----+----+----+----+----+----+
This is the first paragraph.
This is the second one.
    


If you want to create a 5x5 grid into which to put single characters, try this:

Code:
N=5
l=1 
while l<=N+1 
      c=1 
      while c<=N 
            times 4 db '-'
            c=c+1 
      end while 
      db '-' 
      db 0dh,0ah 
      if l<N+1 
            c=1 
            while c<=N 
                  db '|   '
                  c=c+1 
            end while 
            db '|' 
      end if 
      db 0dh,0ah 
      l=l+1 
end while
    


The grid document should be as follows:

Code:
---------------------
|   |   |   |   |   |
---------------------
|   |   |   |   |   |
---------------------
|   |   |   |   |   |
---------------------
|   |   |   |   |   |
---------------------
|   |   |   |   |   |
---------------------
    


Doesn't look good, so we add some joints (as + signs):

Code:
N=5
l=1  
while l<=N+1  
      c=1  
      while c<=N 
            db '+' 
            times 3 db '-'
            c=c+1  
      end while  
      db '+' 
      db 0dh,0ah  
      if l<N+1  
            c=1  
            while c<=N  
                  db '|   '
                  c=c+1  
            end while  
            db '|'  
      end if  
      db 0dh,0ah  
      l=l+1  
end while
    


This is the new grid:

Code:
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
    


Last edited by Ciper on 02 Jan 2013, 08:32; edited 5 times in total
Post 02 Jan 2013, 03:56
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 02 Jan 2013, 04:04
Ciper wrote:
You don't have to write assembler programs in FASM; you can create any kind of file (e.g. text files).

Enter the following code in "MyText.asm":

Code:
; MyText.asm
db 'First line', 0Dh, 0Ah
db 'Second line'
    


Then run:
Code:
fasm MyText.asm MyText.txt    


At least you know what your line separators are Wink


we know. Someone showed us a png/bmp from scratch by hand
Post 02 Jan 2013, 04:04
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 02 Jan 2013, 05:25
Sorry, I did not mean to be pedantic; this stuff is already in the documentation of FASM anyhow. I am just trying to build a series of tutorials that may be of use to somebody.

The moderator can delete this thread as it is not of much significance.
Post 02 Jan 2013, 05:25
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.