Cooler_

SWAP inline ASM

Feb 3rd, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. /*
  2. by Cooler_
  3.  
  4. o que é isso ?
  5. Um desafio simples, como trocar string de A para B e de B para A,
  6. sem usar variável C ou seja variáveis adicionais.
  7.  
  8.  
  9. este é um ex de resposta, existe outras formas de se fazer ^ ^
  10.  
  11. o que pode ajudar a entender,resolver de formas diferentes ?
  12. http://code.google.com/p/bugsec/wiki/AssemblyArqComp
  13. http://coolerlab.wordpress.com/2012/04/07/um-pouco-de-assembly-com-linguagem-c/
  14. http://staff.ustc.edu.cn/~xlanchen/cailiao/x86%20Assembly%20Programming.htm
  15. https://coolerlab.wordpress.com/2011/11/24/a-magia-dos-bits/
  16.  
  17. */
  18. #include <stdio.h>
  19.  
  20. char *A="Opa",*B="Ola";
  21.  
  22. int
  23. main()
  24. {
  25.  
  26.  __asm__ (
  27.   "pusha\n"
  28.   "movl A, %eax\n"
  29.   "movl B, %ebx\n"
  30.   "movl %ebx, A\n"
  31.   "movl %eax, B\n"
  32.   "xor %eax, %eax\n"
  33.   "xor %ebx, %ebx\n"
  34.   "popa\n"
  35.  );
  36.  
  37.  fprintf(stdout,"A= %s , B= %s  \n", A,B);
  38.  
  39.  return 0;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment