title: C assembly programming
body: <p>I got this working everyone thank you!</p>
  
  <p>I have a homework to write an assembly program mulq.s that goes with my C program bigmult.c</p>
  
  <p>The C program is supposed to multiply two unsigned hexadecimal numbers together. I got it started but I think I need a lot of help. This is an introduction to assembly so it's not very long. </p>
  
  <p>Here is the full question:  </p>
  
  <blockquote>
    <p>You are to write a C program called
    big_mult.c that multiplies two unsigned integers, x and y, read from
    the command line. The output is a pair of unsigned integers
    representing the most significant and least significant 64 bits of the
    full 128-bit product x * y. The inputs and outputs are to be given in
    hexadecimal format. Your C program will take care of reading the
    inputs and printing the output, but it will call a function mull.s to
    do the actual multiplication. Your C program should use only int or
    unsigned int variables and should not do any arithmetic. The function
    defined by mull.s should have the following declaration in C before
    the procedure main. void mull(unsigned int x, unsigned int y, unsigned
    int* high, unsigned int* low);
    The least significant 64 bits of the product are to be assigned to
    low, and the most significant 64 bits of the product are to be
    assigned to high. Remember to put an appropriate header comment into
    your assembly file (the ordinary C comment /* ... */ will work for
    assembly too).
    One way to approach writing this assembly program is to write a
    similar program in C, compile it to assembly code using the -S option,
    and modify the resulting assembly code to do what you need. Your final
    assembly code should be very short and should contain only one
    multiplication instruction mull.</p>
  </blockquote>
  
  <p>I started writing a dummy program to get the unimportant parts of the code at the top and then I'm completely lost on what to do. I have pushq instruction to push %rbp and move the address to %rsp. What am I supposed to do after this? </p>
  
  <p>Any hints would be welcome! </p>
  
  <p>My code so far: </p>
  
  <pre><code>    .section    __TEXT,__text,regular,pure_instructions
      .globl  _main
      .align  4, 0x90
  _main:
      pushq   %rbp
      movq    %rsp, %rbp
  </code></pre>
  
  <p>My C program: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void mull(unsigned int x, unsigned int y, unsigned int* high, unsigned int* low);
  int main(int argc, char* argv[]) {
      unsigned long long int x, y;
      if(argc != 3)
          printf("Usage: bigmult x1 x2 &lt;where x1 and x2 are hexadecimal integers&gt;\n");
      else {
          sscanf(argv[1], "%x", &amp;x);
          sscanf(argv[2], "%x", &amp;y);
          printf("%x x %x = ", x, y);
          mull(x, y, &amp;x, &amp;y);
      }
      return 0;
  }
  </code></pre>