Listing 1

#include <stdio.h>

/*  re: "Executable Strings" by James A. Kuzdrall in the May 1990 issue.
 *  It is possible to execute stings in any 80x86 memory model by
 *  casting the string to a far function pointer.
 *
 *  Yours Truly,
 *
 *  Rick Shide
 *  Moore Data Management
 *  S Hwy 100
 *  Minneapolis, MN 55416-1519
 */

/*  asm equivalent of executable string setting return value to 5
 *
 *  mov ax,5  ; B8 05 00
 *  ret       ; CB
 */

typedef int (far *FPFI)();      // pointer to far function returning int

/*  demonstrate executable strings
 */
main()
{
   int   i;
   char  *str;
   
   /*  immediate form
    */
   i = ((FPFI)"\xb8\x05\x00\xcb")();
   printf("%d\n", i);                // will print "5"
   
   /*  string ptr form
    */
   str = "\xb8\x34\x12\xcb";
   i = ((FPFI)str)();
   printf("0X%x\n", i);              // will print "0X1234"
}