Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem linking files with tlink

Status
Not open for further replies.

x86

IS-IT--Management
Oct 17, 2002
1
ZA
Hi. I was reading a book on asm and I am currently on a chapter where we are learning to link multiple source files to create a single .COM file. The book is using MASM but I am using TASM and I am having some trouble linking the source files. I have copied the source for each file directly out of the book and then assembled them. But, when I try to link them (by using tlink /t file1 file2) I get "Cannot generate COM file : invalid initial entry point address" I thought it sounded like something that had to do with missing an ORG 100h but I checked and it is there. Here is the source for file1 and file2 if that helps:

file1:

CODE_SEG SEGMENT PUBLIC
ASSUME CS:CODE_SEG
ORG 100h

EXTRN WRITE_DECIMAL:NEAR

TEST_WRITE_DECIMAL PROC NEAR
MOV DX, 12345
CALL WRITE_DECIMAL
INT 20h
TEST_WRITE_DECIMAL ENDP

CODE_SEG ENDS

END TEST_WRITE_DECIMAL

file2:
CODE_SEG SEGMENT PUBLIC
ASSUME CS:CODE_SEG

PUBLIC WRITE_HEX

WRITE_HEX PROC NEAR
PUSH CX
PUSH DX
MOV DH, DL
MOV CX, 4
SHR DL,CL
CALL WRITE_HEX_DIGIT
MOV DL, DH
AND DL, 0Fh
CALL WRITE_HEX_DIGIT
POP DX
POP CX
RET
WRITE_HEX ENDP

PUBLIC WRITE_HEX_DIGIT

WRITE_HEX_DIGIT PROC NEAR
PUSH DX
CMP DL, 10
JAE HEX_LETTER
ADD DL, "0"
JMP Short WRITE_DIGIT
HEX_LETTER:
ADD DL, "A"-10
WRITE_DIGIT:
CALL WRITE_CHAR
POP DX
RET
WRITE_HEX_DIGIT ENDP

PUBLIC WRITE_CHAR

WRITE_CHAR PROC NEAR
PUSH AX
MOV AH, 2
INT 21h
POP AX
RET
WRITE_CHAR ENDP

PUBLIC WRITE_DECIMAL

WRITE_DECIMAL PROC NEAR
PUSH AX
PUSH CX
PUSH DX
PUSH SI
MOV AX, DX
MOV SI, 10
XOR CX, CX
NON_ZERO:
XOR DX, DX
DIV SI
PUSH DX
INC CX
OR AX, AX
JNE NON_ZERO
WRITE_DIGIT_LOOP:
POP DX
CALL WRITE_HEX_DIGIT
LOOP WRITE_DIGIT_LOOP
END_DECIMAL:
POP SI
POP DX
POP CX
POP AX
RET
WRITE_DECIMAL ENDP

CODE_SEG ENDS

END

Now I have tried another source file from the book and I was able to link that to file2. I don't understand why this one worked and the other didn't. Here is the code again for both files in case that helps

new file1:

CGROUP GROUP CODE_SEG, DATA_SEG
ASSUME CS:CGROUP, DS:CGROUP

CODE_SEG SEGMENT PUBLIC
ORG 100h

EXTRN WRITE_HEX:NEAR
EXTRN WRITE_CHAR:NEAR

DISP_LINE PROC NEAR
XOR BX, BX
MOV CX, 16
HEX_LOOP:
MOV DL, SECTOR[BX]
CALL WRITE_HEX
MOV DL, ' '
CALL WRITE_CHAR
INC BX
LOOP HEX_LOOP
INT 20h
DISP_LINE ENDP

CODE_SEG ENDS

DATA_SEG SEGMENT PUBLIC
PUBLIC SECTOR
SECTOR DB 10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
DB 18h, 19h, 1Ah, 1Bh, 1Ch, 1Dh, 1Eh, 1Fh
DATA_SEG ENDS

END DISP_LINE

file2:

CODE_SEG SEGMENT PUBLIC
ASSUME CS:CODE_SEG
ORG 100h


TEST_WRITE_DECIMAL PROC NEAR
MOV DX, 12345
CALL WRITE_DECIMAL
INT 20h
TEST_WRITE_DECIMAL ENDP

PUBLIC WRITE_HEX

WRITE_HEX PROC NEAR
PUSH CX
PUSH DX
MOV DH, DL
MOV CX, 4
SHR DL,CL
CALL WRITE_HEX_DIGIT
MOV DL, DH
AND DL, 0Fh
CALL WRITE_HEX_DIGIT
POP DX
POP CX
RET
WRITE_HEX ENDP

PUBLIC WRITE_HEX_DIGIT

WRITE_HEX_DIGIT PROC NEAR
PUSH DX
CMP DL, 10
JAE HEX_LETTER
ADD DL, "0"
JMP Short WRITE_DIGIT
HEX_LETTER:
ADD DL, "A"-10
WRITE_DIGIT:
CALL WRITE_CHAR
POP DX
RET
WRITE_HEX_DIGIT ENDP

PUBLIC WRITE_CHAR

WRITE_CHAR PROC NEAR
PUSH AX
MOV AH, 2
INT 21h
POP AX
RET
WRITE_CHAR ENDP

PUBLIC WRITE_DECIMAL

WRITE_DECIMAL PROC NEAR
PUSH AX
PUSH CX
PUSH DX
PUSH SI
MOV AX, DX
MOV SI, 10
XOR CX, CX
NON_ZERO:
XOR DX, DX
DIV SI
PUSH DX
INC CX
OR AX, AX
JNE NON_ZERO
WRITE_DIGIT_LOOP:
POP DX
CALL WRITE_HEX_DIGIT
LOOP WRITE_DIGIT_LOOP
END_DECIMAL:
POP SI
POP DX
POP CX
POP AX
RET
WRITE_DECIMAL ENDP

CODE_SEG ENDS

END TEST_WRITE_DECIMAL

Thanks for your time.
 
i think this is because two different code segments in the two files. in a com file, there should be only one code segment.

i don't know much but hope this will give you a hint.
 
Hey, if this ant too late, you have to go through 3 steps to create a .com out of a .asm file, first you use tasm i belive, then its tlink, or vice versa (i forget now) but then once youve got your .exe file, you need to use a program that converts .exe files to .com, i got a simple one called exe2bin.exe , should be able to find that on the net. Good luck with your asm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top