First post, by Exploit
I have three assembler files for DOS, these are:
; Note: Quit with CTRL+C
; Program name: MAIN.ASM
EXTRN WAIT_X:FAR
.MODEL SMALL
.STACK 256
.CODE
START:
MOV DL, 00h
M1:
MOV AH, 02h
INT 21h ; Shows value of DL register
INC DL
CALL WAIT_X ; subroutine call of WAIT_X
JMP M1
MOV AH, 4Ch ; return to DOS
INT 21h
END START
; Note: With manual register saving
; Program name: WAIT_A.ASM
PUBLIC WAIT_X
.MODEL SMALL
.STACK 256
.CODE
WAIT_X PROC FAR ; subroutine
PUSH BX
PUSH CX
MOV BL, 80H ; delay loop
M2: MOV CX, 0FFFFh ; outer loop
M1: DEC CX ; inner loop
JNZ M1
DEC BL
JNZ M2
POP CX
POP BX
RET ; return to main
WAIT_X ENDP
END
and
; Note: With USES directive and language type C
; Program name: WAIT_B.ASM
PUBLIC WAIT_X
.MODEL SMALL, C
.STACK 256
.CODE
WAIT_X PROC FAR USES BX CX ; subroutine
MOV BL, 80H ; delay loop
M2: MOV CX, 0FFFFh ; outer loop
M1: DEC CX ; inner loop
JNZ M1
DEC BL
JNZ M2
RET ; return to main
WAIT_X ENDP
END
WAIT_A.ASM and WAIT_B.ASM use both the same public routine name WAIT_X which is called by MAIN.ASM
The only difference is, that WAIT_B does make use of the USES assembler directive and this directive expects to have a language type set in the directive .MODEL
diff WAIT_A.ASM WAIT_B.ASM
1,2c1,2
< ; Note: With manual register saving
< ; Program name: WAIT_A.ASM
---
> ; Note: With USES directive and language type C
> ; Program name: WAIT_B.ASM
4c4
< .MODEL SMALL
---
> .MODEL SMALL, C
8,10c8
< WAIT_X PROC FAR ; subroutine
< PUSH BX
< PUSH CX
---
> WAIT_X PROC FAR USES BX CX ; subroutine
18,19d15
< POP CX
< POP BX
When i use the following comands:
jwasmr -0 MAIN.ASM WAIT_A.ASM WAIT_B.ASM
wlink name main_a file main,wait_a
wlink name main_b file main,wait_b
The assembly of the files works without erros:
JWasm v2.14, Dec 20 2020, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
MAIN.ASM: 20 lines, 2 passes, 0 ms, 0 warnings, 0 errors
WAIT_A.ASM: 23 lines, 2 passes, 0 ms, 0 warnings, 0 errors
WAIT_B.ASM: 19 lines, 2 passes, 0 ms, 0 warnings, 0 errors
And wlink works with the WAIT_A.OBJ file but it fails with the similar but not identical WAIT_B.OBJ file.
It gives the following error message when using WAIT_B.OBJ:
Error! E2028: WAIT_X is an undefined reference
creating a DOS executable
file main.obj(MAIN.ASM): undefined symbol WAIT_X
Can anyone tell me how to fix this and why this error occurs?
Both WAIT* files use the PUBLIC directive to make the WAIT_X function public.
And MAIN.ASM has a EXTRN WAIT_X:FAR directive, thus it should know that WAIT_X function.
But still, it fails.
Personally i assume, that the set language type C in the .MODEL directive is the problem. At least the same error will occur, if i set the same language type in WAIT_A.ASM to C.
But i don't know, how to solve that.
I also tried other language types, like FASTCALL
.MAIN SMALL, FASTCALL
but this didn't solve it.