Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned short len;
- unsigned short width;
- // On a 64Bit System (w/ 64bit OS) int is 4Byte, thus long enough
- unsigned int area;
- int main()
- {
- // Figure out the size of a short
- //printf("sizeof(short) == %lu Byte\n", sizeof(short));
- // 2 Byte
- // Figure out the size of a int
- //printf("sizeof(int) == %lu Byte\n", sizeof(int));
- // 4 Byte
- // Figure out the size of a long
- //printf("sizeof(long) == %lu Byte\n", sizeof(long));
- // 8 Byte
- /*
- __asm__ __volatile__
- (
- "movw $10000, (width)\n\t"
- "movw $5000, (len)\n\t"
- "movw (width), %%ax\n\t"
- // Multiply. Result goes to DX:AX
- "mulw (len)\n\t"
- // Delete everyting in edx, except for the 16 lowest Bit
- "and $0x0ffff, %%edx\n\t"
- "movl %%edx, (area)\n\t"
- "movw %%ax, %%bx\n\t"
- // Move the upper 16 Bit of the result into eax
- "movl (area), %%eax\n\t"
- // Shift them 16 Bit to the left
- "movl $0x10000, %%ecx\n\t"
- "mull %%ecx\n\t"
- // the result ends up in dx:ax
- // Now add the pieces together
- "add %%bx, %%ax\n\t"
- "mov %%eax, (area)"
- :
- :
- : "%eax", "%ecx", "%edx"
- );
- */
- __asm__ __volatile__
- (
- "movw $10000, (width)\n\t"
- "movw $5000, (len)\n\t"
- "movw (width), %%ax\n\t"
- // Multiply. Result goes to DX:AX
- "mulw (len)\n\t"
- // only copy dx (the upper 16 Bit of the result)
- "movw %%dx, (area)\n\t"
- // Copy the lower 16 Bit of the result to bx
- "movw %%ax, %%bx\n\t"
- // Move the upper 16 Bit of the result into eax
- "movl (area), %%eax\n\t"
- // Now shift them so that they're in the right position
- "sal $16, %%eax\n\t"
- // Now add the pieces together
- "add %%bx, %%ax\n\t"
- "mov %%eax, (area)"
- : /* no output registers */
- : /* no input registers */
- : "%eax", "%ecx"
- );
- printf("width is now: %d \n", width);
- printf("len is now: %d \n", len);
- printf("area is now: %d \n", area);
- return 0;
- }
- /*
- mov width, 10000
- mov len, 5000
- mov ax, width
- mul len
- // make sure edx is clean, except for the value in dx
- and edx, 0ffffh
- mov area, edx
- mov bx, ax
- mov eax, area
- mov ecx, 10000h
- mul ecx
- add ax, bx
- mov area, eax
- */
Advertisement
Add Comment
Please, Sign In to add comment