-5

How to convert this c++ code to assembly code ?

while(( A = getch()) != "0")
{
  switch(A){
    case "x":
     printf("x");
     break;
    case "w":
     printf("w");
    case "k":
     if(cx==0)
       continue;
     break;
     default: printf("error");
           }
} 

specially how to convert: getch() != "0";

Sam
  • 1,842
  • 3
  • 19
  • 33
Behnam Maboudi
  • 655
  • 5
  • 21
  • Duplicate? [How do you get assembler output from C/C++ source in gcc?](http://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc) – luk32 Dec 15 '13 at 08:32
  • 2
    This is not the place where work is done for of you. Show us what you have tried, what didn't work, where you struggled, and ask specific questions. – bolov Dec 15 '13 at 08:43
  • 3
    `g++ -S -o assembly.s mycode.cpp` Done. – Michael Dec 15 '13 at 09:05
  • Whats the point of the C++ tag??? – Devolus Dec 15 '13 at 09:07

1 Answers1

1

I think that for x86 assembly, you can write

call   getchar

which will cause a trap. When the char is ready, it will be put in the eax register. You can then compare this value to the decimal value of char "0", which is 48.

Kent Munthe Caspersen
  • 5,918
  • 1
  • 35
  • 34