.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:
ES=DS=SS=CS
IP=0100h
AX=BX=CX=DX=BP=SI=DI=0000h
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).
ES=DS=SS=CS
IP=0100h
AX=BX=CX=DX=BP=SI=DI=0000h
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).
was i the only one thinking about the .com TLD first when reading the title? ;D
PS:
I have no idea.
PS:
I have no idea.
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
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.
If I break the 32b barrier, I'll probably blog about it and post back here.
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/
Link: http://www.hugi.scene.org/compo/
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.
I ended up breaking the 16b barrier :-D
Now I am _really_ curious about what you are doing :)
Now I need to figure out what to do with it. Are there any 32b compos still around?
Adok, sensen: Thanks for the links and info!
Preacher: Don't get too excited, it's in text mode :)
Preacher: Don't get too excited, it's in text mode :)
Here's the final result: http://trixter.oldskool.org/2012/12/17/maze-generation-in-thirteen-bytes/
Duude...
Oh man, 2 hours later and Peter Ferrie schooled me, he shaved a byte. :-) Nice.