delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq138.html   search  

| Previous | Next | Up | Top |

17.4 Which registers need to be saved in assembly code?

Q: Which register can I safely change in my assembly code that is called from a C program?

Q: How come my program crashes with a GPF, but only if I compile it with -O2?


A: You can safely clobber EAX, ECX, and EDX, but must save and restore all other registers at the end of your assembly function. Failure to preserve, e.g., ESI, EDI, or EBX in functions written in assembly can cause a C program linked with such functions to crash, since GCC expects those registers to be preserved across function calls.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)