CENG 222 – Computer Organization - Lab Work 6

Exercises

Re-write the following C codes in assembly.

  1. While loop

    int a = 125;
    int b = 0;
    while(a>0){
      b += a;
      a -=2;
    }
  2. While loop with a condition

    int a = 125;
    int b = 0;
    while(a>0){
      b += a;
      if(a>10)
        a -= 2;
      else
        a--;
    }
  3. For loop

    b=0;
    for(i=0;i<10;i++)
      b = b+ i*2;
    
  4. Double for loop

    b=0;
    for(i=0;i<5;i++)
      for(j=0;j<5;j++)
        b = b+ j*2;
  5. Do-while loop with a condition

    int a = 125;
    int b = 0;
    do{
      b += a;
      if(a>10)
         a -= 2;
      else
        a--;
    }while(a>0)
  6. Collatz conjecture

    int a = 21;
    while(a != 1){
      if(a%2 == 1)
        a = 3*a+1;
      else
        a = a/2;
    }