@@ -15,84 +15,173 @@ export const valueToNumeralSystem = (
15
15
: ( value ?? 0 ) . toString ( ) . padStart ( padStartVal , "0" ) ;
16
16
} ;
17
17
18
- export const mapInstructionsArgsByType = ( args : Args | null , numeralSystem : NumeralSystem , counter : number ) => {
18
+ export const valueToBinary = ( value ?: number | bigint | string , padStartVal : number = 0 ) : string => {
19
+ return ( ( Number ( value ) ?? 0 ) >>> 0 ) . toString ( 2 ) . padStart ( padStartVal , "0" ) ;
20
+ } ;
21
+
22
+ export enum argType {
23
+ IMMEDIATE = "IMMEDIATE" ,
24
+ OFFSET = "OFFSET" ,
25
+ REGISTER = "REGISTER" ,
26
+ EXTENDED_WIDTH_IMMEDIATE = "EXTENDED_WIDTH_IMMEDIATE" ,
27
+ }
28
+
29
+ export const mapInstructionsArgsByType = (
30
+ args : Args | null ,
31
+ numeralSystem : NumeralSystem ,
32
+ counter : number ,
33
+ ) :
34
+ | {
35
+ type : argType ;
36
+ value : string | number ;
37
+ } [ ]
38
+ | null => {
19
39
switch ( args ?. type ) {
20
40
case ArgumentType . NO_ARGUMENTS :
21
- return "" ;
41
+ return [ ] ;
22
42
case ArgumentType . ONE_IMMEDIATE :
23
- return < span > { valueToNumeralSystem ( args . immediateDecoder . getI64 ( ) , numeralSystem ) } </ span > ;
43
+ return [ { type : argType . IMMEDIATE , value : valueToNumeralSystem ( args . immediateDecoder . getI64 ( ) , numeralSystem ) } ] ;
24
44
case ArgumentType . TWO_IMMEDIATES :
25
- return (
26
- < span >
27
- { valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) } ,{ " " }
28
- { valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) }
29
- </ span >
30
- ) ;
45
+ return [
46
+ {
47
+ type : argType . IMMEDIATE ,
48
+ value : valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) ,
49
+ } ,
50
+ {
51
+ type : argType . IMMEDIATE ,
52
+ value : valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) ,
53
+ } ,
54
+ ] ;
31
55
case ArgumentType . ONE_OFFSET :
32
- return < span > { valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) } </ span > ;
56
+ return [ { type : argType . OFFSET , value : valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) } ] ;
33
57
case ArgumentType . ONE_REGISTER_ONE_IMMEDIATE :
34
- return (
35
- < span >
36
- ω< sub > { args ?. registerIndex } </ sub > , { valueToNumeralSystem ( args . immediateDecoder . getI64 ( ) , numeralSystem ) }
37
- </ span >
38
- ) ;
58
+ return [
59
+ {
60
+ type : argType . REGISTER ,
61
+ value : `ω<sub>${ args ?. registerIndex } </sub>` ,
62
+ } ,
63
+ {
64
+ type : argType . IMMEDIATE ,
65
+ value : valueToNumeralSystem ( args . immediateDecoder . getI64 ( ) , numeralSystem ) ,
66
+ } ,
67
+ ] ;
39
68
case ArgumentType . ONE_REGISTER_TWO_IMMEDIATES :
40
- return (
41
- < span >
42
- ω< sub > { args ?. registerIndex } </ sub > , { valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) }
43
- , { valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) }
44
- </ span >
45
- ) ;
69
+ return [
70
+ {
71
+ type : argType . REGISTER ,
72
+ value : `ω<sub>${ args ?. registerIndex } </sub>` ,
73
+ } ,
74
+ {
75
+ type : argType . IMMEDIATE ,
76
+ value : valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) ,
77
+ } ,
78
+ {
79
+ type : argType . IMMEDIATE ,
80
+ value : valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) ,
81
+ } ,
82
+ ] ;
46
83
case ArgumentType . ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET :
47
- return (
48
- < span >
49
- ω< sub > { args ?. registerIndex } </ sub > , { valueToNumeralSystem ( args ?. immediateDecoder . getI64 ( ) , numeralSystem ) } ,{ " " }
50
- { valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) }
51
- </ span >
52
- ) ;
84
+ return [
85
+ {
86
+ type : argType . REGISTER ,
87
+ value : `ω<sub>${ args ?. registerIndex } </sub>` ,
88
+ } ,
89
+ {
90
+ type : argType . IMMEDIATE ,
91
+ value : valueToNumeralSystem ( args ?. immediateDecoder . getI64 ( ) , numeralSystem ) ,
92
+ } ,
93
+ {
94
+ type : argType . OFFSET ,
95
+ value : valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) ,
96
+ } ,
97
+ ] ;
53
98
case ArgumentType . ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE :
54
- return (
55
- < span >
56
- ω< sub > { args ?. registerIndex } </ sub > , { valueToNumeralSystem ( args ?. immediateDecoder . getValue ( ) , numeralSystem ) }
57
- </ span >
58
- ) ;
99
+ return [
100
+ {
101
+ type : argType . REGISTER ,
102
+ value : `ω<sub>${ args ?. registerIndex } </sub>` ,
103
+ } ,
104
+ {
105
+ type : argType . EXTENDED_WIDTH_IMMEDIATE ,
106
+ value : valueToNumeralSystem ( args ?. immediateDecoder . getValue ( ) , numeralSystem ) ,
107
+ } ,
108
+ ] ;
59
109
case ArgumentType . TWO_REGISTERS :
60
- return (
61
- < span >
62
- ω< sub > { args ?. firstRegisterIndex } </ sub > , ω< sub > { args ?. secondRegisterIndex } </ sub >
63
- </ span >
64
- ) ;
110
+ return [
111
+ {
112
+ type : argType . REGISTER ,
113
+ value : `ω<sub>${ args ?. firstRegisterIndex } </sub>` ,
114
+ } ,
115
+ {
116
+ type : argType . REGISTER ,
117
+ value : `ω<sub>${ args ?. secondRegisterIndex } </sub>` ,
118
+ } ,
119
+ ] ;
65
120
case ArgumentType . TWO_REGISTERS_ONE_IMMEDIATE :
66
- return (
67
- < span >
68
- ω< sub > { args ?. firstRegisterIndex } </ sub > , ω< sub > { args ?. secondRegisterIndex } </ sub > ,{ " " }
69
- { valueToNumeralSystem ( args ?. immediateDecoder . getI64 ( ) , numeralSystem ) }
70
- </ span >
71
- ) ;
121
+ return [
122
+ {
123
+ type : argType . REGISTER ,
124
+ value : `ω<sub>${ args ?. firstRegisterIndex } </sub>` ,
125
+ } ,
126
+ {
127
+ type : argType . REGISTER ,
128
+ value : `ω<sub>${ args ?. secondRegisterIndex } </sub>` ,
129
+ } ,
130
+ {
131
+ type : argType . IMMEDIATE ,
132
+ value : valueToNumeralSystem ( args ?. immediateDecoder . getI64 ( ) , numeralSystem ) ,
133
+ } ,
134
+ ] ;
72
135
case ArgumentType . TWO_REGISTERS_ONE_OFFSET :
73
- return (
74
- < span >
75
- ω< sub > { args ?. firstRegisterIndex } </ sub > , ω< sub > { args ?. secondRegisterIndex } </ sub > ,{ " " }
76
- { valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) }
77
- </ span >
78
- ) ;
136
+ return [
137
+ {
138
+ type : argType . REGISTER ,
139
+ value : `ω<sub>${ args ?. firstRegisterIndex } </sub>` ,
140
+ } ,
141
+ {
142
+ type : argType . REGISTER ,
143
+ value : `ω<sub>${ args ?. secondRegisterIndex } </sub>` ,
144
+ } ,
145
+ {
146
+ type : argType . OFFSET ,
147
+ value : valueToNumeralSystem ( args ?. nextPc - counter , numeralSystem ) ,
148
+ } ,
149
+ ] ;
79
150
case ArgumentType . TWO_REGISTERS_TWO_IMMEDIATES :
80
- return (
81
- < span >
82
- ω< sub > { args ?. firstRegisterIndex } </ sub > , ω< sub > { args ?. secondRegisterIndex } </ sub > ,{ " " }
83
- { valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) } ,{ " " }
84
- { valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) }
85
- </ span >
86
- ) ;
151
+ return [
152
+ {
153
+ type : argType . REGISTER ,
154
+ value : `ω<sub>${ args ?. firstRegisterIndex } </sub>` ,
155
+ } ,
156
+ {
157
+ type : argType . REGISTER ,
158
+ value : `ω<sub>${ args ?. secondRegisterIndex } </sub>` ,
159
+ } ,
160
+ {
161
+ type : argType . IMMEDIATE ,
162
+ value : valueToNumeralSystem ( args ?. firstImmediateDecoder . getI64 ( ) , numeralSystem ) ,
163
+ } ,
164
+ {
165
+ type : argType . IMMEDIATE ,
166
+ value : valueToNumeralSystem ( args ?. secondImmediateDecoder . getI64 ( ) , numeralSystem ) ,
167
+ } ,
168
+ ] ;
87
169
case ArgumentType . THREE_REGISTERS :
88
- return (
89
- < span >
90
- ω< sub > { args ?. firstRegisterIndex } </ sub > , ω< sub > { args ?. secondRegisterIndex } </ sub > , ω
91
- < sub > { args ?. thirdRegisterIndex } </ sub >
92
- </ span >
93
- ) ;
94
-
170
+ return [
171
+ {
172
+ type : argType . REGISTER ,
173
+ value : `ω<sub>${ args ?. firstRegisterIndex } </sub>` ,
174
+ } ,
175
+ {
176
+ type : argType . REGISTER ,
177
+ value : `ω<sub>${ args ?. secondRegisterIndex } </sub>` ,
178
+ } ,
179
+ {
180
+ type : argType . REGISTER ,
181
+ value : `ω<sub>${ args ?. thirdRegisterIndex } </sub>` ,
182
+ } ,
183
+ ] ;
95
184
default :
96
- return "err" ;
185
+ return null ;
97
186
}
98
187
} ;
0 commit comments