I had an old game... Starflight. I think it came out in '86. Good ol' IBM PC jr days. I figured I'd break out a disassembler and see how it worked. I can see in the little that I've decoded, code size was optimized for sure... but I ended up jumping to an address that is outside of the file. That makes no sense.
I added the comments in below listing; they're my "thoughts".
Until other files are loaded with, I assume, int 0x3d
or int 0x0f
... since all segment registers point to the same memory segment.... and that segment is the code segment, the .COM file, every memory reference or jump should stay within the file. Yes?
Starflt.com
00000000 FA CLI ;Prevent interrupts
00000001 8CC8 MOV AX,CS ;Copy code segment to all segments
00000003 8ED0 MOV SS,AX
00000005 8EC0 MOV ES,AX
00000007 8ED8 MOV DS,AX
00000009 BE2901 MOV SI,word 0x0129 ;SI = 0x0129
0000000C 8B7C02 MOV DI,word [SI+0x02] ;DI = 0x3c15 (SI+2)
0000000F 47 INC DI
00000010 47 INC DI ;DI = 0x3c17
00000011 BB0507 MOV BX,word 0x0705 ;BX = 0x0705
00000014 8B1F MOV BX,word [BX] ;BX = 0xa924
00000016 81C30001 ADD BX,word 0x0100 ;BX = 0xaa24
0000001A 8BE3 MOV SP,BX ;SP = 0xaa24 (0x0e41)
0000001C 81C38000 ADD BX,word 0x0080 ;BX = 0xaaa4
00000020 8BEB MOV BP,BX ;BP = 0xaaa4 (0x0bae)
00000022 FB STI ;Restore Interrupts
00000023 FC CLD ;Clear direction flag
00000024 AD LODSW ;AX = DS:SI = 0xfa13
00000025 8BD8 MOV BX,AX ;BX = 0xfa13
00000027 FF27 JMP word [BX] ;Past COM EOF (0xd3a7)
Memory:
00000705 24 byte 0x24 '$'
00000706 A9 byte 0xA9 '©'
00000129 13 byte 0x13
0000012A FA byte 0xFA 'ú'
0000012B 15 byte 0x15
0000012C 3C byte 0x3C '<'
0000AA24 41 byte 0x41 'A'
0000AA25 0E byte 0x0E
0000AAA4 AE byte 0xAE '®'
0000AAA5 0B byte 0x0B