关键词不能为空

当前您在: 主页 > 英语 >

MARS使用手册

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-06 10:57
tags:

-

2021年2月6日发(作者:aote)


MARS


使用手册





MARS



MIPS


汇编语言的模拟机,由密苏里州立大学开发,其下载地址是

/MARS




目前最新版本为< /p>


3.6




下面 我们将分三个部分介绍


MARS






第一部分:


MARS


的基本使用



< p>
我们将根据示例程序



----

用于计算斐波那契序列,来具体演示


MARS


的操


作步骤。



1




双击< /p>


,启动


MARS


程序。

< br>


2




点击菜单


File…O


pen


或者双 击打开工具栏按钮


,打开



< p>
序。(所有的工具栏按钮都具有相应的菜单项,在后续的具体操作中我们


将 尽可能地使用工具栏按钮。



3




双击< /p>


工具栏按钮


,汇编该程序。



4




熟悉程 序初始数据在内存中的位置和具体的数值。单击复选框


,在“


1 0


进制显示”和“


16


进制显示”之间 进行切


换。



?



长度为


1 9


的数组


fibs


被初始化为


0


,其内存地址为


0x10010000 …


0x10010048




?



变量


si ze


的内存地址为


0x1001004c


,其值为


19.



?



地址


0x10010050 … 0x1001006c


中存放着一些非空的


ASCII


串。



5




使用“


Settings


”菜单配置


MARS


的显示内容。



6




观察寄 存器显示窗口,这里显示了


32


个通用


MIPS


寄存器的内容。寄存器


显示窗口里的另外两个标签页显 示了浮点运算寄存器


(Coproc 1)



(Coproc


0)


,暂时可以不看。



7




使用滑 动条来改变运行速度,便于观察汇编程序的执行过程,而不是瞬间


运行完毕。

< p>


8




选择程序运行方式:



?



:直接运行程序:通过黄色高亮部 分来观察程序的运行,并在数


据段显示窗口


Data Segment display


中观察斐波那契序列数值的变化。

如下图中黄色和蓝色部分。





Page 1



?



?





9




在输入输出窗口中观察程序的输出,如下图所示:



:重置程序为初始值。



:单步执行程 序,和


(单步回退程序)功能相反。



10




?



在输出结果子程序的第一条指令前 添加断点,即勾中该指令的复选


框。



?



?



单击



,重新运行程序后,程序将在断点处 停止运行。



?



双击存储菲波那契序列



某个内存位置,该单元将高亮显示,并接受键




修改某个内存地址中的内容。(修改寄存器的内容类似)



盘输入。输入一个数值,按回车键结束输入,如下图所示,内存地址


0x10010008


中现在存放的数据是


0x0000002 4





?



单击


,从 断点处继续执行程序。程序的输出将会包含刚才输入的


数值,而不是原来的菲波那契数。



单击


,查看帮助文件,熟悉


MIPS


指令、伪指令、


directives



syscalls




12




修改程序,使得



程序运行时提示用户输入菲波那契序列的长度。



11






Page 2


?



选择


Ed ition


标签页,返回程序编辑界面。




?



MIP S


注释符号是


#


。一行中


#


后面的所有符号都是注释内容。



?



去掉第


1 2


行到第


19


行代码的注释标志,这几 行用于提示用户输入




波那契序列的 长度,允许输入的长度范围为


2-19


(主要是受


32


位数的


大小限制)。



?



查找帮助文件,找出执行读入整数 功能的


syscall


指令的参数值。



13




重新运行程序,观察结果值。





Page 3



Part 2 : MARS Tools



You may have noticed that MARS has a


Tools


menu. The capabilities provided


through this menu really catapult MARS into a different league of computer science


educational software.



We call each of the items in the Tools menu a MARS Tool. A MARS Tool is best


described as a pop-up application that observes MIPS memory and/or register activity


during MIPS program execution then communicates that activity to the tool user to serve


a particular purpose. This is best seen by example.




MARS Tools Activity 1 : Running the Data Cache Simulator tool



1.




2.



Open the program



from the


Examples


folder. This


program will traverse a 16 by 16 element integer matrix in row-major order, assigning


elements the values 0 through 255 in order. It performs the following algorithm:



for (row = 0; row < 16; row++)


for (col = 0; col < 16; col++)


data[row][col] = value++;




3.



Assemble the program.



4.



From the


Tools


menu, select


Data Cache Simulator


. A new frame will


appear in the middle of the screen.



Close any MIPS programs you are currently using.





Page 4


This is a MARS Tool that will simulate the use and performance of cache


memory when the underlying MIPS program executes. Notice its three major


sections:


?



Cache Organization:


You can use the combo boxes to specify


how the cache will be configured for this run. Feel free to explore the


different settings, but the default is fine for now.


?



Cache Performance:


With each memory access during program


execution, the simulator will determine whether or not that access can be


satisfied from cache and update the performance display accordingly.


?



Tool Control:


These buttons perform generic control functions as


described by their labels.



5.



Click the tool's


Connect to MIPS


button. This causes the tool to register


as an observer of MIPS memory and thus respond during program execution.



6.



Back in MARS, adjust the


Run Speed slider


to 30 instructions per second.


It is located at the right side of the toolbar. This slows execution so you can watch


the Cache Performance animation.




7.



In MARS, run the program using the


Run


toolbar button


, the menu


item or keyboard shortcut. Watch the Cache Performance animate as it is updated


with every access to MIPS memory.



8.



What was the final cache hit rate?


_____________. With each miss, a


block of 4 words are written into the cache. In a row-major traversal, matrix elements


are accessed in the same order they are stored in memory. Thus each cache miss is


followed by 3 hits as the next 3 elements are found in the same cache block. This is


followed by another miss when Direct Mapping maps to the next cache block, and the


patterns repeats itself. So 3 of every 4 memory accesses will be resolved in cache.



9.



Given that explanation,


what do you predict the hit rate will be if the block


size is increased from 4 words to 8 words?


______________.


Decreased from 4


words to 2 words?


___________.



10.



Verify your predictions by modifying the block size and re- running the


program from step 7.


NOTE:


when you modify the Cache Organization, the performance values are


automatically reset (you can always use the tool's


Reset


button).


NOTE:


You have to


reset



the MIPS program before you can re-run it.


NOTE:


Feel free to adjust the


Run Speed slider


to maximum speed anytime you


want.





Page 5


11.



Repeat steps 2 through 10 for program



from the


Examples


folder. This program will traverse a 16 by 16 element integer matrix in


column-major order, assigning elements the values 0 through 255 in order. It


performs the following algorithm:



for (col = 0; col < 16; col++)


for (row = 0; row < 16; row++)


data[row][col] = value++;




NOTE:


You can leave the Cache Simulator in place, move it out of the way, or close


it. It will not interfere with the actions needed to open, assemble, or run this new


program and will remain connected to MIPS memory. If you do not close the tool,


then skip steps 4 and 5.



12.



What was the cache performance for this program?


____________. The


problem is the memory locations are now accessed not sequentially as before, but


each access is 16 words beyond the previous one (circularly). With the settings we've


used, no two consecutive memory accesses occur in the same block so every access is


a miss.



13.



Change the block size to 16. Note this will reset the tool.



14.



Create a second instance of the Cache Simulator by once again selecting


Data Cache Simulator


from the


Tools


menu. Adjust the two frames so you can


view both at the same time. Connect the new tool instance to MIPS, change its block


size to 16 and change its number of blocks to 16.



15.



Re-run the program.


What is the cache performance of the original tool


instance?


____________. Block size 16 didn't help because there was still only one


access to each block, the initial miss, before that block was replaced with a new one.


What is the cache performance of the second tool instance?


____________. At this


point, the entire matrix will fit into cache and so once a block is read in it is never


replaced. Only the first access to a block results in a miss.




In what courses might an exercise like this one be useful for your students? I have


used a variation on this exercise as a student exercise in Operating Systems, and for a


lecture illustration of the cache concept in Otterbein's CS 0 course,


Computer Science







Page 6


MARS Tools Activity 2 : Running the Cache Simulator as a stand-


alone





1.



In command mode, traverse to the directory containing and enter


the command:



java -classpath imulator




2.



The cache simulator tool is launched. Its Tool Control section is replaced


by Application Control, which contains additional controls for loading, assembling


and running MIPS programs. It uses MARS' MIPS assembler and runtime simulator


in the background to control MIPS execution.






3.



Click the


Open MIPS program


button and a File Open dialog will pop up.


Browse to and select a MIPS program to run. Select


row_


again if you


wish.



4.



The


Assemble and Run


button is now enabled. Click it to assemble and


run the program. The animation will be very rapid.



5.



Use the


Run Speed slider


to adjust the running speed, click the


Reset



button then click


Assemble and Run


again. While the program is running, the


Stop



button is enabled. Program status is updated in the single line text field.




We plan to implement a small MARS Tool Suite application to simplify the


selection and launching of tools such as the Cache Simulator that are capable of running




Page 7


outside the MARS integrated development environment.




Page 8


MARS Tools Activity 3 : The Memory Reference Visualization tool




1.



Open the program



from the


Examples


folder if it is


not already open.



2.



Assemble the program.



3.



From the


Tools


menu, select


Memory Reference Visualization


. A new


frame will appear in the middle of the screen.





This tool will paint a grid unit each time the corresponding MIPS memory word


is referenced. The base address, the first static data segment (


.data


directive) word,


corresponds to the upper-left grid unit. Address correspondence continues in row-


major order (left to right, then next row down).



The color depends on the number of times the word has been referenced. Black


is 0, blue is 1, green is 2, yellow is 3 and 4, orange is 5 through 9, red is 10 or higher.


View the scale using the tool’s slider control. You can change the color (but not the


reference count) by clicking on the color patch.




4.



Click the tool's


Connect to MIPS


button. This causes the tool to register


as an observer of MIPS memory and thus respond during program execution.



5.



Back in MARS, adjust the


Run Speed slider


to 30 instructions per second.




Page 9


6.



Run the program. Watch the tool animate as it is updated with every


access to MIPS memory.


Feel free to stop the program at any time.




7.



Hopefully you observed that the animation sequence corresponded to the


expected memory access sequence of the program.


If you have


trouble seeing the blue,


reset the tool, move the slider to position 1, change the color


to something brighter, and re-run.



8.



Repeat steps 2 through 7, for



. You should


observe that the animation sequence corresponded to the expected memory access


sequence of this program.



9.



Repeat again for



to observe the animated pattern of


memory references. Adjust the run speed and re-run if necessary.



10.



(Optional)


Create a new instance of the Data Cache Simulator. Move the


two frames around so you can see both. Connect the cache simulator to MIPS and


reset the Memory Reference Visualization. Re-run the program. This exercise


illustrates that two different tools can be used simultaneously.




The Memory Reference Visualization tool could be useful in an operating systems


course to illustrate spatial and temporal locality and memory reference patterns in general.







Page 10


Part 3 : Extending MARS Capabilities




Our session today is not long enough for interactive activities in this area, but we’ll


provide you with enough detail that you can pursue them on your own if you desire.





Abstract



MARS can be customized and extended in four different ways: (1) writing new


MARS Tools, (2) writing new MIPS system calls, (3) writing new MIPS pseudo-


instructions, and (4) writing new MIPS basic instructions. Techniques for all four are


described here.





You have the ability to extend and customize certain MARS capabilities to make it


more useful in your courses. This document describes four different techniques for


extending MARS capabilities:



1.



Ability to write MARS Tools for inclusion in the Tools menu and stand-


alone use.



2.



Ability to define and add new system calls for subsequent use by MIPS


programs.



3.



Ability to customize the instruction set by adding, removing or modifying


pseudo (macro) instruction specifications.



4.



Ability to customize the basic instruction set by adding, removing or


modifying basic instruction specifications.



These procedures apply to MARS 3.2.1, released January 2007. Some may be


streamlined in future releases.



The ability to define and plug in new MARS Tools will be used to develop new


learning aids for students in a variety of computer science courses and provide micro-


worlds for assembly language students to target in their projects. Through those tools it


is possible to deeply engage students in both settings.



The ability to modify the set of system calls, basic instructions, and pseudo-


instructions can be used to define a complete instruction set for an alternative RISC


architecture. MARS was not designed with this in mind however, so support is uneven.


For example, instruction syntax analysis and code generation is driven by the example


and template provided with each instruction, whereas lexical analysis such as the


recognition of register names is embedded in program logic and cannot easily be




Page 11


modified. A customized instruction set has to use MIPS conventions for labeling,


register naming, and so forth. Hopefully MARS can be refactored in future releases to


facilitate its use for alternative instruction sets.




Page 12

-


-


-


-


-


-


-


-



本文更新与2021-02-06 10:57,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/607616.html

MARS使用手册的相关文章