I have the following code. And I want to complete the assembly code as indicated below:
int main(void)
{
int x = 10;
int i=0;
label1:
asm (.....) // code to add here: if i>=x then jump to label2
printf("%d\n",i);
i++;
asm (.....) // code to add here: jump to label 1
label2:
printf("out\n");
}
My machine is x86 and the Operating system is Ubuntu 12
First, get yourself a list of x86 op codes, should be easy to find online.
The
asm()function follows this order:Second, one major problem you have is you can’t “jump” to a C label, you need to make your label an “assembly” label to be able to jump to it. ex:
Output of this program is simply “World” as we jumped over the “Hello “. Here’s the same example but with a comparative jump: