-1

I am trying to understand the movement of the rbp value. I understand that rbp is the base pointer of the stack that I am working on.

I have a declaration of:

var_1= dword ptr -3
push rbp
move rbp, rsp
< some code >
mov [rbp+var_1], 1

I am lost on following the value of [rbp+var_1] in this case.

Later, I have a sequence of comparisons of that value:

test eax, eax
jnz short loc_12C0

mov [rbp+var_1], 0

loc_12C0:
cmp [rbp+var_1], 0
jnz new_location

In trying to follow the logic of this assembly code, I have watched several youtube videos and referenced this post but I do not understand it.

Could somebody please trace the value of the [rbp+var_1] expression, and explain to me what it is equal to?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
artemis
  • 6,857
  • 11
  • 46
  • 99
  • I don’t see a real question here. What do you want to know about that stack location? The two values it might have are obvious… – Davis Herring Jun 09 '19 at 02:48
  • @DavisHerring They are not obvious to me. The question is explicitly asked in the bottom of the post. Can someone help me understand the value of that expression throughout those code lines (i.e., what `var_1` equates to, how that changes `rbp`, etc) – artemis Jun 09 '19 at 02:59
  • 3
    Then, I’m afraid, you need an (x64) assembly tutorial, not a StackOverflow answer. Simply reading these 8 instructions to you won’t illuminate any useful concept, and a literal answer is hobbled by the fact that `[rbp+var_1]` is not an expression but a location. – Davis Herring Jun 09 '19 at 03:55
  • 1
    You defined `var_1` as `dword ptr -3`. Therefore `[rbp+var_1]` is `dword ptr [rbp-3]`. It's the dword starting at the address 3 bytes less than the current value of `rbp`. – Raymond Chen Jun 09 '19 at 04:19
  • @RaymondChen if you don't mind, please post as answer so I can accept, please and thank you. – artemis Jun 10 '19 at 19:38
  • You can answer your own question and accept it. – Raymond Chen Jun 10 '19 at 20:27

1 Answers1

0

Per @RaymondChen

var_1 = dword ptr -3

So, [rbp+var_1] is dword ptr [rbp-3] Its the d word starting at the address 3 bytes less than the current value of rbp

artemis
  • 6,857
  • 11
  • 46
  • 99