0
   127:    int a = 2815;
00007FF78B5126EE  mov dword ptr [a],0AFFh
   128:
   129:    short c = static_cast<char>(a);
00007FF78B5126F5  movsx    ax,byte ptr [a]
00007FF78B5126FA  mov      word ptr [c],ax

In my environment an int takes 4 byte and a short takes 2, so in the movsx instruction, why there is a byte not a word? Hope someone can help me!

phuclv
  • 37,963
  • 15
  • 156
  • 475
Shawn
  • 82
  • 4
  • Your image of text [isn't very helpful](//meta.unix.stackexchange.com/q/4086). It can't be read aloud or copied into an editor, and it doesn't index very well, meaning that other users with the same problem are less likely to find the answer here. Please [edit] your post to incorporate the relevant text directly (preferably using copy+paste to avoid transcription errors). – Toby Speight May 28 '18 at 16:13

2 Answers2

1

A char is one byte. The static_cast casts a to a char. One byte. Hence, the one-byte value of the char-cast variable a is moved into ax.

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
0

It moves the lowest byte of the int a, because that's what static_cast<char> gives you.

Max Langhof
  • 23,383
  • 5
  • 39
  • 72