美文网首页
讲解:program、C/C++、Java,PythonHask

讲解:program、C/C++、Java,PythonHask

作者: vn07227 | 来源:发表于2020-01-13 23:46 被阅读0次

Hmk5: Running target codeMacau University of Science and Technology2019 FAllPurposeWe will write a program that works as a virtual machine that can process a sequence of instructionsof P-code. Instructions of P-code have been introduced in class, which are based on a stack. Theabove picture is found from the internet,PreparationThe file p-code.pdf lists the instructions of P-code.The P-code MachineThe runtime environment of a P-code virtual machine (PVM) has 5 parts.Code area: It is an array of P--code instructions.PC: A special place in memory, which records the address of the next instruction to be executed.By default, PC = PC + 1, after the current instruction is executed. A special case is a jumpinginstruction: when the current is a jump instruction to some label, and the corresponding labeledinstruction is at address j, then PC will be changed to j.Data area: It is an array. Each slot in the array is dedicated to a name (variable or label), in theslot is the value of the name. For a variable, its value is an integer (assume ). For a label, its valueis an address (index in the code area).Symbol table: It is a data structure that supports the following operations:lookup(x) : Given a name (a string) return its address in the data area. If x does not exists,some special signal is returned. The names include variable names and label names.insert(x) : Allocate a new slot in the data area for the value of the name x (x is notinitialized at the moment). A simple way is that the address of the next available slot of thedata area is reserved for x, and the address of x should be registered in the symbol table sothat x can be looked up later.When should insert(x) be called?When a name x is used by an instruction (lod or lda), if x is new (lookup(x) cannot find it), x isinserted into the symbol table. When a label instruction is executed, the label should beinserted into the data area, and its address should be registered in the symbol table.stack: A stack is needed by the P-code instructiprogram留学生作业代做、C/C++编程语言作业代写、代做Java,Python实验作业 帮做Haskell程序|代ons. It is an array of integer.A stack remembers:the stack top, which is an index in the array, it is the address where the latest data item issaved. Data are added or removed from the stack at the top. Initially, when the stack isempty, the top could be a special value like -1.The stack supports 2 operations:pop() : When the stack is not empty, return the data (integer) at the top, and top = top 1.When the stack is empty, nothing is popped, and some error message is printed out.push(c) : When the stack is not full, top = top + 1, and c is saved at the top in the dataarea. When the stack is already full, nothing is pushed, and some error message is printed.Behavior of the PVM.Given a P-code program. The PVM executable file should open the program and executes theinstructions one by one. The output of of the wri instruction should be be printed on the screen. A−P--code program will stop when there is no more instruction to run, or the halting instruction ( stp ) isexecuted.How to submitSubmit before Monday, January 6, 2020.Attach all of your source code file. If you created some P-code files ( .p files) for testing, alsoattached them. Please use a file readme.txt to describe your work, like the achievements andproblems of your work, and how to compile and run your codeAt most three students can form a group to do the homework together and submit the homeworktogether with an email. If you can do the homework by yourself (a one-person group), it surelywill be fine.Submit the homework by sending an email (to must_learn_c@126.com ) with attached programfiles (together with the file of the grammar rules). The details of how to submit your homework isin the file how_to_submit_homeworks.pdf .References1. Kenneth C. Louden. Compiler Construction Principles and Practice. PWS Publishing Company,1997. ISBN 0-534-93972-4 http://www.cs.sjsu.edu/~louden/cmptext/.2. Andrew W. Appel. Modern Compiler Implementation in C: Basic Techniques. CambridgeUniversity Press, New York, NY, USA, 1997.转自:http://www.6daixie.com/contents/9/4775.html

相关文章

网友评论

      本文标题:讲解:program、C/C++、Java,PythonHask

      本文链接:https://www.haomeiwen.com/subject/txhoactx.html