To multiply two numbers using the inline assembly language in C, perform the following steps:
- Load the two values to be multiplied into eax and ebx registers
- Multiply the contents of the eax and ebx registers and store the result in the eax register
- Display the content of the eax register on the screen
The program for multiplying two digits using inline assembly code is as follows:
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv)
{
int32_t var1=10, var2=20, multi = 0;
asm volatile ("imull %%ebx,%%eax;"
: "=a" (multi)
: "a" (var1), "b" (var2)
);
printf("Multiplication = %d\n", multi);
return 0;
}
Now, let's go behind the scenes.