flat assembler
Message board for the users of flat assembler.

Index > DOS > Code not working properly after int21 AH=4C [SOLVED]

Author
Thread Post new topic Reply to topic
redsimplex



Joined: 13 May 2016
Posts: 4
redsimplex 13 May 2016, 03:29
I was working on a code for some time and it went smooth until I added a variable called [origin_color] and after that the terminat interrupt started working incorectly.
Basiclly the code needs to return back to the dos terminal after you press ESC, but it just hangs on instead.

after deleting most of the code but leaving some parts in the code still not works, example:

Code:
format mz

entry code:start


segment varseg
        black_color db ?
        green_color db ?
        orgin_color db ?

        mouse_status db ?
        mouse_x dw ?
        mouse_y dw ?
        previous_x dw ?
        previous_y dw ?
        two dw ?


segment code
        start:

                mov [two], 02h
                mov [green_color], 02h
                mov [orgin_color], 09h

                mov ax, 13h
                int 10h

                main_loop:
                        keyboard_input:
                        in al, 60h
                        dec al
                        jz exit
                        jmp main_loop

        exit:

                mov ah, 4ch
                int 21h    


if you erase

Code:
                mov [two], 02h
                mov [green_color], 02h
                mov [orgin_color], 09h    


the code suddenly works.

Can someone explain why its happening, and how can I fix it? Crying or Very sad

edit1:

Following in a debug you find that that code runs until you press 'esc', then the IP jumps to 'exit' where it suppose to terminate the program and return, but after int 21h it just stacks Sad

and I searched for sometime for an answer in google and in the search in this board and could'nt find anything as the FAQ suggested.


Last edited by redsimplex on 13 May 2016, 06:24; edited 1 time in total
Post 13 May 2016, 03:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20432
Location: In your JS exploiting you and your system
revolution 13 May 2016, 04:50
You don't seem to be initialising the DS register with the value of varseg.
Post 13 May 2016, 04:50
View user's profile Send private message Visit poster's website Reply with quote
redsimplex



Joined: 13 May 2016
Posts: 4
redsimplex 13 May 2016, 06:24
revolution wrote:
You don't seem to be initialising the DS register with the value of varseg.

thanks! problem solved.
But I don't understand what happened there, will you mind to explain?
Post 13 May 2016, 06:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20432
Location: In your JS exploiting you and your system
revolution 13 May 2016, 07:03
When you don't specify a different segment register all the memory writes that don't use SP are controlled by DS.
Post 13 May 2016, 07:03
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 13 May 2016, 07:13
DOS does not set DS to a useful value when starting an EXE. You were effectively writing to a location in memory that wasn't where your variables were located.
Post 13 May 2016, 07:13
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.