Skip to content

Commit

Permalink
feat: Add command STAX
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanta212 committed Mar 5, 2022
1 parent 5186338 commit f664671
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
14 changes: 14 additions & 0 deletions command_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ def store_accumulator(self, args: tuple) -> None:
f"{hex_to_simple(address)} ->" f" {hex_to_simple(self.state.accumulator)}"
)

def store_accumulator_to_register_pair(self, args: tuple) -> None:
"""
Store accumulator to register pair
"""
logger.debug(f"STAX: {args}")
register = args[0]
REG1, REG2 = REGISTER_PAIRS[register]
mem_addr = self.state.get_mem_addr_register_pair(register)
self.state.memory[mem_addr] = self.state.accumulator
logger.debug(f"Stored from ACCUMULATOR: {self.state.accumulator} to {mem_addr}")
print(
f"{REG1}{REG2} [{mem_addr}] -> {hex_to_simple(self.state.accumulator)} [From A]"
)

def add(self, args: tuple) -> None:
"""
Add value from register to accumulator
Expand Down
5 changes: 5 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
"function": "load_accumulator_from_register_pair",
"parameters": {"register_pair": {k: REGISTER_PAIRS[k] for k in ("B", "D")}},
},
"STAX": {
"description": "Store accumulator to register pair",
"function": "store_accumulator_to_register_pair",
"parameters": {"register_pair": {k: REGISTER_PAIRS[k] for k in ("B", "D")}},
},
"INX": {
"description": "Incremented xtended register pairs",
"function": "increment_extended_register",
Expand Down
24 changes: 21 additions & 3 deletions usage_examples.org
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,35 @@ Flags:
: HL -> 0x1261 [0x1260 + 0x01]
: HL -> 0x1260 [0x1261 - 0x01]

** STAX
We move data to M for writing value/data to xtended HL register
For other we have to manually store the value from accumulator to xtended register pair
#+begin_src 8085 :args -db /tmp/8085-session1 :exports both
LXI D 1260H ; DE -> 1260H
MVI A 0aH ; A -> 0aH
STAX D ; DE [1260] now contains 0aH
#+end_src

#+RESULTS:
: DE -> 0x1260 [D -> 0x12 E -> 0x60]
: A -> 0AH
: DE [0x1260] -> 0AH [From A]

** LDAX
We refer to M for the value/data stored in xtended HL register
For other we have to manually load the value to Accumulator
#+begin_src 8085 :args -db /tmp/8085-session1 :exports both
LXI D 1260H ; [1260H] contains value 05A
LDAX D ; It puts that value to A
MVI A 00H ; reset A to 0H
LXI D 1260H ; [1260H] contains value 0aH
LDAX D ; It puts that value to A
OUT A
#+end_src

#+RESULTS:
: A -> 00H
: DE -> 0x1260 [D -> 0x12 E -> 0x60]
: A -> 05H ; FROM DE -> [0x1260]
: A -> 0AH ; FROM DE -> [0x1260]
: A: 0AH

* Practice Problems
** Register setup from 1260 to 1264
Expand Down

0 comments on commit f664671

Please sign in to comment.