-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_WriteMemory.asm
More file actions
595 lines (425 loc) · 11.1 KB
/
Copy pathTest_WriteMemory.asm
File metadata and controls
595 lines (425 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
; This program Try Memory Write with different Data Size
;
; Author: Claudio "CP" La Rosa
; Public version 1.0 - June 2026
.ORG 0
.INCLUDE list.i
.INCLUDE serial.i
.DATA
str_hd DC4.T 10,13,"Memory Write Test",0
str_1 DC4.T 10,13,"Value to Store from register: ",0
str_2 DC4.T 10,13,"Value to store from memory: ",0
str_short DC4.T 10,13,"***** SHORT test *****",0
str_tryte DC4.T 10,13,"***** TRYTE test *****",0
str_push_tttt DC4.T 10,13,"***** Stack: Tryte-Tryte-Tryte-Tryte *****",0
str_push_tst DC4.T 10,13,"***** Stack: Tryte-Short-Tryte *****",0
str_push_tts DC4.T 10,13,"***** Stack: Tryte-Tryte-Short *****",0
str_push_stt DC4.T 10,13,"***** Stack: Short-Tryte-Tryte *****",0
str_push_ss DC4.T 10,13,"***** Stack: Short-Short *****",0
str_pop_st1 DC4.T 10,13,"***** Load Tryte from stack. Should be 8 ***** ",0
str_pop_st2 DC4.T 10,13,"***** Load Tryte from stack. Should be 7 ***** ",0
str_pop_st3 DC4.T 10,13,"***** Load Tryte from stack. Should be 5 ***** ",0
str_pop_st4 DC4.T 10,13,"***** Load Tryte from stack. Should be 4 ***** ",0
;
; ERRORS
;
str_div_by_zero DC.T "Division By Zero: FATAL error.",0
.CODE
;--------------------------------------
;Set Serial Port (R7)
ANYI R7,R0,#SERIAL_PORT_2
;---------------------------------------
;-------- Stack initializing ----------
ANYI R60,R0,#8000 ;R60 Stack address for kernel procedures
STSP R60 ;Kernel Stack
;--------------------------------------
;-- for print integer ternary
ANYI R15,R0,#24
; Print Header
LEA R27,str_hd
JSR println
JSR new_line
JSR new_line
LEA R27,str_short
JSR println
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from register
LEA R27,str_1
JSR print
ANY R10,R0,R2
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a short value at address 15000
ANYI R2,R0,#-265720
ST.S 0(R1),R2
;---- Print value from memory after short write
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;************************************************************
JSR new_line
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a short value at address ** 15001 **
INC R1
ANYI R2,R0,#-265720
ST.S 0(R1),R2
;---- Print value from memory after short write
DEC R1
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;************************************************************
JSR new_line
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a short value at address ** 15002 **
INC R1
INC R1
ANYI R2,R0,#-265720
ST.S 0(R1),R2
;---- Print value from memory after short write
ANYI R1,R0,#15000 ; Start Address
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;************************************************************
;*********************** TRYTE *********************
;************************************************************
JSR new_line
JSR new_line
LEA R27,str_tryte
JSR println
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a TRYTE value at address ** 15000 **
ANYI R2,R0,#-364
ST.T 0(R1),R2
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory after tryte write
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;Write a TRYTE at address 15001
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a TRYTE value at address ** 15001 **
INC R1
ANYI R2,R0,#-364
ST.T 0(R1),R2
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory after tryte write
DEC R1
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;Write a TRYTE at address 15002
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a TRYTE value at address ** 15002 **
INC R1
INC R1
ANYI R2,R0,#-364
ST.T 0(R1),R2
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory after tryte write
DEC R1
DEC R1
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;Write a TRYTE at address 15003
;------------------- FIll Memory
ANYI R1,R0,#15000 ; Start Address
;Value to store
ANYI R2,R0,#265720
ASHI R2,R2,#-12
ANYI R2,R2,#265720
ST.W 0(R1),R2; Store R2 in Address 15000
;---- Print value from memory
LEA R27,str_2
JSR print
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
; write a TRYTE value at address ** 15003 **
ADDI R1,R1,#3
ANYI R2,R0,#-364
ST.T 0(R1),R2
ANYI R10,R0,#0 ;set R10 to 0 before load from memory
;---- Print value from memory after tryte write
SUBI R1,R1,#3
LD R10,0(R1)
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;************************************************************
;*********************** PUSH *********************
;************************************************************
; -------------- PUSH Tryte - Tryte - Tryte - Tryte values -------
LEA R27,str_push_tttt
JSR println
ANYI R5,R0,#4
PUSH.T R5
INC R5
PUSH.T R5
INC R5
PUSH.T R5
INC R5
PUSH.T R5
;POP values
ANYI R10,R0,#265720
POP.W R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;-------------- Push Tryte - Short - Tryte ----------------
LEA R27,str_push_tst
JSR println
ANYI R5,R0,#4
PUSH.T R5
INC R5
PUSH.S R5
INC R5
PUSH.T R5
;POP values
ANYI R10,R0,#265720
POP.W R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;-------------- Push Tryte - Tryte - Short ----------------
LEA R27,str_push_tts
JSR println
ANYI R5,R0,#4
PUSH.T R5
INC R5
PUSH.T R5
INC R5
PUSH.S R5
;POP values
ANYI R10,R0,#265720
POP.W R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;-------------- Push Short - Tryte - Tryte ----------------
LEA R27,str_push_stt
JSR println
ANYI R5,R0,#4
PUSH.S R5
INC R5
PUSH.T R5
INC R5
PUSH.T R5
;POP values
ANYI R10,R0,#265720
POP.W R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;-------------- Push Short - Short ----------------
LEA R27,str_push_ss
JSR println
ANYI R5,R0,#4
PUSH.S R5
INC R5
PUSH.S R5
;POP values
ANYI R10,R0,#265720
POP.W R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
;--------
ANYI R1,R0,#4
PUSH.T R1
ANYI R1,R0,#3652
PUSH.S R1
ANYI R1,R0,#8
PUSH.T R1
ANY R10,R0,R0
LEA R27,str_pop_st1
JSR print
POP.T R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
LEA R27,str_pop_st2
JSR print
POP.T R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
LEA R27,str_pop_st3
JSR print
POP.T R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
LEA R27,str_pop_st4
JSR print
POP.T R10
JSR print_integer_ternary ; Print R10 value in ternary
JSR new_line
HLT
;-----------------------------------------------
;-------------------
; NEW LINE
;
; input: R7 Serial Port
;-------------------
new_line:
;PROLOGUE
PUSH R4
;Insert return value on the stack
PUSH R26
;new line
ANYI R4,R0,#10 ;<LF>
OUT 0(R7),R4
ANYI R4,R0,#13 ;<CR>
OUT 0(R7),R4
;EPILOGUE
POP.W R26
POP.W R4
JR R26
;------------------------------ END new_line
;-------------------
; INTEGER TO STRING
; input: R5 24 trit Integer
; R6 string buffer
;-------------------
integer_to_string:
;PROLOGUE
PUSH R3
PUSH R4
PUSH R5
PUSH R6
PUSH R10
PUSH R11
PUSH R12
PUSH R13
;Insert return value on the stack
PUSH R26
ANYI R3,R0,#0 ; Set as positive number
JBE R5,R0,integer_to_string_start
ANYI R3,R0,#1 ; Is a negative number
STI R5,R5
integer_to_string_start:
ANYI R4,R0,#0 ;contatore cifre
integer_to_string_loop:
ANY R10,R0,R5
ANYI R11,R0,#10 ;divisore
DIV R10,R12,R11,R10 ;R10 = R10 rem R11 R12 = R10/R11
ADDI R10,R10,#48 ;aggiungo 48 al resto
PUSH.W R10
ADDI R4,R4,#1 ;contatore cifre
ANY R5,R0,R12
JB R12,R0,integer_to_string_loop
;is a positive number?
JEQ R3,R0,integer_to_string_view_cifra
;is is a negative number, I write '-'
ANYI R13,R0,#45 ; '-' char
ST 0(R6),R13
ADDI R6,R6,#4
integer_to_string_view_cifra:
POP.W R13
ST 0(R6),R13
ADDI R6,R6,#4
ADDI R4,R4,#-1
JB R4,R0,integer_to_string_view_cifra
ST 0(R6),R0
;EPILOGUE
POP.W R26
POP.W R13
POP.W R12
POP.W R11
POP.W R10
POP.W R6
POP.W R5
POP.W R4
POP.W R3
JR R26
;---------- END INTEGER TO STRING
;------------ print_spaces -----------
; INPUT
; R60 numbers of spaces
print_spaces:
;PROLOGUE
PUSH R60
PUSH R61
;Insert return value on the stack
PUSH.W R26
ANYI R61,R0,#32 ;space
loop_print_spaces:
JEQ R60,R0,exit_print_spaces
SUBI R60,R60,#1
OUT 0(R7),R61
JMP loop_print_spaces
exit_print_spaces:
;EPILOGUE
POP.W R26
POP.W R61
POP.W R60
JR R26
.INCLUDE COMMON/IO_fun.i