News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

linking modules....

Started by ch4o7ic, October 10, 2005, 12:48:48 AM

Previous topic - Next topic

ch4o7ic

I have an assignment for my assembly class which asks me to link a couple of modules together with an .inc file that i wrote.  The problem is that i do not know exactly how to do this, i looked through the book we are using and wrote the file like it had shown, but all to no avail, it said something like....

Assembling: FactorialTest.asm
FactorialTest.obj : error LNK2001: unresolved external symbol _NRfactorial@0
FactorialTest.obj : error LNK2001: unresolved external symbol _Rfactorial@0
FactorialTest.exe : fatal error LNK1120: 2 unresolved externals
Press any key to continue . . .

if anyone can help me it would be greatly appreciated.

here are the other files...

1)
TITLE Factorial Tests      (FactorialTest.asm)

;   Nick Hauschild
;   CSci 373
;   Homework 8.1

; This program's purpose is to test factorial
; procedures that are given from another program.

include Factorial.inc

.data

   n DWORD ?
   prompt BYTE "Input a number to find a factorial for.",0dh, 0ah, 0
   NRout BYTE "Milliseconds for non-recursive factorial procedure: ", 0
   Rout BYTE "Milliseconds for recursive factorial procedure: ", 0
   startTime DWORD ?

.code
;--------------------------------------------------
;-----------------Main Procedure-------------------
;--------------------------------------------------
main proc

   mov edx, offset prompt
   call writeString
   call crlf
   call readInt
   mov n, eax
   call getMSeconds
   mov startTime, eax
   push n
   call NRfactorial
   call getMSeconds
   sub eax, startTime
   mov edx, offset NRout
   call writeString
   call writeDec
   call crlf
   call crlf
   mov n, eax
   call getMSeconds
   mov startTime, eax
   push n
   call Rfactorial
   call getMSeconds
   sub eax, startTime
   mov edx, offset Rout
   call writeString
   call writeDec

   exit
main endp
end main

2)
TITLE Recursive Factorial      (_Rfactorial.asm)

include Factorial.inc

.code
;---------------------------------------------------------
Rfactorial proc
;
; Calculates a factorial recursively
; Receives: [ ebp + 8 ] = n, the number to calculate
; Returns: eax = the factorial of n
;---------------------------------------------------------

   push ebx
   push ebp
   mov ebp, esp
   mov eax, [ ebp + 8 ]
   cmp eax, 0
   ja L1
   mov eax, 1
   jmp L2
   
L1:
   
   dec eax
   push eax
   call Rfactorial
   
   mov ebx, [ ebp + 8 ]
   mul ebx
   
L2:
   
   pop ebp
   pop ebx

   ret 4

Rfactorial endp
end

3)
TITLE Non-Recursive Factorial      (_NRfactorial.asm)

include Factorial.inc

.code

;---------------------------------------------------------
NRfactorial proc
;
; Calculates a factorial non-recursively
; Receives: [ ebp + 8 ] = n, the number to calculate
; Returns: eax = the factorial of n
;---------------------------------------------------------
   
   push edx
   push ebx
   push ecx
   push ebp
   mov ebp, esp
   mov edx, [ ebp + 8 ]
   mov ebx, 1
   dec edx
   mov ecx, edx
   inc edx

t3hLoop:
   
   mov eax, edx
   mul ebx
   mov ebx, eax
   dec edx
   loop t3hLoop
   
   pop ebp
   pop ecx
   pop ebx
   pop edx
   
   ret 4
NRfactorial endp
end

4) inc file
;(Factorial.inc)

include Irvine32.inc

NRfactorial PROTO
Rfactorial PROTO

sluggy

Nick,
you need to show us what your link command looked like. Are you assembling each segment separately, then linking them all, or should you also be including Rfactorial.asm and NRfactorial.asm into FactorialTest.asm before assembling?

ch4o7ic

i use textpad to assemble and run all of my .asm files.  Usually when i assemble a program it just links with the other .inc files that came with the package.  so when i am making my own, i just tried to assemble it with textpad and it came up with those errors.

if you cannot help me with this information that is fine, i will see if my professor can better explain it to me.

thanks again,
nick

hutch--

ch4o7ic,

It depends how you are building the code but I would tend to put the include file at the beginning with a complete path to where the include files and libraries are so the assembler finds them. The errors you are getting at the moment are the linker not being able to find the libraries.

I notice trhat you have no "includelib" line in your code and unless you are using a build batch file that has thew library included, it has no way of finding the required code so you will get the "unresolved external" error.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ch4o7ic

thanks hutch....

i had to write my own batch file, shows how new i am to assembly.

thanks again everyone