I have been working on the below code for about a week now, and have been working with my professor, but still to no avail I haven't gotten it to work fully. This is a course required for my major, while I have no actual interest in programming, I am almost done with the class and this is my final project. I have a very naive understanding of the class but have successfully fumbled my way until here. I have posted my code below. It is compiling, however when I start it without debugging it times out and then says press and key to continue.... it is not giving me back any of the required data and I have no idea where to go from here, and the program is due at midnight :(
INCLUDE Irvine32.inc
.data
target BYTE " AAEBDCFBBC" , 0
freqTable DWORD 256 DUP( 0)
.code
main PROC
call Clrscr
call Get_frequencies
call DisplayTable
exit
main ENDP
;-------------------------------------------------------------
Get_frequencies PROC,
pString:PTR BYTE,; points to string
pTable:PTR DWORD; points to frequencey table
;
; Constructs a character frequency table. Each array position
; is indexed by its corresponding ASCII code.
;
; Returns: Each entry in the table contains a count of how
; many times that character occurred in the string.
;-------------------------------------------------------------
mov esi,pString
mov edi,pTable
cld; clear Direction flag (forward)
L1:mov eax,0; clear upper bits of EAX
lodsb; AL = [ESI], inc ESI
cmp al,0; end of string?
je Exit_proc; yes: exit
shl eax,2; multiply by 4
inc DWORD PTR[edi+eax]; add to table entry
jmp L1; repeat loop
Exit_proc:
ret
Get_frequencies ENDP
;-------------------------------------------------------------
DisplayTable PROC
;
; Display the non-empty entries of the frequency table.
; This procedure was not required, but it makes it easier
; to demonstrate that Get_frequencies works.
;-------------------------------------------------------------
.data
colonStr BYTE ": ",0
.code
call Crlf
mov ecx,LENGTHOF freqTable; entries to show
mov esi,OFFSET freqTable
mov ebx,0; index counter
L1: mov eax,[esi]; get frequency count
cmp eax,0; count = 0?
jna L2; if so, skip to next entry
mov eax, ebx; display the index
call WriteChar
mov edx, OFFSET colonStr; display ": "
call WriteString
mov eax,[esi]; show frequency count
call WriteDec
call Crlf
L2:add esi, TYPE freqTable; point to next table entry
inc ebx; increment index
loop L1
call Crlf
ret
DisplayTable ENDP
END main
Please help!
Quote from: ncmoore91 on August 03, 2012, 05:03:05 AM
while I have no actual interest in programming, ... the program is due at midnight :(
Well, if you really worked a week on it, then you merit a little help:
mov esi, offset target ;pString
mov edi, offset freqTable ;pTable
It will still crash a little bit, but your teacher will accept it :biggrin:
Output:
: 1
A: 2
B: 3
C: 2
D: 1
E: 1
F: 1
when i was in school, i had no interest in Chemistry - or History - or a few others
i wish, now, that i had paid more attention :t