flat assembler
Message board for the users of flat assembler.

Index > DOS > [solved] Problem with procedure

Author
Thread Post new topic Reply to topic
Crumbler



Joined: 05 Mar 2020
Posts: 2
Crumbler 05 Mar 2020, 15:09
I'm trying to write a simple .com program.
The following code works with no issues:
Code:
        org     100h

Start:
        mov     ah, 09h
        mov     dx, strHello
        int     21h

        mov     ax, 0c08h      ; clear input buffer and wait to close window on key press
        int     21h
        test    al, al
        jnz     .RegularChar   ; if extended char, get it's code
        mov     ah, 08h
        int     21h
.RegularChar:

        ret

strHello:
        db      'Hello, world!', 13, 10, '$'    


I decided to put the last block of instructions in a procedure:
Code:
        org     100h

include 'MACRO/proc16.inc'

proc AwaitKey uses ax
        mov     ax, 0c08h      ; clear input buffer wait to close window on key press
        int     21h
        test    al, al
        jnz     .RegularChar   ; if extended char, get it's code
        mov     ah, 08h
        int     21h
.RegularChar:

        ret
endp

Start:
        mov     ah, 09h
        mov     dx, strHello
        int     21h

        stdcall AwaitKey

        ret

strHello:
        db      'Hello, world!', 13, 10, '$'    

However this time nothing was written to the console.
Everything that was written to the console gets cleared after calling AwaitKey for some reason.
Using a procedure(called via call) written like this works fine though:
Code:
AwaitKey:
        mov     ax, 0c08h      ; clear input buffer wait to close window on key press
        int     21h
        test    al, al
        jnz     .RegularChar   ; if extended char, get it's code
        mov     ah, 08h
        int     21h
.RegularChar:

        ret    

Why does this happen?

The program is assembled and run on a 32-bit Windows XP virtual machine.
Here are the docs for the DOS functions used in my code.
Post 05 Mar 2020, 15:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20458
Location: In your JS exploiting you and your system
revolution 05 Mar 2020, 15:16
The first executed instruction is at address 0x100, because a .com file has no header saying where to start, it simply begins at the first byte.

So for your code that would be the code in the procedure "AwaitKey".

Note that the label "Start" has no special meaning to the assembler. You can rename it or remove it, it makes no difference.
Post 05 Mar 2020, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Crumbler



Joined: 05 Mar 2020
Posts: 2
Crumbler 05 Mar 2020, 15:20
Thanks. This was a really stupid mistake on my part.
Post 05 Mar 2020, 15:20
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 805
Location: Russian Federation, Sochi
ProMiNick 05 Mar 2020, 15:43
Where did thou get proc16.inc?
It is one of that I publicate? or some other?
much of time file named proc16.inc presented in my package but only in last time there appear code related to 16 bit, all time before there was just a copy of proc32.inc with fragments related to 16bit and much of 32bit rudiments.
Post 05 Mar 2020, 15:43
View user's profile Send private message Send e-mail Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1403
Location: Piraeus, Greece
Picnic 06 Mar 2020, 06:25
I remember of a proc16.inc implementation by LocoDelAssembly.
Post 06 Mar 2020, 06:25
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 805
Location: Russian Federation, Sochi
ProMiNick 06 Mar 2020, 08:31
locals could make stack misaligned on 2 byte boundary (maybe it is problem or maybe not).
callbacks couldn`t be realized this way because they use retf as return not ret.
calling conventions are too modern (windows native calling convention for 16 bit is pascal, not cdecl or stdcall) - reserving params don`t looks like a problem.
nice date of publishing - far 2006.
Post 06 Mar 2020, 08:31
View user's profile Send private message Send e-mail Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 06 Mar 2020, 11:09
The author’s proc16.inc file must be fine. As far as I can guess, seems to be one of my university students as the program closely resembles the example I use in my lectures and TechHelp version is the one I share. As well as proc16.inc. Triple-checked in multiple pet projects.

Nice to see some students try to move further themselves. Hope to see a cool demo at the end of the year Wink
Post 06 Mar 2020, 11:09
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 805
Location: Russian Federation, Sochi
ProMiNick 06 Mar 2020, 17:36
DimonSoft, I'm a bit jealous that thou have thour own students and they are interested in assembler.
As thou I glad every time when I founding interesting demo. Hope It would be demonstration of one more technology never presented on forum before.
Post 06 Mar 2020, 17:36
View user's profile Send private message Send e-mail Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 07 Mar 2020, 09:27
I wouldn’t expect too much since it’s a starter’s course. But the goal set up is pretty ambitious.
Post 07 Mar 2020, 09:27
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.