-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbin2dec.psm
70 lines (67 loc) · 1.46 KB
/
bin2dec.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
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
;This program has been tested on real
;PicoBlaze and it worked there! While
;this program uses regbanks and flags,
;I would not take the fact that it
;works on PicoBlaze to mean that the
;emulation of flags in this simulator
;is realistic when the regbank changes.
;Namely, given what I know, it is
;possible that real PicoBlaze does not
;have separate flags for each regbank.
;The "Regbanks-Flags Test" is supposed
;to test for that (to succeed if and
;only if flags work the way I think they
;do when the regbank changes, and to
;fail if they do not).
;Converting binary numbers entered using
;the switches to decimal and displaying
;them on the 7-segment displays.
;Also, converting them to Gray code and
;displaying the Gray code using LEDs.
address 0
infinite_loop:
input s0, 0
load sa, s0
load sc, 0
compare sa, 200'd
jump c , lessThan200
sub sa, 200'd
load sc, 2
lessThan200:
compare sa, 100'd
jump c , lessThan100
sub sa, 100'd
load sc, 1
lessThan100:
call divideBy10
call multiplyBy16
add sa, sb
output sc, 1
output sa, 2
load s1, s0
sr0 s1
xor s1, s0
output s1, 0
jump infinite_loop
divideBy10:
star s0, sa
regbank b
load s1, 0
beginning_of_loop:
compare s0, 10'd
jump c , end_of_loop
sub s0, 10'd
add s1, 1
jump beginning_of_loop
end_of_loop:
star sa, s1
star sb, s0
regbank a
return
multiplyBy16:
;16=2^4
sl0 sa
sl0 sa
sl0 sa
sl0 sa
return