views:

61

answers:

2

Edit: Answered my own question. See below. -_-

I have a variable defined in the .data segment as follows:

retVal DW 0100h  ;stores hex fraction of the intermediate value. Starts at 1.00

This is the value that I add or subtract to to get my return value.

The first time it shows up in the code segment is at the following point:

sub [retVal], ax     ; 

I have used the debugger, and can confirm that at the time of this operation, the ax register is: 0000h.

Yet, if I add the following line of code immediately before it:

mov dx, 0100h;
mov [retVal], 0100h;

I get a completely different value (also wrong). I'm quite baffled. Am I fundamentally misusing variables here? I don't see why loading the same value the variable was originally initialized to (and hasn't yet been modified from) would alter the results.

Any ideas? Failing that, could someone remind me how to track the value of a variable via CodeView? (The DOSBox debugger I'm using)

A: 

If this is real 8086 (i.e., segmented architecture), what is ds set to at the point where you do the subtraction? The the first thing that springs to mind, that you may be changing a totally different memory location.

On top of that, you should provide:

  • the shortest possible complete program that exhibits the problematic behaviour (and you may find you solve your own problem while doing this - I frequently do).
  • the actual incorrect values that retVal is being set to, in both cases.
paxdiablo
A: 

Is the program in question a subroutine?

If it is, and you call the subroutine repeatedly, are you reseting the variables you alter?

If you do not re-declare the variables, you are not using the previously declared values the 2nd or future times you run the subroutine, but the altered values you have at the end of your first execution.

Raven Dreamer