0

In dos.h file I came across below macro:

    #define disable()       __emit__((unsigned char)(0xfa))

On some research I understood that emit function is "a pseudo-function that injects literal values directly into the object code". But unable to understand the meaning of emit(0xfa)

Kushal
  • 582
  • 7
  • 23
  • 3
    `0xfa` is probably the machine code for *"disable interrupts"*. – user3386109 Nov 27 '16 at 06:48
  • Oh great. But where is this thing documented? – Kushal Nov 27 '16 at 06:50
  • It's [documented here](http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-manual-325462.html) on page 3-118 in volume 2A. – user3386109 Nov 27 '16 at 06:55
  • Got it. As you said disable() provides control over hardware interrupts by disabling all but the NMI interrupt. http://www.ousob.com/ng/borcpp/ng16c60.php – Kushal Nov 27 '16 at 06:55

1 Answers1

1

It injects int your code literal machine code. According to the comments int main question this is similar to: (I am using TP7 pascal code here, because I am retro-cool):

BEGIN
   WriteLn('Hello world, now interrupts are disabled');
   ASM
      CLI ; // clear interrupts - to re-enable call STI
   END
END.

See also - https://stackoverflow.com/a/1581729/78712

Another example (this time in C, borrowed from http://borlpasc.narod.ru/english/faqs/written.htm) might be

// jump FFFF:0000
#define reboot  __emit__ 0xEA __emit__ 0x00 __emit__ 0x00 __emit__ 0xFF __emit__ 0xFF

This seems to be an Mircrosoft compiler specific, as I am not sure it is available on GCC. Note that this only will work on 16bit DOS and under win32 this will fail in a funny way. Linux/ARM/AMD64 and other variations are out of the question as well.

See also In C programming, what does "emit" do?

Community
  • 1
  • 1
elcuco
  • 8,684
  • 9
  • 45
  • 67