diff --git a/src/main/wacc/backend/asmGenerator.scala b/src/main/wacc/backend/asmGenerator.scala index 2f15cc0..5c584af 100644 --- a/src/main/wacc/backend/asmGenerator.scala +++ b/src/main/wacc/backend/asmGenerator.scala @@ -22,6 +22,7 @@ object asmGenerator { private val RSI = Register(Q64, SI) private val RDX = Register(Q64, DX) private val RCX = Register(Q64, CX) + private val ECX = Register(D32, CX) private val argRegs = List(DI, SI, DX, CX, R8, R9) extension [T](chain: Chain[T]) @@ -195,8 +196,8 @@ object asmGenerator { chain ++= evalExprOntoStack(x) chain += stack.pop(RAX) chain += stack.pop(RCX) - // chain += Compare(RAX, RCX) - // chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.GreaterEqual) + chain += Compare(MemLocation(RAX, D32), ECX) + chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual) chain += stack.pop(RDX) chain += Move( @@ -301,6 +302,8 @@ object asmGenerator { chain += Compare(RCX, ImmediateVal(0)) chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less) chain += stack.pop(RAX) + chain += Compare(MemLocation(RAX, D32), ECX) + chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual) // + Int because we store the length of the array at the start chain += Move( Register(x.ty.elemSize, AX),