Skip to content
BetterDL

STORE instruction

Also called: STORE, store to memory

The instruction that copies the accumulator into a memory word. In Tiny8, STORE a does M[a] ← ACC and leaves ACC and Z unchanged.

STORE a (Tiny8 opcode 2) writes the accumulator into memory word a: M[a] ← ACC. The ACC keeps its value.

Its execute steps:

  • E1 MDR ← ACC: the MDR's mux picks the ACC (MDRsrc = 1), and LdMDR = 1.
  • E2 M[MAR] ← MDR: Write = 1. The MAR already holds a.

The write can't happen in E1, because the MDR only receives the ACC's value at E1's edge. So STORE takes 6 cycles, like LOAD.

Two things STORE doesn't do:

  • It doesn't change the ACC.
  • It doesn't change the zero flag, even if the stored value is 0. Z still reflects the last LOAD, ADD or SUB.

Because program and data share memory, a STORE can overwrite an instruction. That's self modifying code.

Worked example

Example

STORE and Z

ACC = 0 and Z = 1 after a SUB. Tiny8 then executes STORE E, then LOAD F with M[F] = 3, then STORE E again.

  1. 1.

    STORE E: M[E] = 0. Z stays 1.

  2. 2.

    LOAD F: ACC = 3, Z = 0.

  3. 3.

    STORE E: M[E] = 3. Z stays 0. ACC is still 3.

Common mistakes

  • Thinking STORE clears the ACC or moves the value out of it. It copies.

  • Thinking STORE sets Z from the stored value.

  • Doing the memory write in E1, before the MDR holds the ACC's value.

Practice STORE instruction

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

STORE instruction is taught in Basic CPU / Computer Architecture.