user1849298
user1849298

Reputation:

Getting the value at memory address X

I have a question: how can I see what is the value of the number at memory address X in c++.
I want to make something like the:

mov bx, 1024d
mov ax, [bx]

from assembly, where ax will be my result.

Thanks for the support.
P.S. I just started working with pointers and memory addresses

Upvotes: 1

Views: 3671

Answers (2)

Iłya Bursov
Iłya Bursov

Reputation: 24229

in c/c++ address is stored as pointer, so BX in your code in c++ will be

unsigned short* _mybx = (unsigned short*)1024U; // note casting to unsigned short*

to get value which is stored on address you need to use:

unsigned short _myax = *_mybx; // note asterix here

instead of c kind of cast, you can use reinterpret_cast

unsigned short* _bx = reinterpret_cast<unsigned short*>(1024);

which is more c++ way

Upvotes: 2

Kerrek SB
Kerrek SB

Reputation: 477580

In C++, the value at that address is *reinterpret_cast<uint16_t*>(1024).

Upvotes: 6

Related Questions