Skip to content

Commit 2db43b4

Browse files
committed
Add store instruction
1 parent c611e20 commit 2db43b4

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

planner/instruction.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,12 @@ def from_binary(cls, bin: List[int]):
6969
return cls(val)
7070

7171
class MBlockSelector_stage3(Enum):
72-
'''
73-
bits: [1 as is_no_write][.][.]
74-
bits: [0][ 0 ][io_write else ram_write]
75-
bits: [0][ 1 ][pc_next else pc_next_if_eq]
76-
77-
'''
78-
NO_WRITE = 4
79-
VRW_SOURCE_RAM = 0
80-
VRW_SOURCE_IO = 1
81-
PC_NEXT = 2
82-
PC_NEXT_IF_ZERO = 3
72+
NO_WRITE = 0
73+
VRW_SOURCE_RAM = 1
74+
VRW_SOURCE_IO = 2
75+
VRW_VALUE_RAM = 3
76+
PC_NEXT = 4
77+
PC_NEXT_IF_ZERO = 5
8378

8479
@classmethod
8580
def wire(cls, sel) -> List:
@@ -312,6 +307,11 @@ def size(self):
312307
MBlockSelector_stage2.VR_VALUE_RAM,
313308
MBlockSelector_stage3.VRW_SOURCE_RAM,
314309
ALU.PASS_RW)),
310+
ParserInstruction("STORE", unit.Operand.DADDRESS, unit.Operand.ADDRESS,
311+
EncodedInstruction(MBlockSelector_stage1.VR_SOURCE_RAM,
312+
MBlockSelector_stage2.VRW_SOURCE_RAM,
313+
MBlockSelector_stage3.VRW_VALUE_RAM,
314+
ALU.PASS_R)),
315315
ParserInstruction("CMP", unit.Operand.ADDRESS, unit.Operand.ADDRESS,
316316
EncodedInstruction(MBlockSelector_stage1.VR_SOURCE_RAM,
317317
MBlockSelector_stage2.VRW_SOURCE_RAM,

planner/instruction_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def test_all_instructions_validation(self):
1919

2020
("load R3, [R1]", "LOAD [12], [[4]]"),
2121
("load R4, [[50]]", "LOAD [16], [[50]]"),
22+
("store [R1], R3", "STORE [[4]], [12]"),
23+
("store [[50]], R4", "STORE [[50]], [16]"),
2224

2325
("add R0, [10]", "ADD [0], [10]"),
2426
("addc R1, 10", "ADDC [4], 10"),

planner/sim/bin_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ def m_fetch_and_store_stage3(
102102
self,
103103
output_devices: List[devices.Device],
104104
vw_value: int,
105+
vrw_value: int,
105106
vrw_source: int,
106107
sel: instruction.MBlockSelector_stage3):
107108
assert vrw_source >= 0 and vrw_source < 256
108109
if sel == instruction.MBlockSelector_stage3.NO_WRITE:
109110
return
110111
if sel == instruction.MBlockSelector_stage3.VRW_SOURCE_RAM:
111112
return self.write_ram(vrw_source, 4, vw_value) # write using 8-bit address
113+
if sel == instruction.MBlockSelector_stage3.VRW_VALUE_RAM:
114+
return self.write_ram(vrw_value, 4, vw_value) # write using 8-bit address
112115
if sel == instruction.MBlockSelector_stage3.VRW_SOURCE_IO:
113116
assert vw_value >= 0 and vw_value < (1<<32)
114117
output_devices[vrw_source].update(vw_value)
@@ -186,6 +189,7 @@ def step(self):
186189
self.m_fetch_and_store_stage3(
187190
self.output_devices,
188191
vw_value,
192+
vrw_value,
189193
vrw_source,
190194
mblock_s3)
191195

planner/sim/bin_parser_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
add R1, R4
3232
jmp loop_start
3333
loop_end:
34-
out 0x06, R1
34+
# answer is in R1
35+
movc R2, 12 # memory address of R3
36+
store [R2], R1
37+
out 0x06, R3
3538
loop_exit:
3639
jmp loop_exit
3740

programs/boot_sequence.not_ready_asm renamed to programs/boot_sequence.asm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: This is not ready yet
12
# Program
23
# ROM[BootSequence]
34
#
@@ -7,7 +8,7 @@
78
# * ROM[Program] address-line at 0
89
# Really small program to copy ROM[Program] to RAM[Program]
910

10-
PROGRAM_START equ 0x20
11+
PROGRAM_ORG equ 0x40
1112

1213
section .text
1314
main:
@@ -17,18 +18,19 @@ section .text
1718
in R0, 0 # io -> ram
1819
movc R8, 1
1920

20-
movc R2, PROGRAM_START # const -> ram
21+
movc R2, PROGRAM_ORG # const -> ram
2122
movc R1, 1 # const -> ram
2223
_copy_more:
2324
out 0, R1 # ram -> io
2425
in R3, 0 # io -> ram
2526
add R1, R8
2627
add R2, R8
27-
store R2, R3 # ram -> ram
28+
store [R2], R3 # ram -> ram
2829
# bytes left to copy
29-
sub R0, 1
30+
subc R0, 1
3031
cmp R0, R9
31-
jneq _copy_more
32+
jz _copy_completed
33+
jmp _copy_more
3234

3335
_copy_completed:
3436
jmp _copy_completed

0 commit comments

Comments
 (0)