diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+0.1.0.2
+---
+
+* Fix bug in rendering SETUPVAL opcode
+
 0.1.0.1
 ---
 
diff --git a/lua-bc.cabal b/lua-bc.cabal
--- a/lua-bc.cabal
+++ b/lua-bc.cabal
@@ -1,5 +1,5 @@
 name:                lua-bc
-version:             0.1.0.1
+version:             0.1.0.2
 synopsis:            Lua bytecode parser
 description:         Lua bytecode parser
 license:             MIT
diff --git a/src/Language/Lua/Bytecode.hs b/src/Language/Lua/Bytecode.hs
--- a/src/Language/Lua/Bytecode.hs
+++ b/src/Language/Lua/Bytecode.hs
@@ -11,6 +11,7 @@
   toEnum = Reg
   fromEnum (Reg r) = r
 
+-- | Zero-based index into upvalues
 newtype UpIx = UpIx Int
  deriving (Read,Show,Eq,Ord)
 
diff --git a/src/Language/Lua/Bytecode/Debug.hs b/src/Language/Lua/Bytecode/Debug.hs
--- a/src/Language/Lua/Bytecode/Debug.hs
+++ b/src/Language/Lua/Bytecode/Debug.hs
@@ -3,6 +3,7 @@
 
 import Data.ByteString (ByteString,append)
 import qualified Data.ByteString.Char8 as BS
+import           Data.Vector (Vector)
 import qualified Data.Vector as Vector
 import           Data.String(fromString)
 import           Data.Map ( Map )
@@ -18,6 +19,9 @@
 -- Debugging functions
 ------------------------------------------------------------------------
 
+
+
+
 lookupLineNumber ::
   Function ->
   Int {- ^ program counter -} ->
@@ -63,10 +67,17 @@
                                          vs Vector.!? x
   where
   memo      = Vector.generate (Vector.length (funcCode func)) locals
-  locals pc = Vector.map varInfoName
-            $ Vector.filter (\x -> pc < varInfoEnd x)
-            $ Vector.takeWhile (\x -> varInfoStart x <= pc)
-            $ debugInfoVars (funcDebug func)
+  locals pc = Vector.map varInfoName $ getRegistersAt func pc
+
+-- | Get what registers are in scope at a particular op-code.
+-- R1 is at entry 0, R2 is entry 1, etc.
+-- NOTE that there might be multiple registers with the same named thing.
+-- The one currently in scope is the last one.
+getRegistersAt :: Function -> Int {-^PC-} -> Vector VarInfo
+getRegistersAt func pc = Vector.filter (\x -> pc < varInfoEnd x)
+                       $ Vector.takeWhile (\x -> varInfoStart x <= pc)
+                       $ debugInfoVars (funcDebug func)
+
 
 
 
diff --git a/src/Language/Lua/Bytecode/Pretty.hs b/src/Language/Lua/Bytecode/Pretty.hs
--- a/src/Language/Lua/Bytecode/Pretty.hs
+++ b/src/Language/Lua/Bytecode/Pretty.hs
@@ -11,6 +11,7 @@
 import Data.Text.Encoding.Error(lenientDecode)
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.Vector as Vector
+import Numeric (showHex)
 
 data PPInfo = PPInfo
   { ppVarAt    :: Int -> Reg  -> Maybe Doc
@@ -87,9 +88,19 @@
       KString bs    -> str bs
       KLongString b -> str b
 
-    where str = text . show . decodeUtf8With lenientDecode
+    where str = text . showLuaString
 
+showLuaString :: BS.ByteString -> String
+showLuaString bs = '"' : BS.foldr show1 "\"" bs
+  where
+    show1 x
+      | x == '"'                = showString "\\\""
+      | x == '\\'               = showString "\\\\"
+      | '\x20' <= x, x < '\x7f' = showChar x
+      | '\x10' <= x             = showString "\\x"  . showHex (fromEnum x)
+      | otherwise               = showString "\\x0" . showHex (fromEnum x)
 
+
 class PP a where
   pp :: PPInfo -> a -> Doc
 
@@ -193,7 +204,7 @@
       OP_GETTABLE a b c -> a =: lkp b c
 
       OP_SETTABUP a b c -> lkp a b =: c
-      OP_SETUPVAL a b   -> a       =: b
+      OP_SETUPVAL a b   -> b       =: a
       OP_SETTABLE a b c -> lkp a b =: c
 
       OP_NEWTABLE a b c -> a =: (text "{}" <+> parens (text "array size =" <+>
@@ -265,6 +276,3 @@
         case ppExtraArg i of
           Just _  -> empty
           Nothing -> nest 2 (text "where extra =" <+> int n)
-
-
-
