Here's the program I wrote not using a procedure:

.data
target BYTE "aabccdeef", 0
freqTable BYTE 256 DUP(0)
space BYTE " ", 0
					
.code
main PROC

	mov edi, OFFSET target
	mov esi, OFFSET freqTable

	mov ecx, LENGTHOF target	
	mov eax, 0

L1:
	mov al, [edi]
	movzx eax, al
	mov esi, OFFSET freqTable
	add esi, eax
		
	mov eax, 1d
	add [esi], eax
	mov eax, [esi]
	call WriteDec
	call Crlf

	add edi, 1
	loop L1

	mov esi, OFFSET freqTable
	mov ecx, LENGTHOF freqTable
	mov ebx, TYPE freqTable
	call DumpMem

	exit
main ENDP
END main

But the book asks for a procedure. However, passing an array to the procedure doesn't allow me to use LENGTHOF to get the length of the array. Of course in those instances where I need to use it, I could just plug in the numbers since I already know them. But I was wondering if there's a way to get around this problem. Here's the procedure version that doesn't really work.

INCLUDE Irvine32.inc

; Prototype for Procedure call
Get_frequencies PROTO, strTarget:PTR BYTE, arrayFreq:PTR BYTE

.data
target BYTE "This is a string", 0
freqTable DWORD 256 DUP(0)

		
.code
main PROC


	INVOKE Get_frequencies, ADDR target, ADDR freqTable

	exit
main ENDP


;--------------------------------------------------
Get_frequencies PROC USES eax ebx ecx esi edi,
	strTarget:PTR BYTE,
	arrayFreq:PTR BYTE,
;
;--------------------------------------------------


	mov edi, strTarget
	mov esi, arrayFreq

	mov ecx, LENGTHOF strTarget	
	mov eax, 0

L1:
	mov al, [edi]
	movzx eax, al
	mov esi, arrayFreq
	add esi, eax
		
	mov eax, 1d
	add [esi], eax
	mov eax, [esi]
	call WriteDec
	call Crlf

	add edi, 1
	loop L1

	mov esi, arrayFreq
	mov ecx, LENGTHOF arrayFreq
	mov ebx, TYPE arrayFreq
	call DumpMem

	ret
Get_frequencies ENDP

END main

Thanks for any suggestions.

The simple answer is that you need to pass in the lengths of each array as well a the pointer to the arrays.
You can in some cases encode an "END" into the array , for example you could place a zero at the end of the string and then scan for the 0 to get its length. This isn't isn't actually a solution for all cases though.

Hey thanks. I knew that I could pass the length, but I wondered if there was some simple answer I was missing. I'll use that solution though. Thanks!

This question has already been answered. Start a new discussion instead.