LARA

Discussion of parsing homework

Problem 1: Branch Instruction

  • Translate the for-loop and if-condition to branch instructions.
  • Convert the function to byte code.
  • Use CafeBabe to generate the class file.
def bubblesort( xs : Array[Int]) : Array[Int] = {
  for( i <- 0 until (xs.length - 1))
    for( j <- 0 until (xs.length - i - 1))
      if( xs(j) > xs(j+1)) {
        var tmp = xs(j)
        xs(j) = xs(j + 1)
        xs(j + 1) = tmp
      }
  xs
}