EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
Java代做
您的位置: 主页 > 编程案例 > Java代做 >
代做Java:家庭作业课后two编译原理Fundamentals of Compiling CS留学生代写JAVA实现 - Java代做
发布时间:2021-07-25 10:23:25浏览次数:
Lab #1 Writing an Assembler Due Date: 2 March 2018How to Write a Two-Pass AssemblerAll of you are familiar with writing programs in one or more assembly languages. But you may not have really considered how an assembler works when it translates an assembly language program into machine code. These are the functions that the assembler must perform when translating:·Replace symbolic addresses with numeric addresses·Replace symbolic operation codes with machine opcodes·Reserve storage for instructions and data·Translate constants into machine representation.The assignment of numeric address can be performed without foreknowledge of what actual locations will be occupied by the assembled program. It is necessary only to generate addresses relative to the start of the code or data segment. Thus, we assume that we have separate data and code segments and that our assembler normally generates address starting a 0. To illustrate, consider the following assembly code which is equivalent to the following pseudocode:IF flag THEN answer := alpha + 2 * gamma / (C3P0 R2D2) ENDIF PRINT answer1 Section .data2 flag: word3 answer: word4 alpha: word5 gamma: word6 C3PO: word7 R2D2: word8 Section .code9 RVALUE flag10 GOFALSE L011 LVALUE answer 12 RVALUE alpha13 PUSH 214 RVALUE gamma15 MPY16 RVALUE C3P017 RVALUE R2D218 SUB19 DIV20 ADD21 :=22 LABEL L023 RVALUE answer24 PRINT 25 HALTIn translating line 9 of our example program, the resulting machine instruction would be assigned to address 0 of our code segment and occupy 4 bytes, if all machine instructions are 4 bytes (32 bits) long. Hence the instruction corresponding to line 10 would be assigned address 4. Similarly, the variable with the label flagwould be at address 0 of our data segment, and occupy 4 bytes, if words are 32 bit entities. Implementation Issues:The assembler uses a counter to keep track of machine-language addresses. Because these addresses will ultimately specify locations in main stores, the counter is called the location counter. (“Address counter” would be a more accurate term.) Before assembling each section, the location counter is initialized to zero. After each source lien has been examined on the first pass, the location counter is incremented by the length of the machine-language code that will ultimately be generated to correspond to that source line. When a label definition is found, the assembler places both the label and its address (as determined by the value of the location counter) in a symbol table. Creation of the symbol table requires one pass over the source text. During a second pass, the assembler uses the address collected in the symbol table to perform the translation. As each symbolic address is encountered in the second pass, the corresponding numeric address is substituted for it in the object code. Two types of logical errors can occur due to improper use of symbols. If a symbol appears in the operand field of some instruction, but nowhere in a label field, it is undefined. If a symbol appears in the labelfields of more than one instruction, it is multiply-defined. The former error will be detected on the second pass, whereas the latter will be found on the first pass. For an assembler, the symbol table structure is usually rather simple. It simply contains the symbolic labels, the appropriate address, and some simply type information (data or code, # data bits, etc.) Assignment:Your task is write an assembler for a hypothetical stack machine operating on 32 bit integers with the following instructions:PUSH v push v(an integer constant) on the stackRVALUE l push the contents of variable lLVALUE l push the address of the variable lPOP throw away the top value on the stackSTO the rvalue on top of the stack is place in the lvalue below it and both are poppedCOPY push a copy of the top value on the stackADD pop the top two values off the stack, add them, and push the resultSUB pop the top two values off the stack, subtract them, and push the resultMPY pop the top two values off the stack, multiply them, and push the resultDIV pop the top two values off the stack, divide them, and push the resultMOD pop the top two values off the stack, compute the modulus, and push the resultNEG pop the top value off the stack, negate it, and push the resultNOT pop the top value off the stack, invert all the bits, and push the resultOR pop the top two values off the stack, compute the logical OR, and push the resultAND pop the top two values off the stack, compute the logical AND, and push the resultEQ pop the top two values off the stack, compare them, and push a 1 if they are equal, and a 0 if they are not NE pop the top two values off the stack, compare them, and push a 1 if they are not equal, and a 0 if they are equalGT pop the top two values off the stack, compare them, and push a 1 if the first operand is greater than the second, and a 0 if it is not GE pop the top two values off the stack, compare them, and push a 1 if the first operand is greater than or equal to the second, and a 0 if it is not LT pop the top two values off the stack, compare them, and push a 1 if the first operand is less than the second, and a 0 if it is not LE pop the top two values off the stack, compare them, and push a 1 if the first operand is less than or equal to the second, and a 0 if it is not LABEL n serves as the target of jumps to n; has no other effectGOTO n the next instruction is taken from statement with label nGOFALSE n pop the top value; jump if it is zeroGOTRUE n pop the top value; jump if it is nonzeroPRINT pop the top value off the stack and display it as a base 10 integerREAD read a base 10 integer from the keyboard and push its value on the stackGOSUB l push the current value of the program counter on the call stack and transfer control to the statement with label lRET pop the top value off the call stack and store it in the program counterHALT stop executionFor two operand instructions, the operand on top of the stack is the second operand, and the one immediately below it is the first operandThe numeric opcodes are as follows: HALT 0PUSH 1RVALUE 2LVALUE 3POP 4STO 5COPY 6ADD 7SUB 8MPY 9DIV 10MOD 11NEG 12NOT 13OR 14AND 15EQ 16NE 17GT 18GE 19LT 20LE 21LABEL 22GOTO 23GOFALSE 24GOTRUE 25PRINT 26READ 27GOSUB 28RET 29 Write an assembler with the following specifications:All instructions for this machine are 32 bits (4 bytes) long, with the following format: Bits 32-21 are ignored (in practice, filled with zeros,) bits 20-16 hold the opcode, and bits 15-0 hold the operand. (If there is no operand, those bits are filled with zeroes, but otherwise ignored.) Your assembler should produce a binary file which is a set of machine instructions in Big-Endian format. We will use the Harvard memory model, with two separate 256KB (65,536 32-bit words) for instructions and data, and you will have two location counters (one for code, and one for data) rather than one. This also means that, any label with a numeric value greater than 65535 would be an error, although a highly unlikely one to encounter in a debugged assembler. To keep things simple, we will assume that the memory is word-addressable rather than byte-addressable. Thus, the symbol table would conceptually look like:

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。