flat assembler
Message board for the users of flat assembler.
Index
> DOS > Problem with ExitIfESC macro |
Author |
|
Matrix 23 Jan 2006, 13:17
Slai wrote:
hi, well this does not look good, you pop back ax after you exit, so what whould be your problem? the program gets into full screen mode? it will surely get to fullscreen mode if you go graphical, on w98 and winxp too, you can use dosemu on windows, that handles graphic modes in a window. |
|||
23 Jan 2006, 13:17 |
|
Tomasz Grysztar 23 Jan 2006, 14:24
Actually this code is a proper way to do this and should correctly exit on ESC. If after setting text mode the command prompt (or whatever shell you run it from) doesn't come back, it may mean that you have corrupted some of the DOS memory with some other code, what caused DOS to hang after your program exited. Check out all the other code in your program for the possibility that it writes into some memory area that it shouldn't write to.
|
|||
23 Jan 2006, 14:24 |
|
Slai 23 Jan 2006, 21:12
Yes, it appeared that there is nothing wrong with the code .. It was just because I ran the program with F9 from FASMW ..
When I ran the program in the Windows Explorer, everything was as it is suppose to be One more little question that is actualy for the Macroinstructions section, but it is related to the exiting from VGA to DOS. As I know there is no difference between int 20h, and mov ah,4Ch int 21h , exept that the one is returning exit code, right ? so now I have a Exit macro like this: Code: macro Exit _ExitCode { if _ExitCode eq int 20h else mov al,_ExitCode mov ah,4Ch int 21h end if } mov ax,3 int 10h int 20h ? or I just must change the macro to : Code: macro Exit _ExitCode { if _ExitCode eq mov ax,3 int 10h int 20h else mov ax,3 int 10h mov al,_ExitCode mov ah,4Ch int 21h end if } |
|||
23 Jan 2006, 21:12 |
|
Tomasz Grysztar 23 Jan 2006, 21:24
Function 0Fh checks for current video mode, so you can check for mode 3 like this:
Code: mov ah,0Fh int 10h cmp al,3 je already_in_text_mode Also it's not true that there's no difference between int 20h and function 4Ch of int 21h other than exit code - the int 20h requires CS to be the segment with PSP (which is true in .com files, but in case of .exe it can be true only when they are set up in that special way), while int 21h/function 4Ch can be called from anywhere. |
|||
23 Jan 2006, 21:24 |
|
vid 23 Jan 2006, 22:00
And IMO for this shouldn't be used macro, but rather some procedure
|
|||
23 Jan 2006, 22:00 |
|
Slai 23 Jan 2006, 22:49
Yes, I was almost sure that this check can not be done with macroinstructions, but just wanted to make sure.
Thanks For now on I will use int 20h only in the .com files for security |
|||
23 Jan 2006, 22:49 |
|
vid 23 Jan 2006, 23:44
it CAN be done, but it seems you don't understand what macroinstructions are. (or what they are for)
They do only textual substition before compiling your code, so writing: Code: macro a {x y z} mov eax,5 a mov eax,6 a a will be just same as if you would write Code: mov eax,5 x y z mov eax,6 x y z x y z They aren't good for often-used routines, because then you will end up having same routine 50 times in code. It is better to have it once in code, as procedure, and then just call it. |
|||
23 Jan 2006, 23:44 |
|
Slai 24 Jan 2006, 01:47
I know that, but I prefer optimizing for speed than optimising for size .. especially in graphics and game programs ..
Although, if I have to repeat the same code more than 10-20 times, I will probably use a procedure. |
|||
24 Jan 2006, 01:47 |
|
vid 24 Jan 2006, 02:23
well, usually only small "innermost" (in code hierarchy) parts of code need to be optimized, eg. those which are executed most of time, and these usually don't have exit-if-ESC-pressed check But it's allright if you know what you are doing.
Also not that this decreases readability of your code, because if someone else (or you after some time) look at the code, you don't know what all the macros really do and you have to lookup their definition or quess (possibly wrong). Maybe it looks better for you know, but in big long-term project this isn't very good idea. |
|||
24 Jan 2006, 02:23 |
|
rugxulo 24 Jan 2006, 08:34
Plus int 21h, 4Ch closes any open files.
Tomasz Grysztar wrote: Also it's not true that there's no difference between int 20h and function 4Ch of int 21h other than exit code - the int 20h requires CS to be the segment with PSP (which is true in .com files, but in case of .exe it can be true only when they are set up in that special way), while int 21h/function 4Ch can be called from anywhere. |
|||
24 Jan 2006, 08:34 |
|
Slai 26 Jan 2006, 05:56
what about ret .. What is the risk if I exit the program with ret ?
|
|||
26 Jan 2006, 05:56 |
|
Tomasz Grysztar 26 Jan 2006, 07:53
You can only exit from .com programs with ret.
This works because of the few facts combined: 1) The .com program is loaded into the same segment as its PSP, just after it (the size of PSP is 100h bytes), so the CS is the same as the PSP segment. 2) The first two bytes of PSP are 0CDh and 20h, which is an opcode of "int 20h" instruction. 3) The stack for .com program is set up on the top of the same segment, with one zero word (two zero bytes) initially pushed on it, so SS=CS(=DS=ES), SP=0FFFEh, and word [0FFFEh]=0. Now when you execute a RET instruction, it takes the return address from the stack, and it is 0, so it goes to CS:0, and because CS is the PSP segment, it executes the "int 20h" and thus exits the program. With .exe program this won't work this way, except for some very special cases. |
|||
26 Jan 2006, 07:53 |
|
2 18 Dec 2006, 10:06
That's what I needed to know.
I only do COM files in DOS,so no worries there. I can save 1 byte of space! |
|||
18 Dec 2006, 10:06 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.