invoke <a function put the out on eax>

mov edx,eax
mov bh,byte ptr
...............................................

or if i do it directly as well

mov bh,byte ptr


this is giving me an error (something about "MEMORY CAN'T BE READ"

but when i :
................................................
invoke <a function put the out on eax>

mov var,eax ; var is a DWORD
mov bh,byte ptr

...............................................

no problem at all
Posted on 2002-11-29 21:47:27 by DrBios
unless your program is supposed to be working with memory directly addresses...


mov edx,eax
mov bh,byte ptr

-> That moves the value of eax into edx and reads a byte from memory location edx... say eax had the value 3... the second line tries to read from memory location 03h... which causes an error.

mov var,eax ; var is a DWORD
mov bh,byte ptr


-> Moves eax into memory location of var... then loads a byte from the location of var...

try something like this:
mov edx,eax
and edx,ff00h
ror edx,8
mov bh,dl

that *should* work... haven't tested it. if i'm wrong (since i probably am), someone please correct me! anyway, if i'm actually right, then hopefully that'll help.
Posted on 2002-11-29 22:16:21 by jademtech
That is,


mov edx,eax ;stores value of eax in edx
mov bh,byte ptr ;loads a byte from the memory location pointed to by edx (NOT the value of edx) into bh

vs.

mov var,eax ; var is a DWORD ;stores the value of eax in the variable var
mov bh,byte ptr ;the assembler resolves the memory address of var and assembles the program such that the byte pointed to by this resolved memory address (what is pointed to by var) is copied into bh.
Posted on 2002-11-29 22:19:07 by jademtech
but:
mov edx,eax ........store a memory location on edx? the same as eax?
why i can't get the "content of that" memory location with mov bh,byte ptr directly?
or even do this mov ebx,DWORD ?
Posted on 2002-11-29 22:47:42 by DrBios
what are u saying is than assembler can' resolve the memory location if i do this mov bh,byte ptr ?
Posted on 2002-11-29 22:58:01 by DrBios
but:
mov edx,eax ........store a memory location on edx? the same as eax?
why i can't get the "content of that" memory location with mov bh,byte ptr directly?
or even do this mov ebx,DWORD ?
Posted on 2002-11-29 22:58:33 by DrBios
okay... hm. not sure if this is any more clear... here is your original line:



mov edx,eax
mov bh,byte ptr [edx]


if the preceeding line was eax=01234567h, this is the same as:


mov edx,01234567h
mov bh,byte ptr [01234567h]


in the second case,


mov var,eax
mov bh,byte ptr [var]


if eax still=01234567h,

var dd 0 ;say var is loaded at memory location 00000000h


mov [00000000h],01234567h
mov bh,byte ptr [00000000h]

which, as you can hopefully see, are different things.
Posted on 2002-11-29 23:01:12 by jademtech
I have to ask... why they hell did you start 3...... 3 threads for the same question? why didn't you just reply in your original thread?
Posted on 2002-11-29 23:04:40 by Gunner
you could do this:

mov dword ptr ,eax
mov bh,byte ptr

(removing byte and dword ptr would perform the exact same ops in this case, since byte is implicit in the both statements).

but that does something different from the one which you said worked...

if you made sure memory location edx was valid, you could use the above code.
Posted on 2002-11-29 23:09:09 by jademtech
a little mistake ...
Posted on 2002-11-30 00:57:33 by DrBios
look this is what i understand

when a function return a data in eax ....means that eax have the memory location of that data ..m'i right?

maybe that's my mistake ...

if eax=01234567h

mov edx,eax ; means move the memory location 01234567h ( just the number , not the content) to edx then edx=01234567h

mov bh,byte ptr ; means retrieve a byte of what is inside of the memory location 01234567h

so what's wrong whit this?

p.d: please be patient with me :(


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

another thing

var dd 0 ;say var is loaded at memory location 00000000h

code:--------------------------------------------------------------------------------
mov [00000000h],01234567h
mov bh,byte ptr [00000000h]
--------------------------------------------------------------------------------

in this statement ...you mean than

mov var,eax it's like say mov [00000000h],eax ; move the content of eax to 00000000h?

:confused:
Posted on 2002-11-30 01:20:19 by DrBios

a little mistake ...
Fixed: 3 threads merged. :)
Posted on 2002-11-30 01:25:49 by bitRAKE
thanx
Posted on 2002-11-30 03:45:42 by DrBios
A register can only ever hold a number. Nothing more, nothing less. What you do with that number is important.

If you decide to interpret it as ASCII values, that is up to you, similarly if you decide to use it as a pointer to some memory then you can do that too.
mov DWORD PTR ["Mirn"], "o!!!"

That is valid syntax, whether or not it makes sence when running it is another matter.

The value returned from a function depends entirely on the function. Some may only return true or false, in which case eax will contain either a 1 or a 0. Some functions will return a pointer, some will return a 32 bit value, some may return nothing at all.

"mov some_var, eax" will copy the value in eax to the memory location dictated by some_var

"mov eax, some_var" will copy the value held at the memory location dictated by some_var into eax.

"mov eax, edx" will copy what is in edx over what was in eax

"mov eax, " will copy what is at the memory location pointed to by edx into eax

"mov , eax" will copy the contents of eax, to the memory location that edx points to.


I think the fundamental mistake you are making is that the return value of your function call does not return a pointer. It will simply hold some data, so trying to use that data will lead the processor to try to access a bogus area of memory, and cause a fault.

Mirno
Posted on 2002-11-30 12:08:56 by Mirno
after a dip revision of my codes ..i find my error ....i was interpret the value retrieve on eax from the function like a memory location ...THAT WASN'T TRUE, the number on eax was the out value it self...so when i try to read the memory location on eax , obviously a got an error..



SO ...

thankx to every 1 who try to help me :grin: :alright:
Posted on 2002-12-02 05:56:21 by DrBios