Skip to main content
add asm mnemonics. `ret 0` still pops the return address, it's 0 *extra* bytes. Also clarify that `ret` doesn't affect EAX, just that the value there is considered the function's return value).
Source Link
Peter Cordes
  • 5.1k
  • 1
  • 24
  • 35

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 (mov eax, imm32) stores the int 0 in the eax register.

  • c2 00 00 (ret imm16) pops 0 extra bytes from the stack and returns the. (The value in the eax register is the function return value).

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 00 00 pops 0 bytes from the stack and returns the value in the eax register.

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 (mov eax, imm32) stores the int 0 in the eax register.

  • c2 00 00 (ret imm16) pops 0 extra bytes from the stack and returns. (The value in the eax register is the function return value).

added 42 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 00 00 pops 0 bytes from the stack and returns the value in the eax register.

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 returns the value in the eax register.

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 00 00 pops 0 bytes from the stack and returns the value in the eax register.

added 12 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

C (tcc), x86_64, 29 31 33 3939 40 bytes

main[]={(23*8),0xABDCFEbfdec%~-197645~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 returns the value in the eax register.

C (tcc), x86_64, 29 31 33 39 bytes

main[]={(23*8),0xABDCFEbfdec%~-197645}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 returns the value in the eax register.

C (tcc), x86_64, 29 31 33 39 40 bytes

main[]={(23*8),-~0xABEDFCfebdc%95674+1}; 

Returns 0. Thanks to @feersum for suggesting uppercase hex digits.

Try it online!

How it works

The assignment writes two ints (184 and 49664) to the memory location of main. With 32-bit ints and little-endian byte order, the exact bytes are b8 00 00 00 00 c2 00 00.

Since tcc doesn't declare the defined array as .data (most compilers would), so jumping to main executes the machine code it points to.

  • b8 00 00 00 00 stores the int 0 in the eax register.

  • c2 returns the value in the eax register.

added 82 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 15 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
deleted 119 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 622 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading