The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: pikestar on August 02, 2011, 11:15:54 PM

Title: Code not doing what I hoped
Post by: pikestar on August 02, 2011, 11:15:54 PM
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
Title: Re: Code not doing what I hoped
Post by: zekyr on August 02, 2011, 11:34:46 PM
is it just me or did you forget your returns on your procedure?
Title: Re: Code not doing what I hoped
Post by: pikestar on August 02, 2011, 11:41:45 PM
: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
Title: Re: Code not doing what I hoped
Post by: zekyr on August 03, 2011, 12:03:27 AM
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 :)
Title: Re: Code not doing what I hoped
Post by: dedndave on August 03, 2011, 02:31:57 AM
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
Title: Re: Code not doing what I hoped
Post by: pikestar on August 03, 2011, 10:24:39 AM
Quote from: zekyr on August 03, 2011, 12:03:27 AM
did it work?

Yep working fine, cheers dudes  :U