Name _________________________

Machine and Assembly Language Worksheet

(This may be submitted for up to 10 points.)

Given an instruction or instruction sequence which accomplish the following objectives in ISCAL.

    1. Add the contents of register 5 to the contents of register 11 and store the result in register 5.
    2.  

    3. Load register 5 with the value 99.
    4.  

    5. Jump to location 100 if the contents of register 5 is positive.
    6.  

    7. Store the contents of register 5 into memory location 1000.
    8.  

       

    9. Load the contents of memory location 1000 into register 6.
    10.  

       

    11. Set the contents of each memory location between 1001 to 2000 to 0.
    12.  

       

       

       

       

       

       

       

    13. Add up the contents of memory locations 1001 to 2000 and put the result into location 2001.
    14.  

       

       

       

       

       

       

    15. Jump to location 500 + i, where i is the value of an integer in register 6.
    16.  

       

       

    17. Implement the gcd function, as defined by the following Java code:
static int gcd(int x, int y)
{
int temp;
if( x < 0 ) x = -x;
if( y < 0 ) y = -y;

/* assert x >= 0 && y >= 0 */
while( true )
  {
  if( x > y )
    {
    temp = x;
    x = y;
    y = temp;
    }
  /* assert x <= y */

  if( x == 0 )
    break;
  y = y - x;
  }
return y;
}