For this assignment you will create a C program that include
For this assignment you will create a C program that includes inline assembly code. Your code should do the following:
Query the user for a 32-bit integer, saving the integer into an appropriate C variable. Use assembly code to copy the value into another C variable.
Query the user for a 16-bit variable saving the value into an appropriate C variable. Use assembly code to copy the value into another 16-bit C variable.
Query the user for an 8-bit character saving the value into an appropriate C variable. Use assembly code to copy the value into another 8-bit variable.
Copy the 8-bit value entered in step 3 into the lower 8-bit portion of the copied-to variable used in step 1 (using assembly).
Print the results of each of the above steps (using printf in your C code).
Solution
#include <stdint.h>
 #include<stdio.h>
 
 int main()
 {
 int n0 , val1 ;
 int16_t n1 , val2 ;
 char ch, cval;
 printf(\"enter 32bit number\ \");
 scanf(\"%d\",&n0);
 
     asm (\"movl %1, %%ebx;\"
          \"movl %%ebx, %0;\"
          : \"=r\" ( val1 )        /* output */
          : \"r\" ( n0 )         /* input */
          : \"%ebx\"         /* clobbered register */
      );
 printf(\"val =%d\",val1);
 printf(\"\ enter 16bit number\ \");
 scanf(\"%d\",&n1);
 
     asm (\"movw %1, %%ax;\"
          \"movw %%ax, %0;\"
          : \"=r\" ( val2 )        /* output */
          : \"r\" ( n1 )         /* input */
          : \"%ax\"         /* clobbered register */
      );
 printf(\"val 2 =%d\",val2);
printf(\"\ enter char\ \");
 scanf(\"%c\",&ch);
 
     asm (\"movb %1, %%dl;\"
          \"movb %%dl, %0;\"
          : \"=r\" ( cval )        /* output */
          : \"r\" ( ch )         /* input */
          : \"%dl\"         /* clobbered register */
      );
      
 printf(\"character =%c\",cval);
 return 0;
 }


