clean up and added code for a simple counting function as a sanity check in the sandbox.
This commit is contained in:
43
src/TC_answers/memory_test.asm
Normal file
43
src/TC_answers/memory_test.asm
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "definitions.asm"
|
||||
; testing memory functionality
|
||||
prog:
|
||||
imm6 32
|
||||
load r0, r5 ; count
|
||||
|
||||
imm6 0
|
||||
load r0, r3 ; start address (by preloading accumulator)
|
||||
aload ; setup counter for later and skip using the ALU for now, just move to 8
|
||||
|
||||
imm6 1 ; stride
|
||||
load r0, r2
|
||||
|
||||
imm6 0
|
||||
load r0, r1
|
||||
load r0, r4 ; current
|
||||
|
||||
imm6 prog.save
|
||||
ba
|
||||
.save_loop:
|
||||
load r4, r1
|
||||
.save:
|
||||
imm6 1
|
||||
load r0, r2 ; stride
|
||||
|
||||
imm6 42 ; value to save
|
||||
out r0 ; after aload "r6" = r3 contains the address you want to write
|
||||
add ; r1 (count) - r2 (stride)
|
||||
load r3, r4 ; save count
|
||||
|
||||
imm6 prog.end ; check if we have reached the end of the write operation
|
||||
load r5, r1
|
||||
load r4, r2
|
||||
sub
|
||||
beqz ; if count - current == 0, branch r0 (prog.end)
|
||||
|
||||
load r4, r3 ; restore result from count
|
||||
aload ; else, load result to address register
|
||||
imm6 prog.save_loop
|
||||
ba ; and loop
|
||||
.end:
|
||||
.halt:
|
||||
halt
|
||||
Reference in New Issue
Block a user