i got some code that loads up a dll with the api LOADLIBRARY

 

lea eax, DS:[0h]
push eax
call LoadLibrary
push eax
pop eax




in the first line(LEA EAX, DS:[0h]) i have A Varible called libName(libName db "dll.dll",0) ..libName is the first item in the DATA section of my code. it should start out as DS:0h

when i compile and run my program, the program crashes.....

why is it doing this?
Posted on 2010-02-13 16:46:37 by snoopyromeo
LoadLibrary suggests Windows OS. You DON'T change the segment registers under a protected-mode OS (unless you absolutely know what you're doing).
Posted on 2010-02-13 19:26:38 by ti_mo_n
ok i found a way to do this

for the code above i replace DS:[0H] WITH DS:[403000h]

it seems to start at 403000

one question though. i have two variables defined as byte...(db) the first starts at 403000 which is resonalble to see that it is zero..but the next variable is 40300Dh...that skips to 14 bytes
why doenst it start at 403009? since a byte is 8 bits

any ideas
thx
Posted on 2010-02-14 05:50:14 by snoopyromeo
ok i found out how to do this. I WENT into the hex editor and went with the BASE 16 number system.
Posted on 2010-02-14 06:22:12 by snoopyromeo
The real question is why are you hardcoding these addresses?
Posted on 2010-02-14 09:55:13 by ti_mo_n
Im learning assembly from Randell Hydes THE ART OF ASSEMBLY

heres the link

http://maven.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html

just going with the book......
Posted on 2010-02-15 02:59:20 by snoopyromeo
just going with the book......
Does AoA hardcore addresses instead of using symbolic variable names? I wouldn't think so :-s

Posted on 2010-02-15 03:26:55 by f0dder
The link seems to point to the old 16-bit dos version of AoA, where "ds:[0]" is a reasonable address to find your first variable. Not so in Windows! The "ds:" doesn't alter the segment register, it's just part of Masm's syntax (doesn't even emit the override). But writing Windows programs using a 16-bit guidebook and a hex-editor is unlikely to meet with much success. Why don't you just:

push offset libName
call LoadLibrary
...

push eax, pop eax... what's the purpose of that, snoopyromeo? Well, Windows code, and I don't know Windows...

Best,
Frank

Posted on 2010-02-15 05:17:07 by fbkotler
the reason i push eax and pop at the end was to put the value into eax since i wasnt using invoke....i think without invoke, you have to manually store into eax..i think not sure
Posted on 2010-02-15 05:19:44 by snoopyromeo

the reason i push eax and pop at the end was to put the value into eax since i wasnt using invoke....i think without invoke, you have to manually store into eax..i think not sure
Nope, EAX is the normal register used for return values, it's being set by the routine you're calling. If the called routine didn't set EAX, how would pushing and then popping the register do anything? :)
Posted on 2010-02-15 05:21:27 by f0dder
ok my mistake...i see i dont need push and pop eax since call sets eax directly
Posted on 2010-02-15 05:25:54 by snoopyromeo
The CALL instruction doesn't set eax.
It is normal for a procedure to return something in eax, such as an error/success value, or other result.
But that is entirely up to the person who wrote that procedure.
Posted on 2010-02-15 05:50:39 by Homer