Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 363
Shuzheng Avatar asked Jul 03 '17 09:07

Shuzheng


1 Answers

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.

like image 104
fuz Avatar answered Oct 04 '22 16:10

fuz