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.