How do I get the size of C instruction ? -
how size of c instruction? example want know, if working on windows xp intel core2duo processor, how space instruction:
while(1==9) { printf("test"); } takes?
c not have notion of "instruction", let alone notion of "size of instruction", question doesn't make sense in context of "programming in c".
the fundamental element of c program statement, can arbitrarily complex.
if care details of implementation, inspect machine code compiler generates. 1 broken down in machine instructions, , can see how many bytes required encode each instruction.
for example, compile program
#include <cstdio> int main() { (;;) std::printf("test"); } with
g++ -c -o /tmp/out.o /tmp/in.cpp and disassemble with
objdump -d /tmp/out.o -mintel and get:
00000000 <main>: 0: 55 push ebp 1: 89 e5 mov ebp,esp 3: 83 e4 f0 , esp,0xfffffff0 6: 83 ec 10 sub esp,0x10 9: c7 04 24 00 00 00 00 mov dword ptr [esp],0x0 10: e8 fc ff ff ff call 11 <main+0x11> 15: eb f2 jmp 9 <main+0x9> as can see, call instruction requires 5 bytes in case, , jump loop requires 2 bytes. (also note conspicuous absence of ret statement.)
you can instruction in your favourite x86 documentation , see e8 single-byte call opcode; subsequent 4 bytes operand.
Comments
Post a Comment