Skip to content

Commit 7dab1a5

Browse files
committed
Fill to the current location *before* emitting new output
1 parent 57a70e1 commit 7dab1a5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Z80/Assembler.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ reserveLoc x st = st{ loc = loc st + x }
6565

6666
tellBytes :: [Word8] -> Z80ASM
6767
tellBytes bytes = do
68+
loc <- incrementLoc . fromIntegral $ length bytes
6869
Z80 $ tell $ BS.pack bytes
69-
incrementLoc . fromIntegral $ length bytes
70+
pure loc
7071
-- The new location has to be computed lazily in the actual
7172
-- content of the bytes, so that we can emit byte values
7273
-- referring to later labels.
@@ -91,8 +92,9 @@ resb n = Z80 $ do
9192

9293
defByteString :: ByteString -> Z80ASM
9394
defByteString bs = do
95+
loc <- incrementLoc . fromIntegral $ BS.length bs
9496
Z80 $ tell bs
95-
incrementLoc . fromIntegral $ BS.length bs
97+
pure loc
9698

9799
label :: Z80 Location
98100
label = loc <$> Z80 get

0 commit comments

Comments
 (0)