Rename 'ld' instruction to 'lda'

This commit is contained in:
2021-11-14 11:08:25 +01:00
parent 6c50259228
commit 3bb880f045
3 changed files with 23 additions and 23 deletions

View File

@@ -747,12 +747,12 @@ spec = do
actual <- exec vm input
actual `shouldBe` expected
describe "ld" $ do
describe "lda" $ do
it "lifts the function argument to the stack top" $ do
let input = " push 14 \n\
\ call &f \n\
\ nop \n\
\ f: ld 0 \n\
\ f: lda 0 \n\
\ halt"
let expected = done [14, 4, -1, 14] 7 1
actual <- run input
@@ -763,9 +763,9 @@ spec = do
\ push 4 \n\
\ call &f \n\
\ nop \n\
\ f: ld 2 \n\
\ ld 1 \n\
\ ld 0 \n\
\ f: lda 2 \n\
\ lda 1 \n\
\ lda 0 \n\
\ halt"
let expected = done [4, 11, 14, 8, -1, 4, 11, 14] 15 3
actual <- run input
@@ -775,15 +775,15 @@ spec = do
\ push 11 \n\
\ call &sum \n\
\ halt \n\
\ sum: ld 1 \n\
\ ld 0 \n\
\ sum: lda 1 \n\
\ lda 0 \n\
\ add \n\
\ ret "
let expected = done [25, 11, 14] 6 (-1)
actual <- run input
actual `shouldBe` expected
it "raises error if stack is empty" $ do
let input = " ld 0 \n\
let input = " lda 0 \n\
\ halt "
let expected = Left "Index 0 out of stack bounds"
let vm = empty { _stack = S.fromList [], _fp = 0 }
@@ -791,28 +791,28 @@ spec = do
actual `shouldBe` expected
it "raises error if stack contains only previous fp" $ do
let vm = empty { _stack = S.fromList [-1], _fp = 0 }
let input = " ld 0 \n\
let input = " lda 0 \n\
\ halt "
let expected = Left "Index 0 out of stack bounds"
actual <- exec vm input
actual `shouldBe` expected
it "raises error if stack contains only previous fp and return address" $ do
let vm = empty { _stack = S.fromList [2, -1], _fp = 0 }
let input = " ld 0 \n\
let input = " lda 0 \n\
\ halt "
let expected = Left "Index 0 out of stack bounds"
actual <- exec vm input
actual `shouldBe` expected
it "loads the first (0) argument if stack contains only previous fp, return address and single argument" $ do
let vm = empty { _stack = S.fromList [2, -1, 3], _fp = 1 }
let input = " ld 0 \n\
let input = " lda 0 \n\
\ halt "
let expected = done [3, 2, -1, 3] 2 1
actual <- exec vm input
actual `shouldBe` expected
it "raises error when accessint second (1) argument if stack contains only previous fp, return address and single argument" $ do
let vm = empty { _stack = S.fromList [2, -1, 3], _fp = 1 }
let input = " ld 1 \n\
let input = " lda 1 \n\
\ halt "
let expected = Left "Index 1 out of stack bounds"
actual <- exec vm input
@@ -824,9 +824,9 @@ spec = do
-- │ │
let vm = empty { _stack = S.fromList [ 2, -1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ], _fp = 12 }
-- │ │
-- argument indexes (ld): └─ 0 1 2 3 4 5 6 7 8 9 10 11
-- └───── ld 11 results in pushing 0 on to the top of the stack
let input = " ld 11 \n\
-- argument indexes (lda): └─ 0 1 2 3 4 5 6 7 8 9 10 11
-- └───── lda 11 results in pushing 0 on to the top of the stack
let input = " lda 11 \n\
\ halt "
let expected = done [0, 2, -1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] 2 12
actual <- exec vm input
@@ -850,8 +850,8 @@ spec = do
\ call &sum \n\
\ clr 2 \n\
\ halt \n\
\ sum: ld 1 \n\
\ ld 0 \n\
\ sum: lda 1 \n\
\ lda 0 \n\
\ add \n\
\ ret "
let expected = done [25] 8 (-1)
@@ -1004,13 +1004,13 @@ spec = do
\ clr 2 \n\
\ halt \n\
\ \n\
\ sum: ld 0 \n\
\ ld 1 \n\
\ sum: lda 0 \n\
\ lda 1 \n\
\ add \n\
\ ret \n\
\ \n\
\ prd: ld 0 \n\
\ ld 1 \n\
\ prd: lda 0 \n\
\ lda 1 \n\
\ mul \n\
\ ret "
let expected = done [2*3+5] 14 (-01)