MIPS架構下MCU指令——彙編代碼轉機器代碼編譯器 Matlab GUI

来源:https://www.cnblogs.com/olivermahout/archive/2018/07/19/9333359.html
-Advertisement-
Play Games

MIPS架構下的MCU,指令集包含R-Type、I-Type、J-Type三種,在數電課程設計時為了給MCU編寫指令集,需要將彙編語言轉化成機器代碼,這裡分享一下自己寫的Matlab 的 GUI。 主函數 C2M 函數rig_f 用來尋找名稱對應的寄存器地址 函數rig_n 用來將5位十進位數轉換成 ...


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 %	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一、關於樣式(CSS) 1、Input 1)Input可編輯可下拉 2)Input下拉 3)Input邊線點擊不顯示 input點擊邊框樣式無效 4)提示文字:placeholder="手機號" input修改提示文字顏色 5)input出現背景是黃色 這種點擊框也不會出現黃色了 還有一種就是關閉自 ...
  • 前言 秒殺架構到後期,我們採用了消息隊列的形式實現搶購邏輯,那麼之前拋出過這樣一個問題:消息隊列非同步處理完每個用戶請求後,如何通知給相應用戶秒殺成功? 場景映射 首先,我們舉一個生活中比較常見的例子:我們去銀行辦理業務,一般會選擇相關業務列印一個排號紙,然後就可以坐在小板凳上玩著手機,等待被小喇叭報 ...
  • fork/join作為一個併發框架在jdk7的時候就加入到了我們的java併發包java.util.concurrent中,並且在java 8 的lambda並行流中充當著底層框架的角色。這樣一個優秀的框架設計,我自己想瞭解一下它的底層代碼是如何實現的,所以我嘗試的去閱讀了JDK相關的源碼。下麵我打 ...
  • 所有的異常都有一個超類throwable; throwable有兩個子類:Exception和error(一般在重大錯誤,不能夠自行恢復); Exception有兩個子類:checked和runtime exception異常; checked:檢查時異常,就是程式代碼有的錯誤會有紅色波浪線的異常, ...
  • Description Mato同學最近正在研究一種矩陣,這種矩陣有n行n列第i行第j列的數為gcd(i,j)。 例如n=5時,矩陣如下: 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 2 1 4 1 1 1 1 1 5 Mato想知道這個矩陣的行列式的值,你能求出來嗎? Mato ...
  • 上次知識回顧:https://www.cnblogs.com/dotnetcrazy/p/9278573.html 代碼褲子:https://github.com/lotapp/BaseCode 線上編程:https://mybinder.org/v2/gh/lotapp/BaseCode/mast ...
  • 引言 上一篇文章聊到了Java記憶體模型,在其中我們說JMM是建立在happens before(先行發生)原則之上的。 為什麼這麼說呢?因為在Java程式的執行過程中,編譯器和處理器對我們所寫的代碼進行了一系列的優化來提高程式的執行效率。這其中就包括對指令的“重排序”。 重排序導致了我們代碼並不會按 ...
  • goroutine只是由官方實現的超級"線程池"而已,每個實例4 5kb的棧記憶體占用和用於實現機制而大幅減少的創建和銷毀開銷。 併發不是並行(多CPU): 併發主要由切換時間片來實現"同時"運行,並行則是直接利用多核實現多線程的運行,但Go可以設置使用核數,以發揮多核電腦的能力。 通過go關鍵字實 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...