I have a problem with assembly procedure called from VC++.

If I pass LPSTR to my ASM proc and then try to edit a byte in it with

mov al, BYTE PTR
inc al
mov BYTE PTR , al

if MyPointer points to "first byte" it just erases firt letter but if it points to any other byte in the string it causes error. How can I make this work? I would also like the same code to work with space allocated with GlobalAlloc.
Posted on 2002-01-23 14:16:04 by Milos
load the pointer and then modify the data:

mov eax, ; load address
inc BYTE PTR ; change data

If MyPointer contains the address of the string then you are just changing the pointer value, not the string itself.
Posted on 2002-01-23 15:40:15 by bitRAKE
Ok, thanks....
By the way, why does this thing work fine from "pure asm" ? If My pointer is address of some data from both .data block and allocated space??
Posted on 2002-01-23 15:49:37 by Milos
It doesn't. :grin:
Posted on 2002-01-23 16:19:14 by bitRAKE
How strange.... i wonder what in the world I did so this works to me ... i use it all the time. :) I must be schizophrenic or something. :)
Posted on 2002-01-23 16:29:34 by Milos
SomeData db "Oh, happy day!",0,0
MyPointer dd offset SomeData

Bad Code:
mov al, BYTE PTR
inc al
mov BYTE PTR , al

...do you see why this doesn't work?

Good Code:
mov eax,MyPointer
inc BYTE PTR ; change O to P
Posted on 2002-01-23 16:48:56 by bitRAKE
Does not this work?:



inc BYTE PTR MyPointer


I think it should...
Posted on 2002-01-23 17:44:59 by CodeLover

Does not this work?:



inc BYTE PTR MyPointer


I think it should...
If you want to change the first byte of the address, not if you want to change the string that the address points to. It is a valid instruction, but it doesn't accomplish the goal.
Posted on 2002-01-23 17:50:04 by bitRAKE
So, like this?:

inc BYTE PTR

That should increment it. I think the goal here is to increment the string. Does not this work?
Posted on 2002-01-23 18:38:21 by CodeLover
Maybe I missunderstood the goal?
Surely, 'DWORD PTR' would be more logical.
What if the byte overflowed?

I don't know what Milos is trying to do? :rolleyes:
Posted on 2002-01-23 18:55:37 by bitRAKE
Yes, maybe.

The problem is that i always, when incrementing a value stored in memory, i use a simple inc DWORD PTR ValueMemoryAddress. In this case, as MyPointer points to the string, i thought that maybe a simple inc BYTE PTR should do the work. (or inc dword ptr

Just asking...
Posted on 2002-01-23 19:02:49 by CodeLover
I have put the questio wrong way...

if there is

.data
MyString db "WASSUP?!", 0

.code
lea ebx, MyString
mov al, BYTE PTR Should return me the first byte, shouldn't it?

I assume when passing address of this string to a function by ADDR it gives the same result if we loaded effective address of it.

While ago I coded a function that excepts address of a buffer passed with ADDR (or lea to a register first).

I want to link this function with my C++ program now and I thoght that LPSTR is data type I should use- I used a string as a buffer just for testing but it didnt work....

I hope my problem it's much clear now. What should I use?
Posted on 2002-01-24 06:36:44 by Milos

So, like this?:

inc BYTE PTR

That should increment it. I think the goal here is to increment the string. Does not this work?


It does not work. BYTE PTR is a type cast, not an addressing mode. The x86 does not do data indirection via memory. You must load the address (pointer) into a register to affect the referenced memory.
Posted on 2002-01-24 21:43:33 by tank