flat assembler
Message board for the users of flat assembler.

Index > DOS > Hooray, finished my first program.

Author
Thread Post new topic Reply to topic
Mikor



Joined: 30 Aug 2007
Posts: 4
Location: Hull, England
Mikor 30 Aug 2007, 18:57
I've been using FASM for a grand total of about 2 hours now, and i've just finished my first program:
Code:
        org     100h
        mov     ah,     06h
        sub     al,     al
        mov     dl,     41h

cloop:
        int     21h
        inc     dl
        cmp     dl,     5Ah
        jle     cloop
    


It displays all upper-case letters, and compiles to 15B.

_________________
My Site
Post 30 Aug 2007, 18:57
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1417
Location: Piraeus, Greece
Picnic 30 Aug 2007, 20:13
Congrats Mikor Smile

_________________
Hobby BASIC Interpreter | Get Started
Post 30 Aug 2007, 20:13
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Aug 2007, 21:19
well done.

go on, and hurry to learn 32bit stuff, that is the real thing these days
Post 30 Aug 2007, 21:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8401
Location: Kraków, Poland
Tomasz Grysztar 30 Aug 2007, 21:36
I may have missed something, but how does that program exit?
Post 30 Aug 2007, 21:36
View user's profile Send private message Visit poster's website Reply with quote
Mikor



Joined: 30 Aug 2007
Posts: 4
Location: Hull, England
Mikor 30 Aug 2007, 21:49
Tomasz Grysztar wrote:
I may have missed something, but how does that program exit?

It just seems to terminate when it's done.

_________________
My Site
Post 30 Aug 2007, 21:49
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 30 Aug 2007, 22:14
Quote:

It just seems to terminate when it's done.

You should always have an explicit ending to your code. Luckily, it's ending properly right now, (you are probably using a version of DOS in Windows like the Windows XP DOS), but "real" DOS is likely to crash/otherwise mess up here.

Oh, and I would recommend that you start 32-bit programming as soon as you think that you can. You can read the source code of the "official" FASM examples, they should help quite a bit.
Post 30 Aug 2007, 22:14
View user's profile Send private message Reply with quote
eek



Joined: 21 Oct 2006
Posts: 24
eek 31 Aug 2007, 01:10
Tomasz Grysztar wrote:
I may have missed something, but how does that program exit?


Very Happy
It goes boom.
Post 31 Aug 2007, 01:10
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 31 Aug 2007, 04:16
> It just seems to terminate when it's done.

Bug Crying or Very sad

Code:
 mov ax,$4C00
 int $21
    


vid wrote:

> go on, and hurry to learn 32bit stuff, that is the real thing these days

YES. See FAQ at top of thread how to do "the real thing" in DOS Wink
Post 31 Aug 2007, 04:16
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 31 Aug 2007, 05:16
<sarcasm>
32-bit? That's OLD, you should be working on 64-bits exclusively! It's all the rage these days!
</sarcasm>

(BTW, there's some stuff you won't understand if you can't do 16-bit. But anyways, just start with and learn whatever is most interesting and fun.)
Post 31 Aug 2007, 05:16
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Aug 2007, 06:56
Quote:
(BTW, there's some stuff you won't understand if you can't do 16-bit. But anyways, just start with and learn whatever is most interesting and fun.)

agree.

starting with the 16 bit stuff is of course better because it gives you better understanding. but it takes years, and is almost not used, so it could be very little rewarding to one who learns. Sad
Post 31 Aug 2007, 06:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 31 Aug 2007, 09:23
int20 or ret is fine for ending a .com program, no need for the big int21/4c :]
Post 31 Aug 2007, 09:23
View user's profile Send private message Reply with quote
Mikor



Joined: 30 Aug 2007
Posts: 4
Location: Hull, England
Mikor 31 Aug 2007, 09:46
So, is this better then?
Code:
        org     100h

        mov     ah,     06h
        sub     al,     al
        mov     dl,     41h

cloop:
        int     21h
        inc     dl
        cmp     dl,     5Ah
        jle     cloop

        mov     ax,     4C00h
        int     21h    
Post 31 Aug 2007, 09:46
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 31 Aug 2007, 10:11
Mikor: yes, although you can use "ret" or "int 20h" to end the program since it's a .com file.

The reason your original code did exit is that, by chance, there was a byte sequence of either "0xC3" or "0xCD 0x20" present in memory "somewhere" after your own code... but there's no telling how many other instructions executed before that. (Although perhaps windows puts a ret or int20 when loading com files, dunno).
Post 31 Aug 2007, 10:11
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 31 Aug 2007, 10:14
Quote:
So, is this better then?


YES Smile

Code:
       mov     ah,     06h
       sub     al,     al
    


AH=2 is used more ... but 6 seems to be fine as well. Also, MOV AX,$0600 or MOV AH,6 only would do the job.

Code:
        jle     cloop
    


You have a pitfall here Shocked (but no bug for this code) - G and L are signed - you should use always A and B conditions except you are very sure that you want signed comparisons and know exactly what you are doing.

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 31 Aug 2007, 10:14
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 31 Aug 2007, 10:21
> although you can use "ret" or "int 20h" to end the program since it's a .com file.

True, but INT $21/$4C00 is safer when you change to EXE or to DPMI32 one day.

BTW, Under DPMI there are many additional funny ways how to exit your code, like jmp far 0:$FFFFFFFF, ud2, division by 0, lgdt [ebx], ... just anything (<- almost) illegal will (usually) safely exit your program too Laughing
Post 31 Aug 2007, 10:21
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 31 Aug 2007, 10:26
You should know whether you're doing a .com or .exe file... but okay, it's not like the size of the exit method matters much.

I wouldn't advise on using those "funny methods" to exit DPMI code though, since you'll be causing a crash - I dunno if all DPMI handlers will be very graceful about this, and a register dump certainly doesn't look too pretty to an end-user ^_^
Post 31 Aug 2007, 10:26
View user's profile Send private message Reply with quote
Mikor



Joined: 30 Aug 2007
Posts: 4
Location: Hull, England
Mikor 31 Aug 2007, 11:24
Just edited my code again, and annotated it.
Code:
        ;Tell the OS that this is a COM.
        org     100h

        mov     ax,     0600h
        mov     dl,     41h

cloop:
        int     21h
        inc     dl
        cmp     dl,     5Ah
        ;JLE is signed, we want JBE (Jump if Below or Equal)
        jbe     cloop

        ;RET should be ok for COMs
        ret

        ;However, use the following when making EXEs
        ;mov     ax,     4C00h
        ;int     21h    


I'll try EXEs later, when i'm more used to assembly.
Post 31 Aug 2007, 11:24
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 02 Sep 2007, 17:55
Mikor: Welcome to the asm world Smile
Post 02 Sep 2007, 17:55
View user's profile Send private message 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.