13

How does the CPU distinguish CALL rel16 (E8 cw) and CALL rel32 (E8 cd)?

According to this site, mirroring the Intel architecture manuals, the opcodes for CALL rel16 and CALL rel32 are E8 cw and E8 cd, respectively.

This has made me wonder, how does the CPU distinguish these opcodes from each other, since E8 cw might be a prefix of E8 cw?

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
Shuzheng
  • 11,288
  • 20
  • 88
  • 186

1 Answers1

13

The prefix 66 is used to toggle between 16 and 32 bit operand size. So, in 16 bit operation modes, E8 cw is CALL rel16 and 66 E8 cd is CALL rel32, while in 32 bit operation mode, E8 cd is CALL rel32 and 66 E8 cw is CALL rel16.

In long mode (64 bit mode), CALL rel16 seems to be unavailable according to the Intel manuals. CALL rel32 works like in 32 bit mode but the rel32 immediate is sign extended to 64 bit and added to rip instead of eip.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • Thanks! However, I think it is weird why the Intel manual doesn't mention this prefix (see the site I've linked to). – Shuzheng Jul 03 '17 at 10:03
  • The manual does say that, @Shuzheng. Under "Near Call", it says: *"The operand-size attribute determines the size of the target operand (16 or 32 bits)."* – Cody Gray - on strike Jul 03 '17 at 10:15
  • 2
    @Shuzheng The prefix `66` applies to all instructions that are available in 16 bit and in 32 bit and it works the same way in all of them. Thus, there is no need to explain this over and over again in each instruction's documentation. – fuz Jul 03 '17 at 10:15
  • @CodyGray - I thought they meant whether a 16 or 32 bit operant is given as argument. – Shuzheng Jul 03 '17 at 11:05
  • @Shuzheng The operand size attribute is determined by the current operation mode and the presence of an operand size override prefix (66). – fuz Jul 03 '17 at 12:26