0

Im currently following this youtibe tutorial for assembly x64 (https://www.youtube.com/watch?v=VNDNvm0UY8E&list=RDCMUCq7dxy_qYNEBcHqQVCbc20w&index=3). I know links arent preferred, but in this case there really arent other options.

So I'm using visual studio, and I have this c++ code, just for calling assembly function:

#include  <iostream>

using namespace std;
extern "C" int SomeFunction();
int main() {
    SomeFunction();
    return 0;
}

And this masm assembly code:

.code
SomeFunction proc
    mov ax, -1
    ret
Somefunction endp
end

Now, I add a breakpoint in the "mov ax, -1" line. When the breakpoint hits, I rightclick ax and add a watch. In the video, the watch on ax has a value of 54864, and when the debugger goes to the next line, it is 65535. When i create the watch, it just has 1 as value, no matter what i do and where the breakpoint is. Why is this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
crypto_confuse
  • 463
  • 1
  • 4
  • 9
  • Your debugger is broken (or not showing you what you want to look at) if it says AX = +1 after you step past an instruction that sets AX = 0xFFFF (aka -1). Also note that `int` is 32 bits wide, but `mov ax, -1` leaves the upper 2 bytes of EAX unmodified. I guess you want that in this case, to play around with partial registers? Unlike writing a 32-bit register [Why do x86-64 instructions on 32-bit registers zero the upper part of the full 64-bit register?](https://stackoverflow.com/q/11177137) – Peter Cordes Mar 08 '21 at 06:00
  • hm, is there anything i could or should do to fix it? – crypto_confuse Mar 08 '21 at 17:07
  • @crypto_confuse, if the answer helps you handle the issue, please do not forget to [accept it](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Mr Qian Mar 12 '21 at 09:39

1 Answers1

1

I ran a 64 bit example with VS2015 - debug - watch rax - seems to be working for me. Before |mov rax,-1|, rax == 0x00000000cccccccc, after rax = 0xffffffffffffffff.

c++ code:

#include <iostream>
typedef unsigned long long uint64_t;
extern "C"  uint64_t tst();
int main()
{
    tst();
    return 0;
}

asm code:

        .data
        .data?
        align   16
        .code
        public  tst
tst     proc
        mov     rax,-1
        ret     0
tst     endp
        end
rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • thank you, I'm very new to assembly and dont really understand the point of the code you just posted. Could you tell me/ guess at to what my problem is? – crypto_confuse Mar 08 '21 at 17:08
  • @crypto_confuse - it could be an issue with how the project was setup. I start with an empty project, and if Visual Studio doesn't default a build step for .asm file, I manually create one. Command line: `ml64 /c /Zi /Fo$(OutDir)\xmpl.obj xmpl.asm`, output file: `$(OutDir)\xmpl.obj`. – rcgldr Mar 08 '21 at 17:12
  • hmm, running this command does not seem to be a valid command – crypto_confuse Mar 08 '21 at 18:51
  • @crypto_confuse - the command line is a parameter for custom build step. Open the project, right click on the name of the .asm file, then properties, set excluded from build to "no", then select item type "custom build tool", then select "custom build tool", then select "command line" fill it in as shown above, and "output file" as shown above. For release build, you do not need the /Zi in the command line. – rcgldr Mar 08 '21 at 19:03
  • thx! what is item type, and where do I find it? – crypto_confuse Mar 08 '21 at 22:08
  • @crypto_confuse - right click on the .asm source file name on the right hand side of the screen to get to properties. I don't know if all versions of Visual Studio have an item type. The main thing is to setup the "custom build step". – rcgldr Mar 09 '21 at 00:12