News:

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

Code not doing what I hoped

Started by pikestar, August 02, 2011, 11:15:54 PM

Previous topic - Next topic

pikestar

I'm trying to print to the console the files in a directory however the code is printing nothing. It was crashing until I add the "use edi" on the FindFirst proc, which I thought was strange as I didn't touch the register. I'm guessing it's because I'm trying to get the size of an array but begining to get a little frustrated with it!! (I also tried switching sizeof for length of)


.386
.MODEL flat,STDCALL

include d:\masm32\include\windows.inc
include d:\masm32\include\kernel32.inc
includelib d:\masm32\lib\kernel32.lib

.DATA ;Program Data
msg db "Hello World",13,10,0
filePattern db "*.*",0 ;find any file
foundFile WIN32_FIND_DATA <>

.DATA? ;uninitialized data
conHan HANDLE ? ;hold the console handler
fileHandle HANDLE ?     ;holds found files handle

.CONST ;Program Constants

.CODE ;Program Code

start:

call HelloAll
call FindFirst
invoke ExitProcess, 0


;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Find File
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FindFirst proc uses edi

invoke FindFirstFile, addr filePattern, addr foundFile
.if eax!= INVALID_HANDLE_VALUE
mov fileHandle,eax
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov conHan,eax
invoke WriteConsole, conHan, addr foundFile.cFileName,\
lengthof foundFile.cFileName, 0, 0
.endif

FindFirst endp


;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Hello World
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
HelloAll proc


invoke GetStdHandle, STD_OUTPUT_HANDLE ;get the STD handle
mov conHan, eax        ;save console handler
invoke WriteConsole, conHan, ADDR msg, sizeof msg, 0, 0

HelloAll endp

end start


Any pointers would be appricated cheers

zekyr

is it just me or did you forget your returns on your procedure?

pikestar

:red
Oooooooppps
To be honest I didn't realise it made such a difference I though they were mainly used for breaking out of control statements
thanks

zekyr

did it work?

i think i left a ret earlier off something i wrote and i had it keep crashing

from what i got in my mind im thinking it works like:

CALL pushes the address of where you are onto the stack, then goes to the address you tell it like a jmp

and RET pops the address of where you were on the stack, and goes to that address

so if it never hits a RET you wrote it should just keep sliding down the instructions and do all kinds of crazy unintentional things!

atleast thats how I think it works. someone please correct me if im wrong :)

dedndave

Quoteso if it never hits a RET you wrote it should just keep sliding down
the instructions and do all kinds of crazy unintentional things!

....or words to that effect   :bg

pikestar