Wellllll, I'll try. Like they say, it's complicated (my code). I'll try to post some relevant snippets.
My data section:
;============================================
; HERE BE DATA
;============================================
.data
..... some stuff .....
NoSelectedFolderMsg DB "No folder selected. Use the Browse button to choose one.", 0
EmptyFindFieldMsg DB "Nothing to find! Type some text in the ""Find"" field.", 0
SearchTermErrorMsg DB "Illegal character (<>*?+/\:|) in find specifier.", 0
NoFilesFoundMsg DB "No files found.", 0
NomoFilesMsg DB "No mo' files.", 0
Q2Abuffer DB "01234567890123456789",0 ;20 ASCII digits
FileCountFmt DB "%s files found", 0
NoFilesMsg DB "No files found", 0
FileDateFmt DB "%u/%u/%u, %u:%02u %s", 0
AMstr DB "am", 0
PMstr DB "pm", 0
..... some more stuff .....
The code that's causing the access violation:
;====================================================================
; Convert 64-bit unsigned integer (QWORD) to ASCII decimal string
;
; On entry,
; EDX:EAX = QWORD value to convert
;
; Returns:
; EAX--> buffer containing numeric string
;====================================================================
Q2A PROC
PUSH EBX
PUSH ESI
PUSH EDI
; STD ;No, not a venereal disease:
;set direction flag to go backwards.
MOV EDI, OFFSET Q2Abuffer + 18 ;Start @ end.
MOV ECX, EDX
XCHG EAX, ESI
MOV EBX, 100 ;Load with divisor.
qloop: XOR EDX, EDX
XCHG EAX, ECX
DIV EBX
XCHG EAX, ECX
XCHG EAX, ESI
DIV EBX
XCHG EAX, ESI
XCHG EAX, EDX
AAM
XCHG AL, AH ;Swap bytes.
OR AX, 3030h ;Convert to ASCII.
; STOSW ;Store 2 digits.
mov [edi], ax
sub edi, 2
MOV EAX, ECX
OR EAX, ESI
JNZ qloop
ADD EDI, 2
; CLD ;Be sure to clear direction flag!
CMP BYTE PTR [EDI], '0' ;Leading zero?
JNE exit99 ; No, done.
INC EDI ; Yep, increment past it.
exit99: MOV EAX, EDI ;Return with pointer to buffer.
POP EDI
POP ESI
POP EBX
RET
Q2A ENDP
As soon as I access that item (Q2Abuffer) with
mov [edi], ax, bam! access violation writing to it. WTF????
If I move that item to my
data? section, it works OK.
You'll notice I modified that code (which I just downloaded from here today) to not use the string instruction STOSW. The routine works fine, BTW (so long as there aren't any access violations!).
If it matters, the order of my sections is: