Go to bottom

.COM register initialization

category: code [glöplog]
I'm trying to optimize a 38b .COM file down and for the life of me can't remember what .COM file register initializations are considered "safe". Looking at a debugger on my test rig, it APPEARS that this is true at .COM file startup:

Flags=no carry, no zero, no parity

Is this "reliable" or am I making too many assumptions?

I'm rusty; the only size tricks I can remember are:

RET can be used as a 1-byte "exit program"
PUSH reg1/POP reg2 is a 2-byte "copy from reg1 to reg2"
STOSW as a 1-byte text char output

If there is a pouet thread I should be consulting, please kick me (although I searched before posting this).
added on the 2012-12-13 23:37:54 by trixter trixter
was i the only one thinking about the .com TLD first when reading the title? ;D

I have no idea.
added on the 2012-12-14 01:04:44 by wysiwtf wysiwtf
some informations about initial values can be found here:

link me beautiful

and I think it is okay to make assumptions. there are many intros doing that. sure there might be machines where it won't run but that can happen to every program. assumptions are no guarantee - but they saves bytes :D

Fantastic link, thanks! That's exactly what I was looking for.

If I break the 32b barrier, I'll probably blog about it and post back here.
added on the 2012-12-14 17:23:29 by trixter trixter
but don't forget that in 32b no one cares about ESC and clean exit (=
You might also take a look at the specifications of the Hugi Size Coding Competitions, especially the last competitions.

Link: http://www.hugi.scene.org/compo/
added on the 2012-12-14 19:25:18 by Adok Adok
Quoting from the specifications of the last compo (#29, general.txt):

Code:You may assume that ... the registers have these values (all in hex): (xx - means an unknown value which MUST NOT be assumed) EAX = xxxx**** AL = 00 if first FCB has valid drive letter, FF if not AH = 00 if second FCB has valid drive letter, FF if not EBX = xxxx**** BL = 00 if first FCB has valid drive letter, FF if not BH = 00 if second FCB has valid drive letter, FF if not ECX = xxxx00FF EDX = xxxxxxxx DX = CS = DS = ES = SS = xxxx, 0080 <= DX <=9000. ESI = xxxx0100 EDI = xxxxFFFE EBP = xxxx09xx ESP = xxxxFFFE EIP = xxxx0100 EFLAGS (binary) = xxxxxxxx xxxxxxxx xxxxx01x xx0x0x1x i.e. DF = 0 IF = 1 other flags = x WORD [FFFE] = 0000 Layout of PSP: see [Memory Layout] ... that the program is not loaded high. ... that DPMI services are available. ... FCB functions can be used to access files whose name is given in 8.3 format. You must NOT assume that ... the FPU state is defined; you have to use FINIT to initialize it before using it.
added on the 2012-12-14 19:27:10 by Adok Adok
I ended up breaking the 16b barrier :-D
added on the 2012-12-14 20:19:31 by trixter trixter
Now I am _really_ curious about what you are doing :)
added on the 2012-12-14 21:02:49 by Preacher Preacher
Now I need to figure out what to do with it. Are there any 32b compos still around?
added on the 2012-12-14 21:04:53 by trixter trixter
Adok, sensen: Thanks for the links and info!

Preacher: Don't get too excited, it's in text mode :)
added on the 2012-12-14 21:40:34 by trixter trixter
Here's the final result: http://trixter.oldskool.org/2012/12/17/maze-generation-in-thirteen-bytes/
added on the 2012-12-17 18:05:05 by trixter trixter
added on the 2012-12-17 18:17:45 by Preacher Preacher
Oh man, 2 hours later and Peter Ferrie schooled me, he shaved a byte. :-) Nice.
added on the 2012-12-17 19:59:22 by trixter trixter


Go to top