flat assembler
Message board for the users of flat assembler.

Index > Main > Examples needed!

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
As you can see, the new site still lacks the examples section, I would just put there the ones from the old site, but since many of them were written for the quite old versions of fasm, it would be good to revise them. So if you are the author of one of them, please contact me to agree the updated version for the new website.

Also, anyone who wants to share some program he as written in flat assembler as an example, is welcome to send it to me (or post here).

When you make such a program, don't forget to put comments in English,
put there the name of the author or some documentation if needed. Every example should be provided as ZIP package, containing all the sources and final executable, some makefiles or documentation if necessary.

Please don't be afraid that you are not able to write some really nice program - every piece of code is good if it can help beginners to see how even the very elementary things can be achieved. It is also an occasion to make your name apperar on the fasm's website. Wink


Last edited by Tomasz Grysztar on 19 Jan 2005, 09:27; edited 2 times in total
Post 06 Feb 2004, 13:13
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
I have a few examples here:

http://www.comrade64.com/sources/mkpath.zip
This examples makes nested subdirectory path from command-line.

http://www.comrade64.com/sources/sysview.zip
Incomplete, but functional, window and process browser for Windows.

http://www.comrade64.com/sources/dns-mx.zip
MX (mail) look-up with DNS protocol.

http://www.comrade64.com/sources/linklist.zip
Linked lists.

http://www.comrade64.com/sources/knob.zip
A radial knob.

http://www.comrade64.com/sources/circle.zip
Drawing circles in mode 13h.

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 06 Feb 2004, 19:49
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
Hi Privalov!

Here's a simple base converter. It's not well commented nor well coded, but it might be an example to upload?

Best regards,
Tommy


Description: Base Converter
Download
Filename: Basecnv.zip
Filesize: 3.45 KB
Downloaded: 396 Time(s)

Post 07 Feb 2004, 11:39
View user's profile Send private message Visit poster's website Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
Privalov wrote:
Every example should be provided as ZIP package, containing all the sources and final executable, some makefiles or documentation if necessary.

I got one little question, I assume .zip are for Windows and DOS, examples for other OSes such as MenuetOS, *nix/Linux, *BSD, may use other 'stanard' packing formats (eg .tgz (tar.gzip), .tbz2 (tar.bzip2) for *nix/Linux:/*BSD) Smile


I (currently) don't have any examples for linux, but I think Bazik's 'old' examples should be included - for now I don't think they need to be revised

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 07 Feb 2004, 12:34
View user's profile Send private message Visit poster's website Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng
Hi,Privalov:
The attached file is writed by pure fasm language and used for tested protect mode on DOS platform. It have been downloaded 87 times on the forum and I do a short update for it.
I think that it maybe a good protect mode demo programs . It included all of protect mode edges: flat mode, Interrupt and Exception handler, Page, V86 and Extented V86 mode.

It's not well commented nor well coded, because I am Chinese and doesn't a native English user, But I hope that it maybe use to share on the fasm world, it might be an example to upload?

Thank you.


Description:
Download
Filename: protect.zip
Filesize: 84.84 KB
Downloaded: 431 Time(s)

Post 07 Feb 2004, 13:04
View user's profile Send private message MSN Messenger Reply with quote
Rookie



Joined: 21 Aug 2003
Posts: 44
Location: Planet Romania
Rookie
Greetz to everybody.

The Readme.txt sez:
Quote:
This is one of my first proggies, it demonstrates the handling of command line parameters without the use of the C library, although it copies (more or less) its behaviour.

The _argc variable returns the number of arguments, while _argv stores adresses to null-term strings containing the parameters. The first one is the executable file name. When all the processing is done, [_argv] must (or at least should) be HeapFree-ed.

There is no black magic used here. Labels are self-explaniatory and the code is preety straight-forward, but it does give newbies the chance of exercising ASM programming by optimizing proggies written by rookies like myself.

Hope it helps somebody.


Description: Edited to suit req standards.
Download
Filename: cmd.zip
Filesize: 2.49 KB
Downloaded: 398 Time(s)


_________________
This is who I choose to be.


Last edited by Rookie on 08 Feb 2004, 20:06; edited 1 time in total
Post 08 Feb 2004, 13:16
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
Hi Privalov,

I am intending to write some documentations for the tool scan and inc2inc

_________________
Code it... That's all...
Post 08 Feb 2004, 17:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
Thanks for all your programs - I'll try to assemble the new "examples" section as soon as possible.
Post 09 Feb 2004, 22:06
View user's profile Send private message Visit poster's website Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
What I use and look for on the internet is INCLUDE FILES
since every program is not much more than program parts
put together in a certian order,
prewritten, well commented, pretested, program parts in include files is the ticket.....

I have converted all my Nasm inc16 procs to Fasm
and I'm going to make a Fasm environment zip soon
which is a ready to go to work assembly environment for DOS beginners.
Templates, help, etc......
I have had my
http://bitdog.home.att.net/files/nasmenv.zip
out for about a year, & I was 3/4 of the way through making the upgraded
version when I found Fasm & fell in love immediately........
So I haven't finished my NEW nasmenv.zip as of yet.

----message edited here------
fasmenv.zip version 0.01 beta is out, see link in message below.


Last edited by Bitdog on 12 Feb 2004, 05:23; edited 1 time in total
Post 10 Feb 2004, 04:04
View user's profile Send private message Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng
Dear Comrade:
I have watched your program:sysview.zip. It's a good program . But I found that it absend a file "token.inc" so that it can't be recomplier.
I think that it maybe you forgot it. Can you add it?
Thank you.
Post 11 Feb 2004, 14:34
View user's profile Send private message MSN Messenger Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 191
Location: Madrid - Spain
avcaballero
Hello, I've put it recently in DOS section, it is a small source code (not optimized) which print to the screen the 256 ASCII characters into formatted manner. It can be compiler into COM format. Comments in spanish, sorry Very Happy


Description:
Download
Filename: ASCIICF4.zip
Filesize: 2.46 KB
Downloaded: 360 Time(s)

Post 11 Feb 2004, 14:58
View user's profile Send private message Visit poster's website Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 191
Location: Madrid - Spain
avcaballero
I hope to be a good tranlation Very Happy


Description:
Download
Filename: ASCIICF5.zip
Filesize: 2.23 KB
Downloaded: 347 Time(s)

Post 11 Feb 2004, 15:40
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Kevin_Zheng wrote:
Dear Comrade:
I have watched your program:sysview.zip. It's a good program . But I found that it absend a file "token.inc" so that it can't be recomplier.
I think that it maybe you forgot it. Can you add it?
Thank you.


Updated (redownload). Thank you for noticing Smile

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 11 Feb 2004, 23:17
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
Hello,
I have made the first version of fasmenv.zip for DOS 16 beginners.
It is not much to brag about, but I hope to update it quickly.
Any suggestions, advice, or include files I can use would be appreciated.
If any one has a problem with what I'm doing, please advise me of it.
And, a big thanks Privalov for Fasm.

http://bitdog.home.att.net/files/fasmenv.zip

PS, every thing I made is totally free. Use it in any way you want.
BUT since it will be updated alot in the near future,
I would appreciate it if webmasters just linked to the fasmenv.zip
instead of putting a copy on their site,
so old flawed version won't be floating around the internet,
and the latest version is always available to every one.
I will not change the address or name so links won't be broken.
Bitdog
Post 12 Feb 2004, 05:12
View user's profile Send private message Reply with quote
Ralph



Joined: 04 Oct 2003
Posts: 86
Ralph
I got most of a forth based OS. I don't want to release it, but I don't mind giving you some words that may be useful to others like maybe ascii<->bin (>num and .), keyboard input and display output (accept/key and type/emit) and pretty much anything else that you want. Also has a simple memory manager that might be worth a glance. It's all 32-bit code. Please private message me if you want anything or I'll probably overlook it. I can zip it up with readme/makefile/etc, just let me know what if anything you want.
Post 12 Feb 2004, 07:27
View user's profile Send private message Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
new version out
http://bitdog.home.att.net/files/fasmenv.zip
still not complete or debugged, but I ran into some problems.
Please don't get me wrong here, I love Fasm,
but I have some requests for changes in Fasm:

Every thing that's not a reserved word should be an address. (or something like that)

Macro's should have local labels as default so local defines aren't required.

SHORT, NEAR, FAR should be reserved words for JMP or CALL distance also.

Align macro should be included in Fasm as a reserved word,
which inserts NOPs by default or recieves input
align 4 ;inserts NOPs
align 16 db 0 ;inserts zeros
align 16 ;align at 2,4,8,16,32,64,128,256,1024,or 4096 (NOPs)

Code:
AFAR2 = 102h
 ORG     100h    ; A.com
     USE16
START:     JMP BYTE WERK
AFAR DD 0x12345678
ANUM DB 13,10
WERK:       MOV     AX,[ANUM] ;fails because ANUM is NOT treated as an address
  MOV BYTE [START],5      ;this should work
HERE:  MOV WORD [HERE],0xFFFF  ;this should work too
    

Fasm has defined ANUM as a BYTE, but it's an offset address.
This stops me from accessing all kinds of stuff in memory.
I should be free to get any byte from any where using any label, or #value,
or anything that equates to a value to the assembler,
no matter where it's used in the code and for what purpose.

Above Fasm defined ANUM as a BYTE,
but it's the first byte at the address ANUM
I want to be able to move AX into the first word=offset of a Dword LABELx too.
I'm stoped me from altering one byte of a declaired word in memory.
I should be able to overwrite old code with data using pre existing labels.
In Nasm every thing that's not a reserved word is an address
and the reason is, is because that's the way the CPU see's it &
it works out better that way for the programmer.
Nasm will always be more powerfull than Fasm until the typing is removed.
It is simpler/easier on the assembler to treat every thing that equates
to a number as a number and allow address to be refered to by numbers.
Which is what they are.

Any way, if 5 pages of pre DEFINES, prototypes, extern declairations,
and M$ bloat ware (remember this name) gibberish isn't needed,
an assembler shouldn't demand it.

The perfect mariage between a programmer and his computer is:
The computer does the remembering (in referance files),
leaving the programmer free to concentrate on the goal.

The totally wrong way is:
The computer dumps out massive junk that the programmer has to remember,
which renders him useless.

The reality is:
A computer can dump out more junk than a person can ever remember,
and almost none of it is needed.
Code:
      MOV BYTE [START],AL
 MOV     AX,[START]      ; both of these should work

     MOV WORD [AFAR],AX
  MOV WORD [AFAR+1],AX
        MOV WORD [AFAR+2],AX
        MOV WORD [AFAR2],AX     ; these should work
    

These would work if everything was an address.
I use that kind of stuff all the time in Nasm & it's real handy.

Every thing is an address in assembled code to the CPU, and a debugger.
WYSIWYG = What You See Is What You Get, is important.
When learning from a debugger,
one should be able to write code in the same style as the debuggers output.

MOV WORD [100h],AX ;overwrite word at [DS:100h]
MOV BYTE [100h],AL ;overwrite byte at [DS:100h]

-------------------------------------------------------
Macro problems:
local label
if I make a macro in my program and only use it once,
I don't need to make the macro, I'll just write the code in the program.
If a macro has a non local label, it can only be used once.
If I use it twice, I have to define any labels in it as local
because labels in macro's in Fasm are not local by default.
Nasm has all macro labels as locals as default,
which is as it should be.
-------------------------------------------------------
Jmp problems:
JMP SHORT LABELx ; fails
JMP BYTE LABELx ; is correct,
but it's confusing in that LABELx isn't a declaired byte, I use an
SHORT EQU BYTE ;to solve the problem
but it would be better if they were reserved words included in Fasm ?
Most assemblers use the SHORT, NEAR, FAR key words.
I don't mean, take the BYTE, WORD, DWORD out. Just add the others?
---------------------------------------------------------

Please correct me if I'm incorrect about anything.
I didn't know how to phraze this diplomaticly,
so I blurted, forgive me plz.

Bitdog
Post 14 Feb 2004, 02:14
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
ANUM is a byte label, but AX is a word. You need to use "word" cast.

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 14 Feb 2004, 02:54
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Hi.
Bitdog wrote:

SHORT, NEAR, FAR should be reserved words for JMP or CALL distance also.


"near" and "far" are reserver words (of course). About "short" - FASM produces optimizations of jumps - it compiles the shortest possible form. So in 99% of cases you simply don't need to write anything. In the remaining 1% you may force FASM to produce another form of the instruction using byte, word and dword prefixes to the label. If you are used to use "short" etc. you may define them as equates: "short equ byte" for example. But if you convert NASM sources, simply remove any "short" prefix and everything should be compiled best possible way.

Quote:
Align macro should be included in Fasm as a reserved word,
which inserts NOPs by default or recieves input
align 4 ;inserts NOPs
align 16 db 0 ;inserts zeros
align 16 ;align at 2,4,8,16,32,64,128,256,1024,or 4096 (NOPs)


Align directive is included in FASM since version 1.50

Quote:
Fasm has defined ANUM as a BYTE, but it's an offset address.
This stops me from accessing all kinds of stuff in memory.
I should be free to get any byte from any where using any label, or #value,
or anything that equates to a value to the assembler,
no matter where it's used in the code and for what purpose.


You ARE free to accessing all kind of stuff in memory. Come on, it is not MASM Wink Simply FASM have typed labels. Every label or numeric IS an address, simply they have types assigned to them. Also there are untyped addresses. If you want to access the address not in it's native type, you simply have to write what type you want to use:
Code:
    org $100

    mov  al, [MyData+5]   ; does not need type casting.
    mov  ax, word [MyData+7]  ; need type identifier, because MyData is byte label.
    mov   eax, dword [$100]  ; numerics are untyped so you need type identifier.
MyData  db  'It is test string'  ; label type byte.
    


Quote:
Code:
      MOV WORD [100h],AX      ;overwrite word at [DS:100h]
    MOV BYTE [100h],AL      ;overwrite byte at [DS:100h]
    


Above is absolutely valid code for FASM. Smile

Quote:
Macro problems:
local label
if I make a macro in my program and only use it once,
I don't need to make the macro, I'll just write the code in the program.
If a macro has a non local label, it can only be used once.....


Hm, I think you missunderstood something. There are two completly different kinds of "local" labels in FASM. (Hm, maybe we need another therm for one of them) They havn't nothing common.

1. Macro local labels - that are labels that will be automatically generated as unique on every expanding of the macro - defined via "local" directive.
2. "program" local labels - This are labels that begins with '.' char. They are local relatively to the last global label - not begining with '.'

Regards.
Post 14 Feb 2004, 08:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
Hello, & thanks for the input.

I didn't know that Fasm optimised a jump to a SHORT/BYTE size so SHORT/BYTE isn't needed.
Nasm programmed me to include size, but new Nasm has some optimize in it
and that messed me up too.

The align 16 failed with my Fasm 1.49 then I noticed the new Fasm 1.51 didn't report
an error when I failed to include the align macro, but I thought it was a bug and didn't
align to the right offset adr. But now I know it does & I'll check it out better.
Oh well...... I'm learning...... Smile

Ok, I might have a ligitimate complaint on this one......
Code:
    org $100 

    mov  al, [MyData+5]   ; does not need type casting. 
    mov  ax, word [MyData+7]  ; need type identifier, because MyData is byte label. 
    mov   eax, dword [$100]  ; numerics are untyped so you need type identifier. 
MyData  db  'It is test string'  ; label type byte. 
    

The assembler should know it's size by the size of the Register,
Nasm isn't as multipass as Fasm, so Nasm requires MOV WORD [aLABEL],AX
but shouldn't fasm find something in the line that indicates size and
attach sizeof to [adr of aLABEL] & move the word into it.
BUT, I don't know about any conflicts with other things or would it limit ones
ability to freely program memory address ?
I'll learn to conform to Fasm eventually.

ANUM is a byte label, but AX is a word. You need to use "word" cast.
Word cast, Thanks, I'll look up the term & it's meaning/usage in detail.

I got a little carried away with my complaing,
and didn't double check it first....OOPs
Code:
   MOV WORD [100h],AX   ;overwrite word at [DS:100h] 
   MOV BYTE [100h],AL   ;overwrite byte at [DS:100h] 
    


Ok, local labels in a Fasm macro subject. (not refering to .LABEL (=other type of locals))
So Fasm requires that they be defined in the macro,
my request is that they are defined local by default
so you don't have to define them every time,
and if you want a nonlocal label, you define it as nonlocal. (er something.)
The reason being, I never use a nonlocal label in a macro,
but I do have macros that have jumps to a NonLocalLabel
Why would any one want to use a non local label in a macro ?
You could only use the macro once. and so there is no point in haveing a macro, just write the code.
But, I'll go check the FASM.TXT help for ver 1.51
and see if I can get some new info.
I've been reading the old 1.49 fasm.txt help. OOPs...

So in surmization, thanks JohnFound & Comrade
your both a big help to me.

Bitdog
PS, is there anything usefull to anyone in my
http://bitdog.home.att.net/files/fasmenv.zip
???? Where did I go wrong???? Suggestions are welcome,
I know its fraut with errors, that I find and fix daily,
but I was hoping for an overview to help aim my direction.....
Post 14 Feb 2004, 17:43
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
to local labels.

directive "local" in preprocessing directive and just extends label names by ? and some generated numeric constant.
Code:
 macro pushstr str
 {
   local string, behind   
   push string
   jump behind
   string db str
   behind:
 }
 pushstr 'aaaaa'
    

becomes after preprocessing something like
Code:
  push string?12341234
  jump behind?56785678
  string?12341234 db 'aaaaa'
  behind?56785678:
    

in assembly time, labels whose first char is '.' are appended to last global label so
Code:
  global:
  .local:
    

is same as
Code:
  global:
  global.local:
    

and labels absolutely shouldnt be local be local by default. You often generate global labels (which is same as numeric constant, as you demanded) with macro, like
Code:
macro enum prefix,initval,[name]
{
  local ..counter
    ..counter = initval
  forward
    prefix_#name = ..counter
    ..counter = ..counter + 1
}
    
Post 14 Feb 2004, 17:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.