Search code examples
assemblylinkerx86dosmasm

how to know where the commands where determinated - in the compilation/ link/ load - assembly x86 masm by MAP&LST files


I am trying to check when the commands in red circle were determined - in the compilation process/link process/load process, but I dont know how to do it :((

enter image description here

I read about it a bit and I was found that I need to take a look in the LST and MAP files of the codes (p1.asm, p2.asm) and there I will get the answear... but unfortuently, as I said, I don't find there answears....

Thanks alot for any help,

I adding here the codes and the LST,MAP files

this is the code: p1.asm -

.model small
.data
 char dw 2E41h ;'A'
 public char
 msg db 'My string$'
 public msg

.code
 mov ax,bx
L1: mov cx,ax
 jmp L2

.code
HERE:
 mov ax, @data
 mov ds, ax
 mov ax, 0B800h
 mov es, ax

 jmp far ptr L1
L2:
 extern CONT:near
 jmp CONT
end HERE

p2.asm -

.model small
.stack 100h
.data
 extern char:word
 extern msg:byte
.code
public CONT
CONT:
 mov ax,char
 mov es:[340h], ax

 mov bx, offset msg
 mov dl, msg[5]
 mov dh,ds:[msg+6]

 mov ah,4ch
 int 21h
 end

Lst file - (p1.LST) :

Microsoft (R) Macro Assembler Version 6.11          07/08/18 02:41:49
p1.asm                               Page 1 - 1


                .model small
 0000               .data
 0000 2E41           char dw 2E41h ;'A'
                 public char
 0002 4D 79 20 73 74 72      msg db 'My string$'
       69 6E 67 24
                 public msg

 0000               .code
 0000  8B C3             mov ax,bx
 0002  8B C8            L1: mov cx,ax
 0004  EB 0F             jmp L2

 0006               .code
 0006               HERE:
 0006  B8 ---- R         mov ax, @data
 0009  8E D8             mov ds, ax
 000B  B8 B800           mov ax, 0B800h
 000E  8E C0             mov es, ax

 0010  EA ---- 0002 R        jmp far ptr L1
 0015               L2:
                 extern CONT:near
 0015  E9 0000 E         jmp CONT
                end HERE
Microsoft (R) Macro Assembler Version 6.11          07/08/18 02:41:49
p1.asm                               Symbols 2 - 1




Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

DGROUP . . . . . . . . . . . . .    GROUP
_DATA  . . . . . . . . . . . . .    16 Bit   000C     Word    Public  'DATA'    
_TEXT  . . . . . . . . . . . . .    16 Bit   0018     Word    Public  'CODE'    


Symbols:

                N a m e                 Type     Value    Attr

@CodeSize  . . . . . . . . . . .    Number   0000h   
@DataSize  . . . . . . . . . . .    Number   0000h   
@Interface . . . . . . . . . . .    Number   0000h   
@Model . . . . . . . . . . . . .    Number   0002h   
@code  . . . . . . . . . . . . .    Text     _TEXT
@data  . . . . . . . . . . . . .    Text     DGROUP
@fardata?  . . . . . . . . . . .    Text     FAR_BSS
@fardata . . . . . . . . . . . .    Text     FAR_DATA
@stack . . . . . . . . . . . . .    Text     DGROUP
CONT . . . . . . . . . . . . . .    L Near   0000     _TEXT External
HERE . . . . . . . . . . . . . .    L Near   0006     _TEXT 
L1 . . . . . . . . . . . . . . .    L Near   0002     _TEXT 
L2 . . . . . . . . . . . . . . .    L Near   0015     _TEXT 
char . . . . . . . . . . . . . .    Word     0000     _DATA Public
msg  . . . . . . . . . . . . . .    Byte     0002     _DATA Public

       0 Warnings
       0 Errors

p2.LST -

Microsoft (R) Macro Assembler Version 6.11          07/08/18 02:41:52
p2.asm                               Page 1 - 1


                .model small
                .stack 100h
 0000               .data
                 extern char:word
                 extern msg:byte
 0000               .code
                public CONT
 0000               CONT:
 0000  A1 0000 E         mov ax,char
 0003  26: A3 0340       mov es:[340h], ax

 0007  BB 0000 E         mov bx, offset msg
 000A  8A 16 0005 E      mov dl, msg[5]
 000E  8A 36 0006 E      mov dh,ds:[msg+6]

 0012  B4 4C             mov ah,4ch
 0014  CD 21             int 21h
                end
Microsoft (R) Macro Assembler Version 6.11          07/08/18 02:41:52
p2.asm                               Symbols 2 - 1




Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

DGROUP . . . . . . . . . . . . .    GROUP
_DATA  . . . . . . . . . . . . .    16 Bit   0000     Word    Public  'DATA'    
STACK  . . . . . . . . . . . . .    16 Bit   0100     Para    Stack   'STACK'    
_TEXT  . . . . . . . . . . . . .    16 Bit   0016     Word    Public  'CODE'    


Symbols:

                N a m e                 Type     Value    Attr

@CodeSize  . . . . . . . . . . .    Number   0000h   
@DataSize  . . . . . . . . . . .    Number   0000h   
@Interface . . . . . . . . . . .    Number   0000h   
@Model . . . . . . . . . . . . .    Number   0002h   
@code  . . . . . . . . . . . . .    Text     _TEXT
@data  . . . . . . . . . . . . .    Text     DGROUP
@fardata?  . . . . . . . . . . .    Text     FAR_BSS
@fardata . . . . . . . . . . . .    Text     FAR_DATA
@stack . . . . . . . . . . . . .    Text     DGROUP
CONT . . . . . . . . . . . . . .    L Near   0000     _TEXT Public
char . . . . . . . . . . . . . .    Word     0000     _DATA External
msg  . . . . . . . . . . . . . .    Byte     0000     _DATA External

       0 Warnings
       0 Errors

and finally - p1p2.MAP :

 Start  Stop   Length Name                   Class
 00000H 0002DH 0002EH _TEXT                  CODE
 0002EH 00039H 0000CH _DATA                  DATA
 00040H 0013FH 00100H STACK                  STACK

 Origin   Group
 0002:0   DGROUP

Program entry point at 0000:0006

Solution

  • In general that is not enough information because the separate lst files don't show how they will be linked together. Luckily one of your files has no data and we see how the code has been linked (p2 follows p1 in memory). Also note that the load address 05E6 is determined at runtime so you don't know that in advance. That said, here is how to get the values:

    1. L2 is in the symbol table as 0015 so that's trivial.
    2. From the map file we can see that DGROUP starts at 0002:0 which is relative to the load segment of 05E6 hence 05E8.
    3. B800 is a constant in the asm, how is that even a question.
    4. jmp far ptr L1 See points 1 and 2 above.
    5. jmp cont From p2.lst we see CONT has address 0000 and we figured code from p2 follows p1 and that code size for p1 is 0018 hence 0018+0000=0018.
    6. mov ax,char From p1.lst we see char has address 0000. From the mapfile we see that _DATA starts at 002E but DGROUP starts at 0002:0 hence all offsets in _DATA need to be incremented by 002E-0020=000E.
    7. See point 3 above.
    8. msg is 0002+000E=0010 (see point 6 above). I trust you can then add 5 and 6.