Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- short assembler(char px, short py, char pz)
- {
- int x = px, y = py, z = pz;
- __asm__ ( "addl $7, %%eax;" // eax += 7
- "imul $7, %%eax;" // eax *= 7
- "subl %%ebx, %%eax;" // eax -= ebx
- "imul $3, %%ecx;" // ecx *= 3
- "subl $1, %%ecx;" // ecx -= 1
- "movl $0, %%edx;" // edx = 0
- "idivl %%ecx;" // edx:eax / ecx => eax
- "addl $2, %%eax;" // eax += 2
- : "=a" (x) : "c" (x) , "b" (y), "a" (z) );
- /*
- Input: z => eax, y => ebx, x => ecx
- Output: eax => x
- */
- return x;
- }
- void print(short v_as)
- {
- printf("\tat 10: %d,\tat 16: %s%x\n", v_as, v_as < 0 ? "-": "", v_as < 0 ? -(unsigned)v_as : v_as );
- }
- void solve(char x, short y, char z, short v)
- {
- short v_c = (7 * (z + 7) - y) / (3 * x - 1) + 2;
- short v_as = assembler(x, y, z);
- printf("\n<<Assembler>>"); print(v_as);
- printf("<<True answer>>"); print(v);
- printf("<<C>>\t"); print(v_c);
- }
- int main()
- {
- solve(0x1, 0x1, -0x8, -0x2);
- solve(-0x6B, -0x3CF4, 0x74, -0x31);
- return 0;
- }
Add Comment
Please, Sign In to add comment