-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgray.psm
27 lines (27 loc) · 784 Bytes
/
gray.psm
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
;An example program which converts binary
;to Gray code and vice versa, maybe it
;comes useful to somebody.
;There is also a <a href="https://www.reddit.com/r/PicoBlaze/comments/xdjazy/does_anybody_know_how_the_gray_code_example/?utm_source=share&utm_medium=web2x&context=3">Reddit discussion</a> about
;this program.
address 0
start: ;Infinite loop...
;Converting from binary to gray...
constant binary_input,0
constant gray_output,0
input s0,binary_input
load s1,s0
sr0 s1
xor s1,s0
output s1,gray_output
;Converting from gray to binary...
constant gray_input,1
constant binary_output,1
input s0,gray_input
load s1,s0
convert_to_binary_loop:
sr0 s1
xor s0,s1
compare s1,0
jump nz,convert_to_binary_loop
output s0,binary_output
jump start