Here's a test procedure from a program I'm working on, I pass in some parm's via the stack, one of which is a pointer. When I try to change the value of the dereferenced pointer, the variable isn't updated.
_testProc proc
push bp ;Save base pointer to stack
mov bp, sp ;Set new base pointer
sub sp, 4 ;Allocate stack space for locals
pusha ;Save registers to stack
mov di, [bp + 08] ;Parm 3 - ptr to variable
mov word ptr [di], 10 ; <---- Doesn't work. di contains an address,
; but what it points at doesn't get updated
popa ;Restore registers from stack
mov sp, bp ;Remove local vars by restoring sp
pop bp ;Restore base pointer from stack
ret 6 ;Return and also clean up parms on stack
_testProc endp
The 8086 produces and address by combining the contents of a segment register and an index register; I show that as [SR,IR].
Your update via register di is updating a location defined by [DS,DI]; mov instructions without any special prefix default to using the DS register. If you got the address DI as an offset for some other segment (ES? SS?) then you are in effect combining the wrong registers to hit the address you desire.
Your mistake is in not being clear about what the conventions are for passing a "pointer" to your routine. What you've define assume a relative offset from DS.
The very best thing you can do is to abandon 16-bit segmented code as soon as you can! :)
Failing that, there's "far data" and a "far pointer" to point to it. Your "proc" doesn't say if it's near or far - I assume near (or Parm3 probably isn't where you think it is on the stack... since the far return address is 4 bytes). If the variable you intend to alter is on the stack, you're in for some more complication. mov word ptr ss:[di], 10
at least. If you need to handle either a local or static variable, I think you're going to need a far pointer (4 bytes, segment and offset) to find it.
What first came to my mind is that you say you're trying to change the value of a dereferenced pointer, you don't "dereference" it (as I understand it). Try mov di, [di]
after you get the value off the stack. Easy to try, anyway. :)
If all else fails, show us the calling code. (and get into 32-bit code as soon as you can!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With