MIPS架构——汇编代码转机器代码编译器 Matlab GUI

MIPS架构下的MCU,指令集包含R-Type、I-Type、J-Type三种,在数电课程设计时为了给MCU编写指令集,需要将汇编语言转化成机器代码,这里分享一下自己写的Matlab 的 GUI。

主函数 C2M

  1 function varargout = C2M(varargin)
  2 val = zeros(1,1);
  3 
  4 % C2M MATLAB code for C2M.fig
  5 %      C2M, by itself, creates a new C2M or raises the existing
  6 %      singleton*.
  7 %
  8 %      H = C2M returns the handle to a new C2M or the handle to
  9 %      the existing singleton*.
 10 %
 11 %      C2M('CALLBACK',hObject,eventData,handles,...) calls the local
 12 %      function named CALLBACK in C2M.M with the given input arguments.
 13 %
 14 %      C2M('Property','Value',...) creates a new C2M or raises the
 15 %      existing singleton*.  Starting from the left, property value pairs are
 16 %      applied to the GUI before C2M_OpeningFcn gets called.  An
 17 %      unrecognized property name or invalid value makes property application
 18 %      stop.  All inputs are passed to C2M_OpeningFcn via varargin.
 19 %
 20 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
 21 %      instance to run (singleton)".
 22 %
 23 % See also: GUIDE, GUIDATA, GUIHANDLES
 24 
 25 % Edit the above text to modify the response to help C2M
 26 
 27 % Last Modified by GUIDE v2.5 08-Jun-2018 13:07:05
 28 
 29 % Begin initialization code - DO NOT EDIT
 30 gui_Singleton = 1;
 31 gui_State = struct('gui_Name',       mfilename, ...
 32                    'gui_Singleton',  gui_Singleton, ...
 33                    'gui_OpeningFcn', @C2M_OpeningFcn, ...
 34                    'gui_OutputFcn',  @C2M_OutputFcn, ...
 35                    'gui_LayoutFcn',  [] , ...
 36                    'gui_Callback',   []);
 37 if nargin && ischar(varargin{1})
 38     gui_State.gui_Callback = str2func(varargin{1});
 39 end
 40 
 41 if nargout
 42     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
 43 else
 44     gui_mainfcn(gui_State, varargin{:});
 45 end
 46 % End initialization code - DO NOT EDIT
 47 
 48 
 49 % --- Executes just before C2M is made visible.
 50 function C2M_OpeningFcn(hObject, eventdata, handles, varargin)
 51 % This function has no output args, see OutputFcn.
 52 % hObject    handle to figure
 53 % eventdata  reserved - to be defined in a future version of MATLAB
 54 % handles    structure with handles and user data (see GUIDATA)
 55 % varargin   command line arguments to C2M (see VARARGIN)
 56 
 57 % Choose default command line output for C2M
 58 handles.output = hObject;
 59 
 60 % Update handles structure
 61 guidata(hObject, handles);
 62 
 63 % UIWAIT makes C2M wait for user response (see UIRESUME)
 64 % uiwait(handles.figure1);
 65 
 66 
 67 % --- Outputs from this function are returned to the command line.
 68 function varargout = C2M_OutputFcn(hObject, eventdata, handles) 
 69 % varargout  cell array for returning output args (see VARARGOUT);
 70 % hObject    handle to figure
 71 % eventdata  reserved - to be defined in a future version of MATLAB
 72 % handles    structure with handles and user data (see GUIDATA)
 73 
 74 % Get default command line output from handles structure
 75 varargout{1} = handles.output;
 76 
 77 
 78 
 79 function edit1_Callback(hObject, eventdata, handles)
 80 % hObject    handle to edit1 (see GCBO)
 81 % eventdata  reserved - to be defined in a future version of MATLAB
 82 % handles    structure with handles and user data (see GUIDATA)
 83 
 84 % Hints: get(hObject,'String') returns contents of edit1 as text
 85 %        str2double(get(hObject,'String')) returns contents of edit1 as a double
 86 
 87 
 88 % --- Executes during object creation, after setting all properties.
 89 function edit1_CreateFcn(hObject, eventdata, handles)
 90 % hObject    handle to edit1 (see GCBO)
 91 % eventdata  reserved - to be defined in a future version of MATLAB
 92 % handles    empty - handles not created until after all CreateFcns called
 93 
 94 % Hint: edit controls usually have a white background on Windows.
 95 %       See ISPC and COMPUTER.
 96 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
 97     set(hObject,'BackgroundColor','white');
 98 end
 99 
100 
101 
102 function edit2_Callback(hObject, eventdata, handles)
103 % hObject    handle to edit2 (see GCBO)
104 % eventdata  reserved - to be defined in a future version of MATLAB
105 % handles    structure with handles and user data (see GUIDATA)
106 
107 % Hints: get(hObject,'String') returns contents of edit2 as text
108 %        str2double(get(hObject,'String')) returns contents of edit2 as a double
109 
110 
111 % --- Executes during object creation, after setting all properties.
112 function edit2_CreateFcn(hObject, eventdata, handles)
113 % hObject    handle to edit2 (see GCBO)
114 % eventdata  reserved - to be defined in a future version of MATLAB
115 % handles    empty - handles not created until after all CreateFcns called
116 
117 % Hint: edit controls usually have a white background on Windows.
118 %       See ISPC and COMPUTER.
119 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
120     set(hObject,'BackgroundColor','white');
121 end
122 
123 
124 % --- Executes on button press in pushbutton1.
125 function pushbutton1_Callback(hObject, eventdata, handles)
126 global val
127 % hObject    handle to pushbutton1 (see GCBO)
128 % eventdata  reserved - to be defined in a future version of MATLAB
129 % handles    structure with handles and user data (see GUIDATA)
130 
131 str1 = get(handles.edit2, 'String');    %??????
132 
133 x = size(str1, 2);  %????????
134 y = size(str1, 1);  %????????
135 %b = zeros(y, x);    %b??????????????????
136 
137 for i = 1 : y
138     
139     opcode1 = str1(i,1);
140     opcode2 = strcat(str1(i,1), str1(i,2));
141     opcode3 = strcat(str1(i,1), str1(i,2), str1(i,3));
142     opcode4 = strcat(str1(i,1), str1(i,2), str1(i,3), str1(i,4));
143     rd = strcat(str1(i, 6), str1(i, 7));
144     rs = strcat(str1(i,11), str1(i,12));
145     rt = strcat(str1(i,16), str1(i,17));
146     
147     if (x >= 19)
148         imm_sh = strcat(str1(i,15), str1(i,16), str1(i,17), str1(i, 18), str1(i, 19));
149     end
150     rt4 = strcat(str1(i,7), str1(i,8));
151     rs4 = strcat(str1(i,12), str1(i,13));
152     if (x >= 20) imm4 = strcat(str1(i,16), str1(i,17), str1(i, 18), str1(i, 19), str1(i, 20));
153     end
154     
155     rd2 = strcat(str1(i, 5), str1(i, 6));
156     rs2 = strcat(str1(i,10), str1(i,11));
157     rt2 = strcat(str1(i,15), str1(i,16));    
158     rt_w  = strcat(str1(i, 5), str1(i, 6));
159     imm_w = strcat(str1(i, 9), str1(i, 10), str1(i, 11), str1(i, 12), str1(i, 13));
160     rs_w  = strcat(str1(i, 16), str1(i, 17));
161     
162     switch opcode4         
163         case 'addi'
164             b(i,1)=0;b(i,2)=0;b(i,3)=1;b(i,4)=0;b(i,5)=0;b(i,6)=0;
165             b(i, 7:11) = rig_f(rs4); b(i, 12:16) = rig_f(rt4);
166             b(i, 17:32) = rig_n(imm4);
167             bq(i,:) = 'this is adi';
168             %bqq(i,:) = strcat('this is addi ', rs4 , '-', rt4 , '-',imm4);
169         otherwise
170             switch opcode3
171                 case 'add'
172                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0; 
173                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=0;
174                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
175                     bq(i,:) = 'this is add';
176                     %bqq(i,:) = strcat('this is add, ', rs , '-', rt , '-',rd);
177                 case 'sub'
178                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
179                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=0;
180                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
181                     bq(i,:) = 'this is sub';bqq(i,:) = strcat('this is sub, ', rs , '-', rt , '-',rd);
182                 case 'and'
183                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
184                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=1;b(i,31)=0;b(i,32)=0;
185                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
186                     bq(i,:) = 'this is and';bqq(i,:) = strcat('this is and, ', rs , '-', rt , '-',rd);
187                 case 'slt'
188                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
189                     b(i,27)=1;b(i,28)=0;b(i,29)=1;b(i,30)=0;b(i,31)=1;b(i,32)=0;
190                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
191                     bq(i,:) = 'this is slt';bqq(i,:) = strcat('this is slt, ', rs , '-', rt , '-',rd);
192                 case 'sll'
193                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;  
194                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=0;
195                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
196                      bq(i,:) = 'this is sll';
197 %                      bqq(i,:) = strcat('this is sll, ', rs , '-', rd , '-',imm_sh);
198                 case 'srl'
199                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;     
200                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=0;
201                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
202                      bq(i,:) = 'this is srl';
203 %                      bqq(i,:) = strcat('this is srl, ', rs , '-', rd , '-',imm_sh);
204                 case 'sra'
205                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;     
206                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=1;
207                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
208                      bq(i,:) = 'this is sra';
209                 case 'beq'
210                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=1;b(i,5)=0;b(i,6)=0;  
211                     b(i, 7:11) = rig_f(rd); b(i, 12:16) = rig_f(rs); b(i, 17:32) = rig_n(imm_sh);
212                     bq(i,:) = 'this is beq';
213                     %bqq(i,:) = strcat('this is beq, ', rd , '-', rs , '-',imm_sh);
214                 case 'bne'
215                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=1;b(i,5)=0;b(i,6)=1; 
216                     b(i, 7:11) = rig_f(rd); b(i, 12:16) = rig_f(rs); b(i, 17:32) = rig_n(imm_sh);
217                     bq(i,:) = 'this is bne';
218                     %bqq(i,:) = strcat('this is bne, ', rd , '-', rs , '-',imm_sh);
219                 case 'mul'
220                     b(i,1)=0;b(i,2)=1;b(i,3)=1;b(i,4)=1;b(i,5)=0;b(i,6)=0;
221                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=1;
222                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
223                     bq(i,:) = 'this is mul';bqq(i,:) = strcat('this is mul, ', rs , '-', rt , '-',rd);
224                 case 'muf'
225                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
226                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=1;b(i,31)=0;b(i,32)=1;
227                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
228                     bq(i,:) = 'this is mul';bqq(i,:) = strcat('this is mul, ', rs , '-', rt , '-',rd);
229                 otherwise    
230                             switch opcode1                    
231                                 case 'j'
232                                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=1;b(i,6)=0;
233                                     b(i, 7:32) = 9;
234                                     bq(i,:) = 'this is jrr';bqq(i,:) = strcat('this is j ', '66666666666666666666');
235                                 otherwise
236                             end
237                     end
238     end
239             
240                 switch opcode2                    
241                         case 'or'
242                             b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
243                             b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=1;b(i,31)=0;b(i,32)=1;
244                             b(i, 7:11) = rig_f(rs2); b(i, 12:16) = rig_f(rt2); b(i, 17:21) = rig_f(rd2); b(i, 22:26) = 0;
245                             bq(i,:) = 'this is orr';
246                         
247                         case 'lw'
248                              b(i,1)=1;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=1;b(i,6)=1;
249                              b(i, 7:11) = rig_f(rs_w);b(i, 12:16) = rig_f(rt_w); b(i, 17:32) = rig_n(imm_w);
250                             
251 %                              bqq(i,:) = strcat('this is lwr, ', rs_w, '-', rt_w, '-',imm_w); 
252                              bq(i,:) = 'this is lwr';
253                 
254                         case 'sw'
255                              b(i,1)=1;b(i,2)=0;b(i,3)=1;b(i,4)=0;b(i,5)=1;b(i,6)=1;  
256                              b(i, 7:11) = rig_f(rs_w);b(i, 12:16) = rig_f(rt_w); b(i, 17:32) = rig_n(imm_w);
257                              bq(i,:) = 'this is swr';
258                             otherwise         
259                         end
260 
261 
262 end     
263 
264 bb = num2str(b);
265 set(handles.edit1, 'String', bb);
266 set(handles.edit3, 'String', bq);
267 val = b;
268 
269 % --- Executes on button press in pushbutton2.
270 function pushbutton2_Callback(hObject, eventdata, handles)
271 global val
272 % hObject    handle to pushbutton2 (see GCBO)
273 % eventdata  reserved - to be defined in a future version of MATLAB
274 % handles    structure with handles and user data (see GUIDATA)
275 dlmwrite('C:\Users\ALIENWARE\Desktop\fft_test.txt', val, 'delimiter', '', 'precision', 6, 'newline','pc');
276 
277 
278 
279 function edit3_Callback(hObject, eventdata, handles)
280 % hObject    handle to edit3 (see GCBO)
281 % eventdata  reserved - to be defined in a future version of MATLAB
282 % handles    structure with handles and user data (see GUIDATA)
283 
284 % Hints: get(hObject,'String') returns contents of edit3 as text
285 %        str2double(get(hObject,'String')) returns contents of edit3 as a double
286 
287 
288 % --- Executes during object creation, after setting all properties.
289 function edit3_CreateFcn(hObject, eventdata, handles)
290 % hObject    handle to edit3 (see GCBO)
291 % eventdata  reserved - to be defined in a future version of MATLAB
292 % handles    empty - handles not created until after all CreateFcns called
293 
294 % Hint: edit controls usually have a white background on Windows.
295 %       See ISPC and COMPUTER.
296 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
297     set(hObject,'BackgroundColor','white');
298 end
299 
300 
301 % --- Executes on button press in pushbutton3.
302 function pushbutton3_Callback(hObject, eventdata, handles)
303 % hObject    handle to pushbutton3 (see GCBO)
304 % eventdata  reserved - to be defined in a future version of MATLAB
305 % handles    structure with handles and user data (see GUIDATA)
306 close(gcf);

 

函数rig_f 用来寻找名称对应的寄存器地址

 1 function [q] = rig_f(a)
 2 switch a
 3     case '0_'
 4         q(1)=0;q(2)=0;q(3)=0;q(4)=0;q(5)=0;
 5     case 'at'
 6         q(1)=0;q(2)=0;q(3)=0;q(4)=0;q(5)=1;    
 7     case 'v0'
 8         q(1)=0;q(2)=0;q(3)=0;q(4)=1;q(5)=0;
 9     case 'v1'
10         q(1)=0;q(2)=0;q(3)=0;q(4)=1;q(5)=1;        
11     case 'a0'
12         q(1)=0;q(2)=0;q(3)=1;q(4)=0;q(5)=0;        
13     case 'a1'
14         q(1)=0;q(2)=0;q(3)=1;q(4)=0;q(5)=1;        
15     case 'a2'
16         q(1)=0;q(2)=0;q(3)=1;q(4)=1;q(5)=0;        
17     case 'a3'
18         q(1)=0;q(2)=0;q(3)=1;q(4)=1;q(5)=1;        
19     case 't0'
20         q(1)=0;q(2)=1;q(3)=0;q(4)=0;q(5)=0;        
21     case 't1'
22         q(1)=0;q(2)=1;q(3)=0;q(4)=0;q(5)=1;
23     case 't2'
24         q(1)=0;q(2)=1;q(3)=0;q(4)=1;q(5)=0;        
25     case 't3'
26         q(1)=0;q(2)=1;q(3)=0;q(4)=1;q(5)=1;        
27     case 't4'
28         q(1)=0;q(2)=1;q(3)=1;q(4)=0;q(5)=0;        
29     case 't5'
30         q(1)=0;q(2)=1;q(3)=1;q(4)=0;q(5)=1;        
31     case 't6'
32         q(1)=0;q(2)=1;q(3)=1;q(4)=1;q(5)=0;
33     case 't7'
34         q(1)=0;q(2)=1;q(3)=1;q(4)=1;q(5)=1;        
35     case 's0'
36         q(1)=1;q(2)=0;q(3)=0;q(4)=0;q(5)=0;        
37     case 's1'
38         q(1)=1;q(2)=0;q(3)=0;q(4)=0;q(5)=1;        
39     case 's2'
40         q(1)=1;q(2)=0;q(3)=0;q(4)=1;q(5)=0;       
41     case 's3'
42         q(1)=1;q(2)=0;q(3)=0;q(4)=1;q(5)=1;
43     case 's4'
44         q(1)=1;q(2)=0;q(3)=1;q(4)=0;q(5)=0;        
45     case 's5'
46         q(1)=1;q(2)=0;q(3)=1;q(4)=0;q(5)=1;        
47     case 's6'
48         q(1)=1;q(2)=0;q(3)=1;q(4)=1;q(5)=0;       
49     case 's7'
50         q(1)=1;q(2)=0;q(3)=1;q(4)=1;q(5)=1;  
51     case 't8'
52         q(1)=1;q(2)=1;q(3)=0;q(4)=0;q(5)=0;          
53     case 't9'
54         q(1)=1;q(2)=1;q(3)=0;q(4)=0;q(5)=1;          
55     case 'k0'
56         q(1)=1;q(2)=1;q(3)=0;q(4)=1;q(5)=0;          
57     case 'k1'
58         q(1)=1;q(2)=1;q(3)=0;q(4)=1;q(5)=1;          
59     case 'gp'
60         q(1)=1;q(2)=1;q(3)=1;q(4)=0;q(5)=0;          
61     case 'sp'
62         q(1)=1;q(2)=1;q(3)=1;q(4)=0;q(5)=1;          
63     case 'fp'
64         q(1)=1;q(2)=1;q(3)=1;q(4)=1;q(5)=0;          
65     case 'ra'
66         q(1)=1;q(2)=1;q(3)=1;q(4)=1;q(5)=1;               
67     otherwise
68         q(1)=9;q(2)=9;q(3)=9;q(4)=9;q(5)=9;    
69 end

 

函数rig_n 用来将5位十进制数转换成16位2进制小数输出

 

 1 function [u] = rig_n(a)
 2 
 3 if (a(1) == '-')
 4     nu = str2num(a(2:5));
 5     num = 2^16 - nu;
 6     q = dec2bin(num, 16);
 7 else
 8     if (a(1) == '0' | a(1) == '1' | a(1) == '2' | a(1) == '3' | a(1) == '4' | a(1) == '5')
 9         nu = str2num(a);
10         q = dec2bin(nu,16);
11     end
12 end
13 
14 for i = 1 : 16
15     u(i) = str2num(q(i));
16 end

 

函数rig_sh 用来将3位十进制数转换成5位2进制小数输出 

1 function [u] = rig_sh(a)
2 num = str2num(a);
3 q = dec2bin(num, 5);
4 
5 for i = 1 : 5
6     u(i) = str2num(q(i))
7 end

 

最后欣赏一下炫酷的界面

MIPS架构——汇编代码转机器代码编译器 Matlab GUI_第1张图片

 

以及附带的read me 和最终打包的Matlab程序~~

 1 *** 修正了lw和sw指令
 2 *** 打开C2M.m文件运行程序
 3 *** 立即数变成5位,lw,sw,addi等指令的数字都变成了5位
 4 
 5 
 6 支持指令名称:
 7 add\sub\and\slt\sll\srl\beq\bne\mul\addi\or\lw\sw
 8 
 9 标准形式:
10 add    $s1, $s2, $s0 
11 sub    $s1, $s2, $s0 
12 and    $s1, $s2, $s0 
13 slt    $s1, $s2, $s0 
14 sll    $s1, $s2, 00005 
15 srl    $s1, $s2, 00005 
16 beq    $s1, $s2, 00004 
17 bne    $s1, $s2, 00004 
18 mul    $s1, $s2, $s3 
19 or    $s1, $s2, $s3  
20 lw    $s1, 00005($s2)  
21 sw    $s1, 00005($s2)  
22 addi    $s1, $s2, -12
23 
24 每一个命令之后加一个tab,地址前加$,逗号之后有空格,立即数的输入为3位,如5写成005,负数-5写成-05
25 寄存器文件按照书上标准,其中$0写法为$0_
26 
27 创建txt文件:
28 地址为:line266
29 C:\Users\ALIENWARE\Desktop\test_.txt    (需要改成你自己的地址)
30 
31 *不包含 j 指令
Read_me
  1 function varargout = C2M_export(varargin)
  2 val = zeros(1,1);
  3 
  4 % C2M_export MATLAB code for C2M_export.fig
  5 %      C2M_export, by itself, creates a new C2M_export or raises the existing
  6 %      singleton*.
  7 %
  8 %      H = C2M_export returns the handle to a new C2M_export or the handle to
  9 %      the existing singleton*.
 10 %
 11 %      C2M_export('CALLBACK',hObject,eventData,handles,...) calls the local
 12 %      function named CALLBACK in C2M_export.M with the given input arguments.
 13 %
 14 %      C2M_export('Property','Value',...) creates a new C2M_export or raises the
 15 %      existing singleton*.  Starting from the left, property value pairs are
 16 %      applied to the GUI before C2M_export_OpeningFcn gets called.  An
 17 %      unrecognized property name or invalid value makes property application
 18 %      stop.  All inputs are passed to C2M_export_OpeningFcn via varargin.
 19 %
 20 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
 21 %      instance to run (singleton)".
 22 %
 23 % See also: GUIDE, GUIDATA, GUIHANDLES
 24 
 25 % Edit the above text to modify the response to help C2M_export
 26 
 27 % Last Modified by GUIDE v2.5 19-Jul-2018 00:00:11
 28 
 29 % Begin initialization code - DO NOT EDIT
 30 gui_Singleton = 1;
 31 gui_State = struct('gui_Name',       mfilename, ...
 32                    'gui_Singleton',  gui_Singleton, ...
 33                    'gui_OpeningFcn', @C2M_export_OpeningFcn, ...
 34                    'gui_OutputFcn',  @C2M_export_OutputFcn, ...
 35                    'gui_LayoutFcn',  @C2M_export_LayoutFcn, ...
 36                    'gui_Callback',   []);
 37 if nargin && ischar(varargin{1})
 38     gui_State.gui_Callback = str2func(varargin{1});
 39 end
 40 
 41 if nargout
 42     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
 43 else
 44     gui_mainfcn(gui_State, varargin{:});
 45 end
 46 % End initialization code - DO NOT EDIT
 47 
 48 
 49 % --- Executes just before C2M_export is made visible.
 50 function C2M_export_OpeningFcn(hObject, eventdata, handles, varargin)
 51 % This function has no output args, see OutputFcn.
 52 % hObject    handle to figure
 53 % eventdata  reserved - to be defined in a future version of MATLAB
 54 % handles    structure with handles and user data (see GUIDATA)
 55 % varargin   command line arguments to C2M_export (see VARARGIN)
 56 
 57 % Choose default command line output for C2M_export
 58 handles.output = hObject;
 59 
 60 % Update handles structure
 61 guidata(hObject, handles);
 62 
 63 % UIWAIT makes C2M_export wait for user response (see UIRESUME)
 64 % uiwait(handles.figure1);
 65 
 66 
 67 % --- Outputs from this function are returned to the command line.
 68 function varargout = C2M_export_OutputFcn(hObject, eventdata, handles) 
 69 % varargout  cell array for returning output args (see VARARGOUT);
 70 % hObject    handle to figure
 71 % eventdata  reserved - to be defined in a future version of MATLAB
 72 % handles    structure with handles and user data (see GUIDATA)
 73 
 74 % Get default command line output from handles structure
 75 varargout{1} = handles.output;
 76 
 77 
 78 
 79 function edit1_Callback(hObject, eventdata, handles)
 80 % hObject    handle to edit1 (see GCBO)
 81 % eventdata  reserved - to be defined in a future version of MATLAB
 82 % handles    structure with handles and user data (see GUIDATA)
 83 
 84 % Hints: get(hObject,'String') returns contents of edit1 as text
 85 %        str2double(get(hObject,'String')) returns contents of edit1 as a double
 86 
 87 
 88 % --- Executes during object creation, after setting all properties.
 89 function edit1_CreateFcn(hObject, eventdata, handles)
 90 % hObject    handle to edit1 (see GCBO)
 91 % eventdata  reserved - to be defined in a future version of MATLAB
 92 % handles    empty - handles not created until after all CreateFcns called
 93 
 94 % Hint: edit controls usually have a white background on Windows.
 95 %       See ISPC and COMPUTER.
 96 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
 97     set(hObject,'BackgroundColor','white');
 98 end
 99 
100 
101 
102 function edit2_Callback(hObject, eventdata, handles)
103 % hObject    handle to edit2 (see GCBO)
104 % eventdata  reserved - to be defined in a future version of MATLAB
105 % handles    structure with handles and user data (see GUIDATA)
106 
107 % Hints: get(hObject,'String') returns contents of edit2 as text
108 %        str2double(get(hObject,'String')) returns contents of edit2 as a double
109 
110 
111 % --- Executes during object creation, after setting all properties.
112 function edit2_CreateFcn(hObject, eventdata, handles)
113 % hObject    handle to edit2 (see GCBO)
114 % eventdata  reserved - to be defined in a future version of MATLAB
115 % handles    empty - handles not created until after all CreateFcns called
116 
117 % Hint: edit controls usually have a white background on Windows.
118 %       See ISPC and COMPUTER.
119 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
120     set(hObject,'BackgroundColor','white');
121 end
122 
123 
124 % --- Executes on button press in pushbutton1.
125 function pushbutton1_Callback(hObject, eventdata, handles)
126 global val
127 % hObject    handle to pushbutton1 (see GCBO)
128 % eventdata  reserved - to be defined in a future version of MATLAB
129 % handles    structure with handles and user data (see GUIDATA)
130 
131 str1 = get(handles.edit2, 'String');    %??????
132 
133 x = size(str1, 2);  %????????
134 y = size(str1, 1);  %????????
135 %b = zeros(y, x);    %b??????????????????
136 
137 for i = 1 : y
138     
139     opcode1 = str1(i,1);
140     opcode2 = strcat(str1(i,1), str1(i,2));
141     opcode3 = strcat(str1(i,1), str1(i,2), str1(i,3));
142     opcode4 = strcat(str1(i,1), str1(i,2), str1(i,3), str1(i,4));
143     rd = strcat(str1(i, 6), str1(i, 7));
144     rs = strcat(str1(i,11), str1(i,12));
145     rt = strcat(str1(i,16), str1(i,17));
146     
147     if (x >= 19)
148         imm_sh = strcat(str1(i,15), str1(i,16), str1(i,17), str1(i, 18), str1(i, 19));
149     end
150     rt4 = strcat(str1(i,7), str1(i,8));
151     rs4 = strcat(str1(i,12), str1(i,13));
152     if (x >= 20) imm4 = strcat(str1(i,16), str1(i,17), str1(i, 18), str1(i, 19), str1(i, 20));
153     end
154     
155     rd2 = strcat(str1(i, 5), str1(i, 6));
156     rs2 = strcat(str1(i,10), str1(i,11));
157     rt2 = strcat(str1(i,15), str1(i,16));    
158     rt_w  = strcat(str1(i, 5), str1(i, 6));
159     imm_w = strcat(str1(i, 9), str1(i, 10), str1(i, 11), str1(i, 12), str1(i, 13));
160     rs_w  = strcat(str1(i, 16), str1(i, 17));
161     
162     switch opcode4         
163         case 'addi'
164             b(i,1)=0;b(i,2)=0;b(i,3)=1;b(i,4)=0;b(i,5)=0;b(i,6)=0;
165             b(i, 7:11) = rig_f(rs4); b(i, 12:16) = rig_f(rt4);
166             b(i, 17:32) = rig_n(imm4);
167 %            bq(i,:) = 'this is adi';bqq(i,:) = strcat('this is addi ', rs4 , '-', rt4 , '-',imm4);
168         otherwise
169             switch opcode3
170                 case 'add'
171                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0; 
172                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=0;
173                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
174                     bq(i,:) = 'this is add';bqq(i,:) = strcat('this is add, ', rs , '-', rt , '-',rd);
175                 case 'sub'
176                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
177                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=0;
178                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
179                     bq(i,:) = 'this is sub';bqq(i,:) = strcat('this is sub, ', rs , '-', rt , '-',rd);
180                 case 'and'
181                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
182                     b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=1;b(i,31)=0;b(i,32)=0;
183                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
184                     bq(i,:) = 'this is and';bqq(i,:) = strcat('this is and, ', rs , '-', rt , '-',rd);
185                 case 'slt'
186                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
187                     b(i,27)=1;b(i,28)=0;b(i,29)=1;b(i,30)=0;b(i,31)=1;b(i,32)=0;
188                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
189                     bq(i,:) = 'this is slt';bqq(i,:) = strcat('this is slt, ', rs , '-', rt , '-',rd);
190                 case 'sll'
191                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;  
192                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=0;
193                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
194                      bq(i,:) = 'this is sll';
195 %                      bqq(i,:) = strcat('this is sll, ', rs , '-', rd , '-',imm_sh);
196                 case 'srl'
197                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;     
198                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=0;
199                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
200                      bq(i,:) = 'this is srl';
201 %                      bqq(i,:) = strcat('this is srl, ', rs , '-', rd , '-',imm_sh);
202                 case 'sra'
203                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;     
204                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=1;b(i,32)=1;
205                     b(i, 7:11) = 0; b(i, 12:16) = rig_f(rs); b(i, 17:21) = rig_f(rd); b(i, 22:26) = rig_sh(imm_sh);
206                      bq(i,:) = 'this is sra';
207                 case 'beq'
208                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=1;b(i,5)=0;b(i,6)=0;  
209                     b(i, 7:11) = rig_f(rd); b(i, 12:16) = rig_f(rs); b(i, 17:32) = rig_n(imm_sh);
210                     bq(i,:) = 'this is beq';
211 %                    bqq(i,:) = strcat('this is beq, ', rd , '-', rs , '-',imm_sh);
212                 case 'bne'
213                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=1;b(i,5)=0;b(i,6)=1; 
214                     b(i, 7:11) = rig_f(rd); b(i, 12:16) = rig_f(rs); b(i, 17:32) = rig_n(imm_sh);
215                     bq(i,:) = 'this is bne';
216 %                    bqq(i,:) = strcat('this is bne, ', rd , '-', rs , '-',imm_sh);
217                 case 'mul'
218                     b(i,1)=0;b(i,2)=1;b(i,3)=1;b(i,4)=1;b(i,5)=0;b(i,6)=0;
219                     b(i,27)=0;b(i,28)=0;b(i,29)=0;b(i,30)=0;b(i,31)=0;b(i,32)=1;
220                     b(i, 7:11) = rig_f(rs); b(i, 12:16) = rig_f(rt); b(i, 17:21) = rig_f(rd); b(i, 22:26) = 0;
221                     bq(i,:) = 'this is mul';bqq(i,:) = strcat('this is mul, ', rs , '-', rt , '-',rd);
222                 otherwise    
223                             switch opcode1                    
224                                 case 'j'
225                                     b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=1;b(i,6)=0;
226                                     b(i, 7:32) = 9;
227                                     bq(i,:) = 'this is jrr';bqq(i,:) = strcat('this is j ', '66666666666666666666');
228                                 otherwise
229                             end
230                     end
231     end
232             
233                 switch opcode2                    
234                         case 'or'
235                             b(i,1)=0;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=0;b(i,6)=0;
236                             b(i,27)=1;b(i,28)=0;b(i,29)=0;b(i,30)=1;b(i,31)=0;b(i,32)=1;
237                             b(i, 7:11) = rig_f(rs2); b(i, 12:16) = rig_f(rt2); b(i, 17:21) = rig_f(rd2); b(i, 22:26) = 0;
238                             bq(i,:) = 'this is orr';
239                         
240                         case 'lw'
241                              b(i,1)=1;b(i,2)=0;b(i,3)=0;b(i,4)=0;b(i,5)=1;b(i,6)=1;
242                              b(i, 7:11) = rig_f(rs_w);b(i, 12:16) = rig_f(rt_w); b(i, 17:32) = rig_n(imm_w);
243                             
244 %                              bqq(i,:) = strcat('this is lwr, ', rs_w, '-', rt_w, '-',imm_w); 
245                              bq(i,:) = 'this is lwr';
246                 
247                         case 'sw'
248                              b(i,1)=1;b(i,2)=0;b(i,3)=1;b(i,4)=0;b(i,5)=1;b(i,6)=1;  
249                              b(i, 7:11) = rig_f(rs_w);b(i, 12:16) = rig_f(rt_w); b(i, 17:32) = rig_n(imm_w);
250                              bq(i,:) = 'this is swr';
251                             otherwise         
252                         end
253 
254 
255 end     
256 
257 bb = num2str(b);
258 set(handles.edit1, 'String', bb);
259 set(handles.edit3, 'String', bq);
260 val = b;
261 
262 % --- Executes on button press in pushbutton2.
263 function pushbutton2_Callback(hObject, eventdata, handles)
264 global val
265 % hObject    handle to pushbutton2 (see GCBO)
266 % eventdata  reserved - to be defined in a future version of MATLAB
267 % handles    structure with handles and user data (see GUIDATA)
268 dlmwrite('C:\Users\ALIENWARE\Desktop\fft_test.txt', val, 'delimiter', '', 'precision', 6, 'newline','pc');
269 
270 
271 
272 function edit3_Callback(hObject, eventdata, handles)
273 % hObject    handle to edit3 (see GCBO)
274 % eventdata  reserved - to be defined in a future version of MATLAB
275 % handles    structure with handles and user data (see GUIDATA)
276 
277 % Hints: get(hObject,'String') returns contents of edit3 as text
278 %        str2double(get(hObject,'String')) returns contents of edit3 as a double
279 
280 
281 % --- Executes during object creation, after setting all properties.
282 function edit3_CreateFcn(hObject, eventdata, handles)
283 % hObject    handle to edit3 (see GCBO)
284 % eventdata  reserved - to be defined in a future version of MATLAB
285 % handles    empty - handles not created until after all CreateFcns called
286 
287 % Hint: edit controls usually have a white background on Windows.
288 %       See ISPC and COMPUTER.
289 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
290     set(hObject,'BackgroundColor','white');
291 end
292 
293 
294 % --- Executes on button press in pushbutton3.
295 function pushbutton3_Callback(hObject, eventdata, handles)
296 % hObject    handle to pushbutton3 (see GCBO)
297 % eventdata  reserved - to be defined in a future version of MATLAB
298 % handles    structure with handles and user data (see GUIDATA)
299 close(gcf);
300 
301 % --- Creates and returns a handle to the GUI figure. 
302 function h1 = C2M_export_LayoutFcn(policy)
303 % policy - create a new figure or use a singleton. 'new' or 'reuse'.
304 
305 persistent hsingleton;
306 if strcmpi(policy, 'reuse') & ishandle(hsingleton)
307     h1 = hsingleton;
308     return;
309 end
310 load C2M_export.mat
311 
312 
313 appdata = [];
314 appdata.GUIDEOptions = mat{1};
315 appdata.lastValidTag = 'figure1';
316 appdata.GUIDELayoutEditor = [];
317 appdata.initTags = struct(...
318     'handle', [], ...
319     'tag', 'figure1');
320 
321 h1 = figure(...
322 'PaperUnits','inches',...
323 'Units','characters',...
324 'Position',[135.8 23.5 250.2 52.2857142857143],...
325 'Visible',get(0,'defaultfigureVisible'),...
326 'Color',[0.313725490196078 0.313725490196078 0.313725490196078],...
327 'IntegerHandle','off',...
328 'MenuBar','none',...
329 'Name','C2M',...
330 'NumberTitle','off',...
331 'Tag','figure1',...
332 'Resize','off',...
333 'PaperPosition',get(0,'defaultfigurePaperPosition'),...
334 'PaperSize',[8.5 11],...
335 'PaperSizeMode',get(0,'defaultfigurePaperSizeMode'),...
336 'PaperType','usletter',...
337 'PaperTypeMode',get(0,'defaultfigurePaperTypeMode'),...
338 'PaperUnitsMode',get(0,'defaultfigurePaperUnitsMode'),...
339 'ScreenPixelsPerInchMode','manual',...
340 'HandleVisibility','callback',...
341 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
342 
343 appdata = [];
344 appdata.lastValidTag = 'edit1';
345 
346 h2 = uicontrol(...
347 'Parent',h1,...
348 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
349 'Units','characters',...
350 'HorizontalAlignment','left',...
351 'Max',50,...
352 'String',blanks(0),...
353 'Style','edit',...
354 'Position',[69.6 16.3571428571429 110.2 28.7142857142857],...
355 'BackgroundColor',[0.105882352941176 0.309803921568627 0.207843137254902],...
356 'Callback',@(hObject,eventdata)C2M_export('edit1_Callback',hObject,eventdata,guidata(hObject)),...
357 'Children',[],...
358 'ForegroundColor',[1 1 1],...
359 'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)C2M_export('edit1_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
360 'Tag','edit1',...
361 'FontSize',10);
362 
363 appdata = [];
364 appdata.lastValidTag = 'edit2';
365 
366 h3 = uicontrol(...
367 'Parent',h1,...
368 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
369 'Units','characters',...
370 'HorizontalAlignment','left',...
371 'Max',50,...
372 'String',blanks(0),...
373 'Style','edit',...
374 'Position',[9.8 16.3571428571429 50.2 28.8571428571429],...
375 'BackgroundColor',[0.862745098039216 0.862745098039216 0.862745098039216],...
376 'Callback',@(hObject,eventdata)C2M_export('edit2_Callback',hObject,eventdata,guidata(hObject)),...
377 'Children',[],...
378 'ForegroundColor',[0.231372549019608 0.443137254901961 0.337254901960784],...
379 'TooltipString',blanks(0),...
380 'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)C2M_export('edit2_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
381 'Tag','edit2',...
382 'FontSize',10,...
383 'FontWeight',get(0,'defaultuicontrolFontWeight'));
384 
385 appdata = [];
386 appdata.lastValidTag = 'pushbutton1';
387 
388 h4 = uicontrol(...
389 'Parent',h1,...
390 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
391 'Units','characters',...
392 'String','Come On Boy !',...
393 'Style',get(0,'defaultuicontrolStyle'),...
394 'Value',1,...
395 'ValueMode',get(0,'defaultuicontrolValueMode'),...
396 'Position',[9.8 2.14285714285714 140.2 10.7857142857143],...
397 'BackgroundColor',[1 0 0],...
398 'Callback',@(hObject,eventdata)C2M_export('pushbutton1_Callback',hObject,eventdata,guidata(hObject)),...
399 'Children',[],...
400 'ForegroundColor',[0.945098039215686 0.968627450980392 0.949019607843137],...
401 'Tag','pushbutton1',...
402 'FontSize',22,...
403 'FontWeight','bold',...
404 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
405 
406 appdata = [];
407 appdata.lastValidTag = 'pushbutton2';
408 
409 h5 = uicontrol(...
410 'Parent',h1,...
411 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
412 'Units','characters',...
413 'String','Create txt file',...
414 'Style',get(0,'defaultuicontrolStyle'),...
415 'Position',[159.6 2.14285714285714 60.2 10.7857142857143],...
416 'BackgroundColor',[1 1 1],...
417 'Callback',@(hObject,eventdata)C2M_export('pushbutton2_Callback',hObject,eventdata,guidata(hObject)),...
418 'Children',[],...
419 'ForegroundColor',[0.105882352941176 0.309803921568627 0.207843137254902],...
420 'Tag','pushbutton2',...
421 'FontSize',22,...
422 'FontAngle','italic',...
423 'FontWeight','bold',...
424 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
425 
426 appdata = [];
427 appdata.lastValidTag = 'text3';
428 
429 h6 = uicontrol(...
430 'Parent',h1,...
431 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
432 'Units','characters',...
433 'String','Assemble Language',...
434 'Style','text',...
435 'Position',[5.4 45.7857142857143 60.8 2.92857142857143],...
436 'BackgroundColor',[0.313725490196078 0.313725490196078 0.313725490196078],...
437 'Children',[],...
438 'ForegroundColor',[0.941176470588235 0.941176470588235 0.941176470588235],...
439 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
440 'Tag','text3',...
441 'FontSize',22,...
442 'FontAngle','italic',...
443 'FontWeight','bold');
444 
445 appdata = [];
446 appdata.lastValidTag = 'text4';
447 
448 h7 = uicontrol(...
449 'Parent',h1,...
450 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
451 'Units','characters',...
452 'String','Machine Language',...
453 'Style','text',...
454 'Position',[93.6 45.6428571428571 60.8 2.92857142857143],...
455 'BackgroundColor',[0.313725490196078 0.313725490196078 0.313725490196078],...
456 'Children',[],...
457 'ForegroundColor',[1 1 1],...
458 'ButtonDownFcn',blanks(0),...
459 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
460 'DeleteFcn',blanks(0),...
461 'Tag','text4',...
462 'FontSize',22,...
463 'FontAngle','italic',...
464 'FontWeight','bold');
465 
466 appdata = [];
467 appdata.lastValidTag = 'edit3';
468 
469 h8 = uicontrol(...
470 'Parent',h1,...
471 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
472 'Units','characters',...
473 'Max',50,...
474 'String',blanks(0),...
475 'Style','edit',...
476 'Position',[189.4 16.3571428571429 50.4 28.7142857142857],...
477 'BackgroundColor',[0 0 0],...
478 'Callback',@(hObject,eventdata)C2M_export('edit3_Callback',hObject,eventdata,guidata(hObject)),...
479 'Children',[],...
480 'ForegroundColor',[1 0.949019607843137 0.866666666666667],...
481 'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)C2M_export('edit3_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
482 'Tag','edit3',...
483 'FontSize',10,...
484 'FontWeight','bold');
485 
486 appdata = [];
487 appdata.lastValidTag = 'text5';
488 
489 h9 = uicontrol(...
490 'Parent',h1,...
491 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
492 'Units','characters',...
493 'String','States',...
494 'Style','text',...
495 'Position',[182.4 45.6428571428571 60.8 2.92857142857143],...
496 'BackgroundColor',[0.313725490196078 0.313725490196078 0.313725490196078],...
497 'Children',[],...
498 'ForegroundColor',[1 1 1],...
499 'ButtonDownFcn',blanks(0),...
500 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
501 'DeleteFcn',blanks(0),...
502 'Tag','text5',...
503 'FontSize',22,...
504 'FontAngle','italic',...
505 'FontWeight','bold');
506 
507 appdata = [];
508 appdata.lastValidTag = 'pushbutton3';
509 
510 h10 = uicontrol(...
511 'Parent',h1,...
512 'FontUnits',get(0,'defaultuicontrolFontUnits'),...
513 'Units','characters',...
514 'String','EXIT',...
515 'Style',get(0,'defaultuicontrolStyle'),...
516 'Position',[219.8 2.07142857142857 20.2 10.7857142857143],...
517 'BackgroundColor',[0.105882352941176 0.309803921568627 0.207843137254902],...
518 'Callback',@(hObject,eventdata)C2M_export('pushbutton3_Callback',hObject,eventdata,guidata(hObject)),...
519 'Children',[],...
520 'ForegroundColor',[1 1 1],...
521 'Tag','pushbutton3',...
522 'FontSize',14,...
523 'FontAngle','italic',...
524 'FontWeight','bold',...
525 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
526 
527 
528 hsingleton = h1;
529 
530 
531 % --- Set application data first then calling the CreateFcn. 
532 function local_CreateFcn(hObject, eventdata, createfcn, appdata)
533 
534 if ~isempty(appdata)
535    names = fieldnames(appdata);
536    for i=1:length(names)
537        name = char(names(i));
538        setappdata(hObject, name, getfield(appdata,name));
539    end
540 end
541 
542 if ~isempty(createfcn)
543    if isa(createfcn,'function_handle')
544        createfcn(hObject, eventdata);
545    else
546        eval(createfcn);
547    end
548 end
549 
550 
551 % --- Handles default GUIDE GUI creation and callback dispatch
552 function varargout = gui_mainfcn(gui_State, varargin)
553 
554 gui_StateFields =  {'gui_Name'
555     'gui_Singleton'
556     'gui_OpeningFcn'
557     'gui_OutputFcn'
558     'gui_LayoutFcn'
559     'gui_Callback'};
560 gui_Mfile = '';
561 for i=1:length(gui_StateFields)
562     if ~isfield(gui_State, gui_StateFields{i})
563         error(message('MATLAB:guide:StateFieldNotFound', gui_StateFields{ i }, gui_Mfile));
564     elseif isequal(gui_StateFields{i}, 'gui_Name')
565         gui_Mfile = [gui_State.(gui_StateFields{i}), '.m'];
566     end
567 end
568 
569 numargin = length(varargin);
570 
571 if numargin == 0
572     % C2M_EXPORT
573     % create the GUI only if we are not in the process of loading it
574     % already
575     gui_Create = true;
576 elseif local_isInvokeActiveXCallback(gui_State, varargin{:})
577     % C2M_EXPORT(ACTIVEX,...)
578     vin{1} = gui_State.gui_Name;
579     vin{2} = [get(varargin{1}.Peer, 'Tag'), '_', varargin{end}];
580     vin{3} = varargin{1};
581     vin{4} = varargin{end-1};
582     vin{5} = guidata(varargin{1}.Peer);
583     feval(vin{:});
584     return;
585 elseif local_isInvokeHGCallback(gui_State, varargin{:})
586     % C2M_EXPORT('CALLBACK',hObject,eventData,handles,...)
587     gui_Create = false;
588 else
589     % C2M_EXPORT(...)
590     % create the GUI and hand varargin to the openingfcn
591     gui_Create = true;
592 end
593 
594 if ~gui_Create
595     % In design time, we need to mark all components possibly created in
596     % the coming callback evaluation as non-serializable. This way, they
597     % will not be brought into GUIDE and not be saved in the figure file
598     % when running/saving the GUI from GUIDE.
599     designEval = false;
600     if (numargin>1 && ishghandle(varargin{2}))
601         fig = varargin{2};
602         while ~isempty(fig) && ~ishghandle(fig,'figure')
603             fig = get(fig,'parent');
604         end
605         
606         designEval = isappdata(0,'CreatingGUIDEFigure') || (isscalar(fig)&&isprop(fig,'GUIDEFigure'));
607     end
608         
609     if designEval
610         beforeChildren = findall(fig);
611     end
612     
613     % evaluate the callback now
614     varargin{1} = gui_State.gui_Callback;
615     if nargout
616         [varargout{1:nargout}] = feval(varargin{:});
617     else       
618         feval(varargin{:});
619     end
620     
621     % Set serializable of objects created in the above callback to off in
622     % design time. Need to check whether figure handle is still valid in
623     % case the figure is deleted during the callback dispatching.
624     if designEval && ishghandle(fig)
625         set(setdiff(findall(fig),beforeChildren), 'Serializable','off');
626     end
627 else
628     if gui_State.gui_Singleton
629         gui_SingletonOpt = 'reuse';
630     else
631         gui_SingletonOpt = 'new';
632     end
633 
634     % Check user passing 'visible' P/V pair first so that its value can be
635     % used by oepnfig to prevent flickering
636     gui_Visible = 'auto';
637     gui_VisibleInput = '';
638     for index=1:2:length(varargin)
639         if length(varargin) == index || ~ischar(varargin{index})
640             break;
641         end
642 
643         % Recognize 'visible' P/V pair
644         len1 = min(length('visible'),length(varargin{index}));
645         len2 = min(length('off'),length(varargin{index+1}));
646         if ischar(varargin{index+1}) && strncmpi(varargin{index},'visible',len1) && len2 > 1
647             if strncmpi(varargin{index+1},'off',len2)
648                 gui_Visible = 'invisible';
649                 gui_VisibleInput = 'off';
650             elseif strncmpi(varargin{index+1},'on',len2)
651                 gui_Visible = 'visible';
652                 gui_VisibleInput = 'on';
653             end
654         end
655     end
656     
657     % Open fig file with stored settings.  Note: This executes all component
658     % specific CreateFunctions with an empty HANDLES structure.
659 
660     
661     % Do feval on layout code in m-file if it exists
662     gui_Exported = ~isempty(gui_State.gui_LayoutFcn);
663     % this application data is used to indicate the running mode of a GUIDE
664     % GUI to distinguish it from the design mode of the GUI in GUIDE. it is
665     % only used by actxproxy at this time.   
666     setappdata(0,genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]),1);
667     if gui_Exported
668         gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
669 
670         % make figure invisible here so that the visibility of figure is
671         % consistent in OpeningFcn in the exported GUI case
672         if isempty(gui_VisibleInput)
673             gui_VisibleInput = get(gui_hFigure,'Visible');
674         end
675         set(gui_hFigure,'Visible','off')
676 
677         % openfig (called by local_openfig below) does this for guis without
678         % the LayoutFcn. Be sure to do it here so guis show up on screen.
679         movegui(gui_hFigure,'onscreen');
680     else
681         gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);
682         % If the figure has InGUIInitialization it was not completely created
683         % on the last pass.  Delete this handle and try again.
684         if isappdata(gui_hFigure, 'InGUIInitialization')
685             delete(gui_hFigure);
686             gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);
687         end
688     end
689     if isappdata(0, genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]))
690         rmappdata(0,genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]));
691     end
692 
693     % Set flag to indicate starting GUI initialization
694     setappdata(gui_hFigure,'InGUIInitialization',1);
695 
696     % Fetch GUIDE Application options
697     gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
698     % Singleton setting in the GUI MATLAB code file takes priority if different
699     gui_Options.singleton = gui_State.gui_Singleton;
700 
701     if ~isappdata(gui_hFigure,'GUIOnScreen')
702         % Adjust background color
703         if gui_Options.syscolorfig
704             set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
705         end
706 
707         % Generate HANDLES structure and store with GUIDATA. If there is
708         % user set GUI data already, keep that also.
709         data = guidata(gui_hFigure);
710         handles = guihandles(gui_hFigure);
711         if ~isempty(handles)
712             if isempty(data)
713                 data = handles;
714             else
715                 names = fieldnames(handles);
716                 for k=1:length(names)
717                     data.(char(names(k)))=handles.(char(names(k)));
718                 end
719             end
720         end
721         guidata(gui_hFigure, data);
722     end
723 
724     % Apply input P/V pairs other than 'visible'
725     for index=1:2:length(varargin)
726         if length(varargin) == index || ~ischar(varargin{index})
727             break;
728         end
729 
730         len1 = min(length('visible'),length(varargin{index}));
731         if ~strncmpi(varargin{index},'visible',len1)
732             try set(gui_hFigure, varargin{index}, varargin{index+1}), catch break, end
733         end
734     end
735 
736     % If handle visibility is set to 'callback', turn it on until finished
737     % with OpeningFcn
738     gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
739     if strcmp(gui_HandleVisibility, 'callback')
740         set(gui_hFigure,'HandleVisibility', 'on');
741     end
742 
743     feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
744 
745     if isscalar(gui_hFigure) && ishghandle(gui_hFigure)
746         % Handle the default callbacks of predefined toolbar tools in this
747         % GUI, if any
748         guidemfile('restoreToolbarToolPredefinedCallback',gui_hFigure); 
749         
750         % Update handle visibility
751         set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
752 
753         % Call openfig again to pick up the saved visibility or apply the
754         % one passed in from the P/V pairs
755         if ~gui_Exported
756             gui_hFigure = local_openfig(gui_State.gui_Name, 'reuse',gui_Visible);
757         elseif ~isempty(gui_VisibleInput)
758             set(gui_hFigure,'Visible',gui_VisibleInput);
759         end
760         if strcmpi(get(gui_hFigure, 'Visible'), 'on')
761             figure(gui_hFigure);
762             
763             if gui_Options.singleton
764                 setappdata(gui_hFigure,'GUIOnScreen', 1);
765             end
766         end
767 
768         % Done with GUI initialization
769         if isappdata(gui_hFigure,'InGUIInitialization')
770             rmappdata(gui_hFigure,'InGUIInitialization');
771         end
772 
773         % If handle visibility is set to 'callback', turn it on until
774         % finished with OutputFcn
775         gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
776         if strcmp(gui_HandleVisibility, 'callback')
777             set(gui_hFigure,'HandleVisibility', 'on');
778         end
779         gui_Handles = guidata(gui_hFigure);
780     else
781         gui_Handles = [];
782     end
783 
784     if nargout
785         [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
786     else
787         feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
788     end
789 
790     if isscalar(gui_hFigure) && ishghandle(gui_hFigure)
791         set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
792     end
793 end
794 
795 function gui_hFigure = local_openfig(name, singleton, visible)
796 
797 % openfig with three arguments was new from R13. Try to call that first, if
798 % failed, try the old openfig.
799 if nargin('openfig') == 2
800     % OPENFIG did not accept 3rd input argument until R13,
801     % toggle default figure visible to prevent the figure
802     % from showing up too soon.
803     gui_OldDefaultVisible = get(0,'defaultFigureVisible');
804     set(0,'defaultFigureVisible','off');
805     gui_hFigure = matlab.hg.internal.openfigLegacy(name, singleton);
806     set(0,'defaultFigureVisible',gui_OldDefaultVisible);
807 else
808     % Call version of openfig that accepts 'auto' option"
809     gui_hFigure = matlab.hg.internal.openfigLegacy(name, singleton, visible);  
810 %     %workaround for CreateFcn not called to create ActiveX
811 %         peers=findobj(findall(allchild(gui_hFigure)),'type','uicontrol','style','text');    
812 %         for i=1:length(peers)
813 %             if isappdata(peers(i),'Control')
814 %                 actxproxy(peers(i));
815 %             end            
816 %         end
817 end
818 
819 function result = local_isInvokeActiveXCallback(gui_State, varargin)
820 
821 try
822     result = ispc && iscom(varargin{1}) ...
823              && isequal(varargin{1},gcbo);
824 catch
825     result = false;
826 end
827 
828 function result = local_isInvokeHGCallback(gui_State, varargin)
829 
830 try
831     fhandle = functions(gui_State.gui_Callback);
832     result = ~isempty(findstr(gui_State.gui_Name,fhandle.file)) || ...
833              (ischar(varargin{1}) ...
834              && isequal(ishghandle(varargin{2}), 1) ...
835              && (~isempty(strfind(varargin{1},[get(varargin{2}, 'Tag'), '_'])) || ...
836                 ~isempty(strfind(varargin{1}, '_CreateFcn'))) );
837 catch
838     result = false;
839 end
C2M_EXPORT

 

转载于:https://www.cnblogs.com/olivermahout/p/9333359.html

你可能感兴趣的:(matlab,嵌入式)