News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Undefined Symbol?

Started by arsenalftw067, October 23, 2015, 12:29:21 PM

Previous topic - Next topic

arsenalftw067

I get an error saying: Undefined symbol SortArray
Undefined symbol ShowArray

SortArrray and ShowArray are both procs which I'm calling from my main



TITLE Sort array (Array.asm)

; This program sorts an array with random integers
; and outputs them in order

INCLUDE Irvine32.inc ; new
includelib C:\Irvine\Kernel32
includelib C:\Irvine\User32
includelib C:\Irvine\Irvine32

.data
array BYTE 20, 10, 60, 5, 120, 90, 100 ; array with 6 values
arraysize = ($ - array) -1 ; size of array


.code
main PROC
mov esi, OFFSET array
mov ecx, arraysize;
call SortArray ; call function to sort
call ShowArray ; call function to show

call DumpRegs ; display the registers
call WaitMsg        ; Pause until a key is pressed
exit
main ENDP
END main

SortArray PROC

L1:
push ecx
mov edi, esi ; use seond pointer
mov eax, [esi]
L2:
add edi, 2
CMP eax, [edi]; compare second value with previous
call ShowArray
JGE exchg ; perform exchange
JLE dntxchg ; dont perform exchange

add esi, 2
pop ecx
loop L1

dntxchg:
loop L2 ; start loop again

exchg:
mov eax, [edi]
xchg [esi], eax
mov [edi], eax
loop L2 ;

ret
SortArray ENDP


ShowArray PROC

;show contents of array
mov esi, OFFSET array
mov ecx, arraysize
inc ecx
L3:
mov ebx, TYPE array
call DumpMem
loop L3

ret
ShowArray EndP

rrr314159

You could move the two procs above the routine they're called from. Or, put two proto statements at the top:

SortArray proto
ShowArray proto
I am NaN ;)

dedndave

for PROC's that are CALL'ed, you shouldn't need a PROTO

the problem is the location of the END statement   :biggrin:
it goes at the end of the source file, everything after END is ignored

you might want to add the .lib extension to the LIB files, too

arsenalftw067

Oh yes that's correct! So at the end of my last proc, is that where I put the end main?

Originally I put the procs inside the main but my professor didn't like that so I'm doing it in traditional c++ format

dedndave

        .code

main proc
main endp

proc1 proc
proc1 endp

proc2 proc
proc2 endp

        end     main


in the old days, we used to "nest" procedures all the time
not in vogue, anymore - lol

arsenalftw067


jj2007

Quote from: dedndave on October 23, 2015, 01:18:25 PM
in the old days, we used to "nest" procedures all the time

Strange idea, somehow, but the assembler doesn't complain:
include \masm32\include\masm32rt.inc

.code
proc1 proc
  mov eax, eax

proc2 proc ; nested proc2 in proc1
  mov ebx, ebx
proc2 endp

  mov ecx, ecx
  ret
proc1 endp

start:
int 3
  call proc1
  print "strange"
  exit

end start


Under the hood, you only see this:
  mov eax, eax
  mov ebx, ebx
  mov ecx, ecx
  retn

dedndave

here's one example
you call the proc by using the Func label

Func_Ext PROC

    stosb

Func PROC

    lodsb
    test    al,al
    jnz     Func_Ext

    ret

Func ENDP

Func_Ext ENDP


I suppose it depends on the MASM version and OPTION's
but I got an error last time I tried it