News:

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

More help needed

Started by axtens, May 23, 2007, 06:24:54 AM

Previous topic - Next topic

axtens

A few people have looked at my previous posting re BOSE. This is related to that one.

In this proc I'm trying to figure out the distribution of bytes values in a byte string. Everything seems to work except for counting 00h values. Any help would be appreciated.

Kind regards,
Bruce.


SECharacterDistribution PROC STDCALL uses EBX EDI ESI

LOCAL dLen:DWORD
LOCAL Distrib[256]:DWORD

PUSH ECX
PUSH EDX

MOV EDI, currentSlot
MOV ESI, rv(IntMul, EDI, SIZEOF Slot)

MOV EAX, Slots[ESI].instantiated
.if EAX == 0
fn Log_Error, "SECharacterDistribution", EDI, E_SLOT_NOT_INSTANTIATED, -1
fn Set_Error, E_ERROR_LOGGED
JMP @F
.endif

MOV EAX, Slots[ESI].occupied
.if EAX == 0
fn Log_Error, "SECharacterDistribution", EDI, E_SLOT_NOT_OCCUPIED, -1
fn Set_Error, E_ERROR_LOGGED
JMP @F
.endif

fn memfill, ptr$(Distrib), SIZEOF Distrib, 0d

MOV EDX, Slots[ESI].textbase
MOV ECX, 0d
.repeat
PUSH EDX
ADD EDX, ECX

MOVZX EAX, BYTE PTR [EDX]

PUSH EAX
MOV EDX, ptr$(Distrib)
POP EAX
SHL EAX, 2
ADD EDX, EAX

MOV EAX, [EDX]
INC EAX
MOV [EDX], EAX

MOV EAX, DWORD PTR [EDX]
POP EDX
INC ECX
.until ECX == Slots[ESI].textlength

PUSH slotSize
MOV slotSize, 4096
fn Instantiate, 0d ;instantiate slot zero in case it hasn't been
POP slotSize

MOV EAX, Slots[0].slotbase
MOV Slots[0].textbase, EAX
MOV Slots[0].occupied, 1

MOV ECX, 0d
MOV EDX, Slots[0].textbase

.repeat

PUSH ECX
PUSH EDX
MOV EDX, ptr$(Distrib)
SHL ECX, 2
ADD EDX, ECX

MOV EAX, DWORD PTR [EDX]

MOV EBX, sstr$(EAX)
MOV EAX, len(EBX)
MOV dLen, EAX


POP EDX

PUSH EDX
fn MemCopy, EBX, EDX, dLen
POP EDX

ADD EDX, dLen

MOV BYTE PTR [EDX], "^"
INC EDX

POP ECX
INC ECX
.until ECX == 256
MOV EAX, Slots[0].textbase
SUB EDX, EAX
MOV Slots[0].textlength, EDX

@@:
POP EDX
POP ECX
Ret
SECharacterDistribution EndP