Write a P-Code Assembler. Program Files: File Description pasm.cpp. Project:
|
|
- Dustin Jennings
- 5 years ago
- Views:
Transcription
1 Data Structures CS 3613 Project p06 P-Code Assembler Project: Write a P-Code Assembler. Program Files: File Description pasm.cpp File pasm.cpp contains functions that process command line arguments and parse a P-Code source program. The P-Code source file name has a.pcd suffix. An example of a P- Code source file is in the class directory ~tt/cs3613/lprime.pcd. pasmparse.h File pasmparse.h defines class pasmparse. Member functions and data can be use to parse a P-Code source program. pasmparse.cpp pasmhash.h pasmhash.cpp pasmconstant.h File pasmparse.cpp implements member functions of class pasmparse. File pasmhash.h defines class pasmhash. Class pasmhash is used to recognize and translate P-Code instruction mnemonics, standard function mnemonics, and single characters specifying P-Code types on certain instructions. File pasmhash.cpp implements member functions of class pasmhash. File pasmconstant.h defines template class pasmconstant. Class pasmconstant is used to store and manage P-Code constants. pasmconstant.cpp File pasmconstant.cpp implements member functions of class pasmconstant. pasmpcode.h File pasmpcode.h defines class pasmpcode. Class pasmpcode.cpp pasmlabel.h pasmlabel.cpp pasmmachine.h pasmmachine.cpp pasm*.h pasm*.cpp pasmpcode is used to store and manage P-Code instructions. File pasmpcode.cpp implements member functions of class pasmpcode. File pasmlabel.h defines class pasmlabel. Class pasmlabel is used to define, reference and resolve labels. File pasmlabel.cpp implements member functions of class pasmlabel. File pasmmachine.h defines class pasmmachine. Class pasmmachine is used to convert P-Machine codes to corresponding mnemonic strings. File pasmmachine.h can be found in the class directory ~tt/cs3613/pasmmachine.h. File pasmmachine.cpp implements member functions of class pasmmachine. File pasmmachine.cpp can be found in the class directory ~tt/cs3613/pasmmachine.cpp. All files containing class definitions must have the prefix pasm and the suffix.h. All files containing member function implementations must have the prefix pasm suffix.cpp. makepasm File makepasm contains instructions for compiling and linking the P-Code assembler whose source files are listed above. File makepasm directs UNIX utility make to create executable file pasm. File makepasm is available for your use in the class directory ~tt/cs3613/makepasm. 1
2 Data Structures CS 3613 Project p06 P-Code Assembler Command Line: Project 6 can be invoked with zero or one program parameters. The first program parameter is the name of the P-Code source file to be assembled. A P-Code source file is illustrated in Figure 1. Sample command lines together with corresponding actions by program pasm are shown below. Boldfaced type indicates data entered at the keyboard by the user. $ pasm Enter the P-Code source file name. lprime.pcd The P-Machine executable file is lprime.pex. The P-Machine listing file is lprime.lst. Input File: P-Machine Executable File: P-Machine Listing File: $ pasm lprime.pcd The P-Machine executable file is lprime.pex. The P-Machine listing file is lprime.lst. The input file is a P-Code source file. P-Code source files are described in the P- Code Source File Specification. File lprime.pcd, shown in Figure 1., is an example of a P-Code source program. File lprime.pcd can be found in the class directory ~tt/cs3613/lprime.pcd. Program pasm produces a P-Machine Executable File. P-Machine Executable files are specified in the P-Machine Executable File Specification. A P-Machine Executable File is a binary file that contains a directory, constants, and P-Code Instructions. P-Machine Executable files cannot be viewed using a text editor. Program pasm produces a formatted listing of the P-Machine Executable File. The listing contains the P-Machine directory, constant tables, P-Code instruction array and a summary of the labels found in the P-Code Source File. The label summary lists each label, the value assigned to the label and the addresses of instructions that reference the label. An example of a formatted listing can be found in the class directory ~tt/cs3613/lprime.lst. 2
3 n L000 ent sp L001 ent ep L002 lda 0 6 lvi 0 5 flt csp sqt trc ldc i 1 adi lda 0 7 ldc i 3 L003 lvi 0 7 lvi 0 6 equ i fjp L004 lvi 0 5 lvi 0 7 mod ldc i 0 neq i fjp L004 lda 0 7 lvi 0 7 ldc i 2 adi ujp L003 L004 lda 0 0 lvi 0 7 lvi 0 6 grt i sti b rtn b #define L001 7 #define L002 3 L005 ent sp L006 ent ep L007 lda 0 5 ldc i 1 ldc i 6 ldc i 2 ldc i 5 csp wri lda 0 6 ldc i 3 L008 lvi 0 5 ldc i 100 les i fjp mst 0 lvi 0 6 L009 cup 1 L000 fjp L010 3
4 n lda 0 5 lvi 0 5 ldc i 1 adi ldc i 6 lvi 0 6 ldc i 5 csp wri lvi 0 5 ldc i 10 mod ldc i 0 equ i fjp L010 ldc i 6 csp wln L010 lda 0 6 lvi 0 6 ldc i 2 adi ujp L008 L009 rtn p #define L006 6 #define L007 6 mst 0 cup 0 L005 stp 4
5 Data Structures COMSC 3613 Project p06 File lprime.lst P-Code assembler; Revision 3; Mnemonic translation, constants, labels Instruction Label Mnemonic Operand 1 Operand 2 Address (opcode) (value) (value) 0 L000 0 ent(02) sp(00) L001(-**-) 1 ent(02) ep(01) L002(-**-) 2 lda(29) 0(00) 6(0006) 3 lvi(2f) 0(00) 5(0005) 4 flt(25) 5 csp(01) sqt(000e) 6 trc(27) 7 ldc(2a) i(04) 1(0000) 8 adi(0b) 9 sti(32) i(04) 10 lda(29) 0(00) 7(0007) 11 ldc(2a) i(04) 3(0001) 12 sti(32) i(04) 13 L lvi(2f) 0(00) 7(0007) 14 lvi(2f) 0(00) 6(0006) 15 equ(05) i(04) 16 fjp(23) L004(-**-) 17 lvi(2f) 0(00) 5(0005) 18 lvi(2f) 0(00) 7(0007) 19 mod(10) 20 ldc(2a) i(04) 0(0002) 21 neq(06) i(04) 22 fjp(23) L004(-**-) 23 lda(29) 0(00) 7(0007) 24 lvi(2f) 0(00) 7(0007) 25 ldc(2a) i(04) 2(0003) 26 adi(0b) 27 sti(32) i(04) 28 ujp(21) L003(000d) 29 L lda(29) 0(00) 0(0000) 30 lvi(2f) 0(00) 7(0007) 31 lvi(2f) 0(00) 6(0006) 32 grt(07) i(04) 33 sti(32) b(02) 34 rtn(04) b(02) Instruction Label Mnemonic Operand 1 Operand 2 Address (opcode) (value) (value) 35 #define L #define L L ent(02) sp(00) L006(-**-) 36 ent(02) ep(01) L007(-**-) 37 lda(29) 0(00) 5(0005) 38 ldc(2a) i(04) 1(0000) 39 sti(32) i(04) 40 ldc(2a) i(04) 6(0004) 41 ldc(2a) i(04) 2(0003) 42 ldc(2a) i(04) 5(0005) 5
6 Data Structures COMSC 3613 Project p06 File lprime.lst 43 csp(01) wri(0009) 44 lda(29) 0(00) 6(0006) 45 ldc(2a) i(04) 3(0001) 46 sti(32) i(04) 47 L lvi(2f) 0(00) 5(0005) 48 ldc(2a) i(04) 100(0006) 49 les(09) i(04) 50 fjp(23) L009(-**-) 51 mst(03) 0(00) 52 lvi(2f) 0(00) 6(0006) 53 cup(00) 1(01) L000(0000) 54 fjp(23) L010(-**-) 55 lda(29) 0(00) 5(0005) 56 lvi(2f) 0(00) 5(0005) 57 ldc(2a) i(04) 1(0000) 58 adi(0b) 59 sti(32) i(04) 60 ldc(2a) i(04) 6(0004) 61 lvi(2f) 0(00) 6(0006) 62 ldc(2a) i(04) 5(0005) 63 csp(01) wri(0009) 64 lvi(2f) 0(00) 5(0005) 65 ldc(2a) i(04) 10(0007) 66 mod(10) 67 ldc(2a) i(04) 0(0002) 68 equ(05) i(04) 69 fjp(23) L010(-**-) 70 ldc(2a) i(04) 6(0004) 71 csp(01) wln(000d) 72 L lda(29) 0(00) 6(0006) 73 lvi(2f) 0(00) 6(0006) 74 ldc(2a) i(04) 2(0003) 75 adi(0b) 76 sti(32) i(04) 77 ujp(21) L008(002f) 78 L rtn(04) p(00) Instruction Label Mnemonic Operand 1 Operand 2 Address (opcode) (value) (value) 79 #define L #define L mst(03) 0(00) 80 cup(00) 0(00) L005(0023) 81 stp(28) 82 Label Table Label Address Resolved References L000 0 yes 53 L001 7 yes 0 L002 3 yes 1 L yes 28 L yes
7 Data Structures COMSC 3613 Project p06 File lprime.lst L yes 80 L006 6 yes 35 L007 6 yes 36 L yes 77 L yes 50 L yes P-Machine Program File Directory pcstart = 79 ldstore = 1024 oistore = 80 listore = 328 oicon = 48 licon = 32 orcon = 48 lrcon = 0 oscon = 48 lscon = 0 otcon = 48 ltcon = 0 Real Constants Index Constant Integer Constants Index Constant P-Code Instruction Array Instruction Opcode Operand 1 Operand 2 Address Mnemonic 0 ent sp 7 1 ent ep 3 2 lda lvi flt 5 csp sqt 6 trc 7 ldc i 1 8 adi 9 10 lda ldc i lvi lvi equ i 16 fjp 29 7
8 Data Structures COMSC 3613 Project p06 File lprime.lst 17 lvi lvi mod 20 ldc i 0 21 neq i 22 fjp lda lvi ldc i 2 26 adi ujp lda lvi lvi grt i 33 sti b 34 rtn b Instruction Opcode Operand 1 Operand 2 Address Mnemonic 35 ent sp 6 36 ent ep 6 37 lda ldc i ldc i 6 41 ldc i 2 42 ldc i 5 43 csp wri 44 lda ldc i lvi ldc i les i 50 fjp mst 0 52 lvi cup fjp lda lvi ldc i 1 58 adi ldc i 6 61 lvi ldc i 5 63 csp wri 64 lvi ldc i mod 67 ldc i 0 68 equ i 69 fjp ldc i 6 8
9 Data Structures COMSC 3613 Project p06 File lprime.lst 71 csp wln 72 lda lvi ldc i 2 75 adi ujp rtn p 79 mst 0 80 cup stp 9
10 COMSC 3613 Project 6 Data Structures P-Code Source File Specification P-Code source files contain the following. 1. P-Code instructions that can be optionally preceded by a label. 2. P-Code assembler directives that define the value of a label. A P-Code instruction consists of an instruction mnemonic and up to two operands depending on the instruction. Examples of the four types of instructions are given below. 1. The add integer instruction (adi) has no operands. All strings appearing in a P-Code source program are separated by one or more blank spaces. An example P-Code source program appears on the following page. The P-Code source program is presented in two columns. P-Code source in the second column follows the first column. Label Opcode Operand 1 Operand 2 adi 2. The equality comparison instruction (equ) has only operand 1. Label Opcode Operand 1 Operand 2 equ i 3. The false jump instruction (fjp) has only operand 2. Label Opcode Operand 1 Operand 2 fjp L The load address instruction (lda) has both operand 1 and 2. Label Opcode Operand 1 Operand 2 lda 0 5 P-Code instructions can be labeled. The label is a symbol for the address of that instruction. In the example below, label L005 is a symbol for the address of the equality comparison instruction. Labels always begin with the capital letter L. Subsequent characters are digits forming a unique integer value. Label Opcode Operand 1 Operand 2 L005 equ i A directive defining a label is shown below. Directive Label Value #define L Directives begin with the reserve word #define. The label is next followed by an integer value. In the example, label L001 is assigned the integer value
11 Data Structures COMSC 3613 L000 ent sp L001 ent ep L002 lda 0 6 lvi 0 5 flt csp sqt trc ldc i 1 adi lda 0 7 ldc i 3 L003 lvi 0 7 lvi 0 6 equ i fjp L004 lvi 0 5 lvi 0 7 mod ldc i 0 neq i fjp L004 lda 0 7 lvi 0 7 ldc i 2 adi ujp L003 L004 lda 0 0 lvi 0 7 lvi 0 6 grt i sti b rtn b #define L001 7 #define L002 3 L005 ent sp L006 ent ep L007 lda 0 5 ldc i 1 ldc i 6 ldc i 2 ldc i 5 csp wri lda 0 6 ldc i 3 L007 lvi 0 5 ldc i 100 les i fjp L008 mst 0 lvi 0 6 Project p06 P-Code Source File Specification cup 1 L000 fjp L009 lda 0 5 lvi 0 5 ldc i 1 adi ldc i 6 lvi 0 6 ldc i 5 csp wri lvi 0 5 ldc i 10 mod ldc i 0 equ i fjp L009 ldc i 6 csp wln L009 lda 0 6 lvi 0 6 ldc i 2 adi ujp L007 L008 rtn p #define L006 6 #define L007 6 mst 0 cup 0 L005 stp 11
12 Data Structures Project 6 COMSC 3613 P-Machine Executable File Specification P-Machine Executable File Specification A P-Machine accepts a file containing a directory, constants, and an array of P-Code instructions as shown in Figure 1. directory constants index of first instruction stack size p-code instruction array offset p-code instruction array length integer constants offset integer constants length real constants offset real constants length set constants offset set constants length string constants offset string constants length string constants set constants real constants integer constants p-code instruction array Figure 1. Anatomy of a P-Machine Executable File The directory is placed at the beginning of the file. Constants are placed after the directory and the P-Code instruction array comes directly after the constants. 1. Directory The P-Machine program directory has fields containing the offsets to components of the program. Offsets are relative to the start of the file and are given in bytes. The size of the directory is equal to the size of twelve integers. On an IBM RISC 6000 computer, the size of an integer is four bytes making the size of the directory 48 bytes. On many IBM-compatible personal computers, the size of an integer is two bytes and the size of the directory is 24 bytes Index of first instruction The index of the first instruction marks the first P-Code instruction to execute. The index of the first instruction designates the beginning of the P-Machine program whose instructions are in the P-Code instruction array Stack size The stack size is the size of stack allocated for the P-Machine program P-Code instruction array offset The P-Code instruction array offset is the number of bytes from the beginning of the file to the first byte of the P-Code instruction array P-Code instruction array length The length of the P-Code instruction array is the number of bytes occupied by that array Integer constants offset Integer constants are an array of integers. The offset to integer constants is the number of bytes from the beginning of the file to the first byte of integer constants Integer constants length The length of integer constants is the number of bytes occupied by the array of integer constants Real constants offset Real constants are an array of real numbers. The offset to real constants is the number of bytes from the beginning of the file to the first byte of real constants Real constants length The length of real constants is the number of bytes occupied by the array of real numbers Set constants offset A set is an array of eight bytes. Each bit in the set represents an element of a set. There can be at most 64 elements in a set. Set constants are an array of sets. The offset to set constants is the number of bytes from the beginning of the file to the first byte of set constants Set constants length The length of set constants is the number of bytes occupied by the array of sets String constants offset A string is a sequence of characters terminated by the character whose integer value is zero. P- Machine strings are identical to those defined in the C programming language. String constants are packed into an array of characters. The offset to string constants is the 12
13 Data Structures Project 6 COMSC 3613 P-Machine Executable File Specification number of bytes from the beginning of the file to the first character of the first string constant String constants length The length of string constants is the number of bytes occupied by all the string constants. 2. String constants String constants are stored in an array. String constants vary in size. P-Machine strings have the same form as C-programming language strings. Strings consist of a sequence of characters terminated by a character whose ordinal value is zero. P-Machine instructions reference string constants by using the index of the first character of the string. Two strings are shown in Figure 2. The string "candy" is followed by the string "is." Together, both strings require nine (9) characters including their terminators bits 1 byte c a n d y 0 i s 0 string constants length Figure 2. Anatomy of string constants 3. Set constants Set constants are stored in an array. Each set occupies 64 bits. The number of sets, n s, is given by n s =l s /8, where l s is the value of the field labeled "set constants length" in the directory. index 0 1 ns-1 64 bits 8 bytes Figure 3. Anatomy of set constants ls set constants length 4. Real constants Real constants are stored in an array. Each real number occupies 64 bits. The number of real constants, n r, is given by, n r =l r /8, where l r is the value of the field labeled "real constants length" in directory. Real constants are stored in IEEE 754 binary double format. index 0 1 nr-1 64 bits 8 bytes Figure 4. Anatomy of real constants lr real constants length 5. Integer constants Integer constants are stored in an array. An integer occupies four bytes (32 bits) on IBM RISC 6000 computers. An integer occupies two bytes on many IBM-compatible personal computers. The number of integers, n is given l i by ni = li I where is the value stored in the directory in the field labeled "integer constants length" and I is the number of bytes occupied by an integer. i 13
14 Data Structures Project 6 COMSC 3613 P-Machine Executable File Specification index I bytes 0 1 li integer constants length ni-1 Figure 5. Anatomy of integer constants 6. P-Code instruction array P-Code instructions are stored in an array. Each P-Code instruction occupies 4 bytes (32 bits). The number of P-Code instructions, n p, is given by, n p =l p /4, where l p is the value of the field labeled "P-Code instructions array length" in the directory. index 0 1 np-1 4 bytes (32 bits) opcode operand 1 operand 2 lp P-Code Instruction Array Length Figure 6. Anatomy of the P-Code instruction array P-Code instructions consist of three fields, an operation code (opcode) followed by two operands. Operands depend on the opcode. P-Code instructions occupy 32 bits or 4 bytes. The opcode is stored in the first byte of the instruction. The first operand is stored in the second byte and the third operand occupies the remaining two bytes as shown in Figure opcode operand 1 operand Figure 7. Anatomy of a P-Code instruction The opcode and both operands are unsigned integers. 14
15 COMSC 3613 Project 6 CS3613 P-Machine Specification 1. Introduction The P-Machine is a virtual machine usually implemented using an interpreter. The difference between the P-Machine and most other computer architectures is the P-Machine relies heavily on a stack. The P- Machine also supports additional data types not ordinarily available on conventional computers. The P-Machine defines storage for registers, data, and instructions as shown in Figure 1. Registers, data, and instructions are discussed in succeeding sections. rstore Register Store PC: Program Counter SP: Stack Pointer MP: Mark Pointer NP: New Pointer EP: Extreme Pointer dstore Data Store constants heap stack istore Instruction Store opcode operand 1 operand 2 Figure 1. P-Machine Memory 15
16 COMSC 3613 Project 6 CS3613 P-Machine Specification 2. Registers The P-Machine has five registers: they are: 1. PC, the program counter 2. SP, the stack pointer 3. MP, the mark pointer 4. NP, the new pointer 5. EP, the extreme stack pointer 2.1. Program Counter Register (PC) The program counter register contains the index of the current instruction being executed. Instructions are stored in array istore. Each element of the array occupies 32 bits and contains three fields, an operation code and two operands. The format of P-Machine instructions is shown in Figure 2. P-Machine programs are limited to instructions. Instructions are stored in array istore starting with element zero. The program counter is a 32-bit integer opcode operand 1 operand Figure 2. P-Code Instruction Format 2.2. Stack Pointer (SP) The stack pointer register contains the index of the element on top of the stack. Note that the stack is entirely contained in the data store. The data store is entirely composed of elements, each occupying eight (8) bytes. The stack pointer is an index of array dstore. dstore Data Store heap unallocated stack frame stack frame stack frame NP SP Figure 3. Anatomy of the Data Store The anatomy of the data store is shown in Figure 3. The stack and heap grow toward each other as a P- Code program executes. Each time a procedure or function is called, another stack frame is allocated on the stack. As procedures and functions return to their callers, stack frames are removed from the stack. The stack pointer marks the maximum extent of the stack. The stack pointer register is a 32-bit integer New Pointer (NP) The new pointer register marks the maximum extent of the heap. The new pointer register is an index of array dstore. Each time standard function new is called, storage for data referenced by the pointer returned by function new is allocated from the heap and the new pointer is moved toward the stack. 16
17 COMSC 3613 Project 6 CS3613 P-Machine Specification If the value of the stack pointer exceeds that of the new pointer the stack and heap have collided. This situation is an error and the P-Machine terminates the P-Code program Mark Pointer (MP) The mark pointer register marks the beginning of a stack frame and it, too, contains an index of array dstore. The anatomy of a stack frame is shown in Figure 4. A stack frame is divided into sections, the mark, parameters, locals, and computation stack. The mark pointer register contains the index of the return value in the stack mark. The mark pointer register is a 32-bit integer. computation stack locals (if present) EP SP parameters (if present) return address (ra) old extreme pointer (ep) dynamic link (dl) static link (sl) return value (rv) Figure 4. Anatomy of a Stack Frame stack mark 2.5. Extreme Pointer (EP) The extreme pointer register marks maximum extent of the frame. The value of the extreme pointer relative to the mark pointer is the size of the stack mark, parameters, local variables, and largest computation stack. The stack will not grow beyond the value stored in the extreme pointer during the execution of a function or procedure. 3. Stack Frame The anatomy of a stack frame is shown in Figure 4. A stack frame is allocated each time a procedure or function is called and removed when the subprogram returns. Each region of the frame is discussed below Return Value (rv) The return value is storage reserved for the return value of a function: the value returned by a function is stored here. The return value is a single element of array dstore and occupies eight (8) bytes. Eight bytes are sufficient to store any of the P-Machine types Static Link (sl) The static link references the frame on the stack associated with the immediately enclosing procedure or function. For example, if procedure A encloses procedure B, then the static link in the frame for procedure B references the frame for procedure A. The static link is an index into array dstore. The static link occupies a single element of array dstore. MP 17
18 COMSC 3613 Project 6 CS3613 P-Machine Specification program main; var j:integer; procedure p; var i:integer; procedure q; begin if i>0 then begin i:=i-1; j:=j+1; q end end{q}; begin{p} i:=2; q; end{p}; begin{main} j:=0; p end{main}. Figure 5. Program main Consider program main in Figure 5. The diagram in Figure 6 is a snapshot of the stack on the third (recursive) invocation of procedure q. Note the static links from all three invocations of procedure q reference the frame associated with the invocation of procedure p. Procedure p encloses procedure q. Non local references to variable i allocated in procedure p are accessed via the static link in the frame for procedure q. Third invocation procedure q stack frame Second invocation procedure q stack frame First invocation procedure q stack frame procedure p stack frame program main stack frame dynamic links ra ep dl sl rv ra ep dl sl rv ra ep dl sl rv i ra ep dl sl rv j ra ep dl sl rv Figure 6. Static and dynamic links The static link references the frame of the enclosing procedure. Procedure p encloses procedure q and static links in all three invocations of procedure q reference procedure p's frame Dynamic Link (dl) The dynamic link references the caller's frame. For example, if procedure F called procedure G, then the dynamic link in procedure G's frame references the frame of procedure F. The dynamic link is an index of array dstore. The dynamic link occupies a single element of array dstore. Dynamic links illustrated in Figure 6 refer to the calling subprogram. Program main is called by the operating system so its dynamic link is not shown. Only procedures and functions of program main have valid dynamic links. The dynamic link in procedure p's frame refers to program main. The dynamic link in the first invocation of procedure q refers to the frame allocated for procedure p. Procedure p called procedure q. Dynamic links in subsequent invocations of procedure q refer to the frame allocated for the previous invocation of procedure q. Procedure q is recursive: it calls itself. static links 18
19 COMSC 3613 Project 6 CS3613 P-Machine Specification 3.4. Old Extreme Pointer (ep) The old extreme pointer contains the value of the extreme pointer register. The value of the extreme pointer register is saved in the stack mark when a procedure or function is called and restored when the subprogram returns. The old extreme pointer occupies a single element of array dstore Return Address (ra) The return address contains the address of the instruction following the procedure call in the calling procedure. The return address is the next instruction to execute after the subprogram returns. The return address is an index of array istore. The return address occupies a single element of array dstore Parameters Parameters are stored immediately above the stack mark. Parameters are optional. Procedures or functions without parameters require no storage for such. program params; var j:integer; procedure addparams (var i:integer); begin{addparams} i:=i+1 end{addparms}; begin{params} j:=1; addparams(j) end{params}. The first parameter is located five elements from the mark pointer. Parameters having type Boolean, character, integer, real, or set occupy one element in array dstore. Figure 7. Program params iaddr P-Code Operand 1 Operand 2 Comment 0 ent sp 5 Start procedure addparams Allocate storage for parameter i and the stack mark 1 ent ep 3 Reserve 3 elements for the computation stack 2 lva 0 5 Load the value of parameter i: it is an address. Parameter i will be used as the target in the store indirect instruction in element 7 of array iaddr. 3 lva 0 5 Load the value of parameter i, an address, in preparation to obtain the value of variable i. 4 ldi i Load indirect. Obtain the value of variable i 5 ldc i 1 Load an integer constant 1. 6 adi Add the two integers on top of the stack. 7 Assign the sum to the location whose address is in parameter i. Assign the sum to variable j. 8 rtn p Return to the caller 9 ent sp 5 Start program params Allocate storage for variable j and the stack mark 10 ent ep 6 Reserve 6 elements for the computation stack 11 lda 0 5 Load the address of variable j 12 ldc i 1 Load an integer constant Assign the integer constant to variable j. 14 mst 0 Allocate storage for procedure addparams stack mark 15 lda 0 5 Load the address of variable j just above the mark in the parameters section, passing variable j by reference. 16 cup 1 0 Call procedure addparams, having one argument. 17 rtn p Return to the caller 18 mst 0 Execution starts here. Create program params' stack mark. 19 cup 0 9 Call program params 20 stp Stop Figure 8. Annotated P-Code listing of program params 19
20 COMSC 3613 Project 6 CS3613 P-Machine Specification Consider program params in Figure 7 and the annotated P-Code listing of program params in Figure 8. Instructions for procedure addparams occupy elements 0 through 8 of array istore. Code for program main is stored in elements 9 through 17 of array istore. The program prologue, that creates the stack mark for program main, is stored in elements 18 and 19 of array istore. Note that storage for one parameter is allocated by the entry (ent) instruction located in element 0 of array istore. The address of variable j is passed to procedure addparams by the instruction in element 15 of array istore Locals Storage for variables local to the subprogram is allocated above parameters. Temporary variables allocated by the compiler may also be allocated in the local storage section. Procedures or functions without local variables require no storage for locals. Consider program locals in Figure 9 and the corresponding listing of P-Code instructions in Figure 10. Variable i is local to procedure addlocal. Storage for variable i is allocated by the entry (ent) instruction in element 0 of array istore. Instructions stored in elements 0 through 7 implement procedure addlocal. Program locals is stored in elements 8 through 12 of array istore and the program prologue that creates the stack mark for program locals is stored in elements 13 and 14 of array istore. program locals; procedure addlocal; var i:integer; begin{addlocal} i:=i+1 end{addlocal}; begin{locals} addlocal end{locals}. Figure 9. Program locals 3.8. Computation Stack Storage for the computation stack is allocated in this region. The amount of storage required for the most complex computation in the subprogram is computed during compilation and used to determine the number of elements in the computation stack. iaddr P-Code Operand 1 Operand 2 Comment 0 ent sp 5 Start procedure addlocal Allocate storage for variable i and the stack mark 1 ent ep 3 Reserve 3 elements for the computation stack 2 lda 0 5 Load the address of variable i in preparation to store a value. 3 lvi 0 5 Load the value of variable i 4 ldc i 1 Load an integer constant 1. 5 adi Add the two integers on top of the stack. 6 Assign the sum to variable i. 7 rtn p Return to the caller 8 ent sp 4 Start program locals Allocate storage for the stack mark 9 ent ep 5 Reserve 5 elements for the computation stack 10 mst 0 Allocate storage for procedure addlocals' stack mark 11 cup 0 0 Call procedure addlocal. 12 rtn p Return to the caller 13 mst 0 Execution starts here. Create program main's stack mark. 14 cup 0 8 Call program local 15 stp Stop Figure 10. Annotated P-Code listing of program locals The purpose of reserving storage for computation in advance is to improve execution performance. Every time the stack pointer is incremented, it must be checked against the new pointer to prevent a collision. The stack cannot grow into the heap. By reserving the entire storage required for computation in the subprogram prologue, the P-Machine is not required to check the value of the new pointer every time the stack pointer is incremented. The extreme pointer delimits the maximum extent of the computation stack. 20
21 COMSC 3613 Project 6 CS3613 P-Machine Specification 4. P-Machine register codes P-Machine registers are assigned numeric codes in Table 1. Table 1. P-Machine Registers Register Mnemonic Value (Hex) Description sp 00 Stack Pointer ep 01 Extreme Pointer mp 02 Mark Pointer pc 03 Program Counter np 04 New Pointer P-Machine type codes P-Machine types are assigned numeric codes in Table 2. Table 2. P-Machine Types Type Value (Hex) Description p 00 Procedure a 01 Address b 02 Boolean c 03 Character i 04 Integer r 05 Real s 06 Set t 07 String Instruction mnemonic and standard function codes P-Machine instructions are assigned numeric codes in tables 3, 7, 9, 11, 13, 15, 17, 19, and 21. Notes discussing the function of P-Code instructions follow the tables that contain their numeric codes. Standard function codes for the call standard procedure (csp) P-Code instruction are found in table 5. Table 3. Subprogram Linkage P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After cup 00 argsize iaddr empty empty Call User Procedure csp 01 stdfunction function specific Call Standard Procedure ent 02 register amount empty empty Entry mst 03 level empty empty Mark Stack rtn 04 type empty empty Return Table 4. Subprogram Linkage P-Machine Operation Notes Operand Symbol argsize iaddr stdfunction register amount Description argsize specifies the size of the arguments passed to the procedure called. argsize is specified in elements of array dstore. argsize is an unsigned integer in the range 0 to 255. iaddr is the instruction address that marks the first instruction of the procedure called. iaddr is an index of array istore. iaddr is an unsigned integer in the range 0 to stdfunction is the index of a Pascal standard procedure or function. Indexes of standard procedures and functions are given in Table 5. register is an integer value representing one of two registers, the stack pointer (sp) or the extreme pointer (ep). When coded as operand 1 of the entry instruction, sp represents a zero (0) and ep represents a (1). amount is the amount to be added to the value of the mark pointer register and assigned to the register in operand 1 of the entry instruction. 21
22 COMSC 3613 Project 6 CS3613 P-Machine Specification Table 4. Subprogram Linkage P-Machine Operation Notes (continued) Operand Symbol Description level level specifies which stack frame contains variables not local to the current subprogram. level specifies the number of static links to traverse before arriving at that stack frame allocated when the immediately enclosing procedure was called. level is computed by adding one to the level of the calling procedure minus the level of the called procedure. type type is a P-Machine type. P-Machine types are listed in Table 2. Table 5. Standard Functions Mnemonic Opcode Operation on stack Description (hex) Before After rdb 00 (a,f) empty Read Boolean rdc 01 (a,f) empty Read Character rdi 02 (a,f) empty Read Integer rdr 03 (a,f) empty Read Real rln 04 (f) empty Read Line wrb 05 (w,b,f) empty Write Boolean wrc 06 (w,c,f) empty Write Character wri 07 (w,i,f) empty Write Integer wrr 08 (d,w,r,f) empty Write Real wrs 09 (s,f) empty Write Set wrt 0A (t,f) empty Write String wln 09 (f) empty Write Line sqt 0B (r) sqrt(r) Square Root ln 0C (r) ln(r) Natural Logarithm exp 0D (r) exp(r) Exponentiation Table 6. Standard Function Notes Symbol Description (x 1,x 2,x 3,x 4 ) Operands on the stack are enclosed in parentheses and separated by commas. The leftmost operand, x 1, is on top of the stack. Subsequent operands, x 2, x 3, and x 4 are on the stack, under x 1, in the order listed. For example, element x 4 is fourth from the top of the stack. (a,f) Operand a represents the address of a variable and operand f represents the file to be read. For example, standard function rdb reads a Boolean value, true or false, from file f and stores a zero or a one, depending on which value was read, into the Boolean value whose address a, is on top of the stack. (w,b,f) Boolean value b is right justified in a field of width w in file f. (w,c,f) Character value c is right justified in a field of width w in file f. (w,i,f) Integer value i is right justified in a field of width w in file f. (d,w,r,f) Real value r is right justified in a field of width w having d fraction digits in file f. (r) Operand r is a real value on top of the stack sqrt(r) sqrt(r) is the square root of r. 22
23 COMSC 3613 Project 6 CS3613 P-Machine Specification Table 7. Comparison P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After equ 05 type (x 1,x 2 ) b Equality comparison, b:=x 2 =x 1 neq 06 type (x 1,x 2 ) b Inequality comparison, b:=x 2 <>x 1 grt 07 type (x 1,x 2 ) b Greater than comparison, b:=x 2 >x 1 geq 08 type (x 1,x 2 ) b Greater than or equal comparison, b:=x 2 >=x 1 les 09 type (x 1,x 2 ) b Less than comparison, b:=x 2 <x 1 leq 0A type (x 1,x 2 ) b Less than or equal comparison, b:=x 2 <=x 1 Table 8. Comparison P-Machine Operation Notes Operand Symbol Description (x 1,x 2 ) Operand x 1 is on top of the stack and operand x 2 is next to the top of the stack (x 1,x 2 ) Operands x 1 and x 2 are values having the same type. Comparisons compare two values having the same type b The value b is the Boolean result of comparing two values of the same type type type is a P-Machine type. P-Machine types are listed in Table 2. Table 9. Arithmetic P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After adi 0B (i 1,i 2 ) i 3 Integer addition, i 3 :=i 2 +i 1 sbi 0C (i 1,i 2 ) i 3 Integer subtraction, i 3 :=i 2 -i 1 ngi 0D (i 1 ) i 2 Integer sign inversion, i 2 :=-i 1 mpi 0E (i 1,i 2 ) i 3 Integer multiplication, i 3 :=i 2 *i 1 dvi 0F (i 1,i 2 ) i 3 Integer division, i 3 :=i 2 div i 1 mod 10 (i 1,i 2 ) i 3 Modulo, i 3 :=i 2 mod i 1 abi 11 (i 1 ) i 2 Integer absolute value, i 2 := i 1 adr 12 (r 1,r 2 ) r 3 Real addition, r 3 :=r 2 +r 1 sbr 13 (r 1,r 2 ) r 3 Real subtraction, r 3 :=r 2 -r 1 ngr 14 (r 1 ) r 2 Real sign inversion, r 2 :=-r 1 mpr 15 (r 1,r 2 ) r 3 Real multiplication, r 3 :=r 2 *r 1 dvr 16 (r 1,r 2 ) r 3 Real division, r 3 :=r 2 /r 1 abr 17 (r 1 ) r 2 Real absolute value, r 2 := r 1 Table 10. Arithmetic P-Machine Operation Notes Operand Symbol Description (i 1,i 2 ) i 1 is on top of the stack and i 2 is next to the top of the stack (r 1,r 2 ) r 1 is on top of the stack and r 2 is next to the top of the stack i 1, i 2, i 3 i 1, i 2, and i 3 are integers. r 1, r 2, r 3 r 1, r 2, and r 3 are real numbers. 23
24 COMSC 3613 Project 6 CS3613 P-Machine Specification Table 11. Boolean P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After ior 18 (b 1,b 2 ) b 3 Inclusive OR, b 3 :=b 2 b 1 and 19 (b 1,b 2 ) b 3 AND, b 3 :=b 2 b 1 xor 1A (b 1,b 2 ) b 3 Exclusive OR, b 3 :=b 2 b 1 not 1B (b 1 ) b 2 Complement, b 2 :=not b 1 Table 12. Boolean P-Machine Operation Notes Operand Symbol Descriptions (b 1,b 2 ) b 1 is on top of the stack and b 2 is next to the top of the stack b 1, b 2, b 3 b 1, b 2, and b 3 are Boolean values. Table 13. Set P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After inn 1C (s,i) b Set membership, b:=i s uni 1D (s 1,s 2 ) s 3 Set union, s 3 :=s 2 s 1 int 1E (s 1,s 2 ) s 3 Set intersection, s 3 :=s 2 s 1 dif 1F (s 1,s 2 ) s 3 Set difference, s 3 :=s 2 not s 1 cmp 20 (s 1 ) s 2 Complement, s 2 :=not s 1 Table 14. Set P-Machine Operation Notes Operand Symbol (s,i) Description s is a bit-vector representing a set of 64 elements numbered 0 to 63 from most significant bit to least significant bit. i is an integer value between 0 and 63. If the ith bit is set, Boolean value b is assigned true, otherwise it is assigned false. (s 1,s 2 ) s 1 is on top of the stack and s 2 is next to the top of the stack s 1, s 2, s 3 s 1, s 2, and s 3 are sets having a maximum of 64 elements. Table 15. Jump P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After ujp 21 iaddr empty empty Unconditional jump xjp 22 iaddr (i) empty Indexed jump fjp 23 iaddr (b) empty False jump tjp 24 iaddr (b) empty True jump Table 16. Jump P-Machine Operation Notes Operand Symbol Description iaddr iaddr is an instruction address in the range 0 to (i) i is an integer offset from iaddr. The indexed jump instruction is used to implement case statements b b is a Boolean value Table 17. Conversion P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After flt 25 (i) r Float top of stack flo 26 (x,i) (x,r) Float next to top of stack trc 27 (r) i Truncate Table 18. Conversion P-Machine Operation Notes Operand Symbol i r (x,i) Description i is an integer value r is a real value x is a value of any type on top of the stack and i is an integer value next to the top of stack. 24
25 COMSC 3613 Project 6 CS3613 P-Machine Specification Table 19. Program Termination P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After stp 28 empty empty Stop Table 20. Program Termination P-Machine Operation Notes Operand Symbol Description stp stp is always the last instruction in a P-Machine Program Table 21. Data Reference P-Machine Operations Mnemonic P-Code Operand 1 Operand 2 Operation on stack Description (hex) Before After lda 29 level offset empty a Load address of data ldc 2A type cindex empty x Load constant ldi 2B type (a) x Load indirect lva 2C level offset empty a Load value (address) lvb 2D level offset empty b Load value (Boolean) lvc 2E level offset empty c Load value (character) lvi 2F level offset empty i Load value (integer) lvr 30 level offset empty r Load value (real) lvs 31 level offset empty s Load value (set) sti 32 type (x,a) empty Store indirect Table 22. Data Reference P-Machine Operation Notes Operand Symbol level offset Description level references the frame in which the value sought is found. When the value of level is zero, the value sought is in the frame on top of the stack. When the value of level is one or greater, the value sought is one or more frames distant in the stack following the static link. For example, if the value of level was two, the value sought is in that frame that can be found following the static link twice. offset is the amount added to the mark pointer register to obtain the desired value. Values are stored in elements of array dstore. Recall that the mark pointer register always contains a valid index of array dstore. type type is a P-Machine type. P-Machine types are listed in Table 2. cindex cindex is a constant index. A P-Machine program contains tables of integer, real, set, and string constants. If the value of type is i (4), r (5), s(6) or t(7), the value of the constant is in the associated constant table. Boolean and character constants are coded in operand 2 directly. 25
Table 1. Subset Pascal Grammar
Project: Generate instructions for program. Produce program prologs and epilogs Produce subprogram prologs and epilogs. Compute values for the sp and ep. P- Code instructions specific to this assignment
More informationObject Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code
Code Generation Intermediate Code? Assembly Code Object Code (Machine Code) 1 Intermediate Code P-Code Three Address Code 2 Compiler Construction F6S 1 Intermediate Representation Abstract Syntax Tree
More informationCS401 - Computer Architecture and Assembly Language Programming Glossary By
CS401 - Computer Architecture and Assembly Language Programming Glossary By absolute address : A virtual (not physical) address within the process address space that is computed as an absolute number.
More informationCS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri
CS356: Discussion #6 Assembly Procedures and Arrays Marco Paolieri (paolieri@usc.edu) Procedures Functions are a key abstraction in software They break down a problem into subproblems. Reusable functionality:
More informationCourse Administration
Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701
More informationIntermediate Code Generation
Intermediate Code Generation Front-end intermediate code generation source program Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator intermediate representation Symbol Table Advantages
More informationUNIT-II. Part-2: CENTRAL PROCESSING UNIT
Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:
More informationCode Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University
Code Generation Frédéric Haziza Department of Computer Systems Uppsala University Spring 2008 Operating Systems Process Management Memory Management Storage Management Compilers Compiling
More informationRun-time Environment
Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are
More informationMicroprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)
Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017) High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationComputer Organization CS 206 T Lec# 2: Instruction Sets
Computer Organization CS 206 T Lec# 2: Instruction Sets Topics What is an instruction set Elements of instruction Instruction Format Instruction types Types of operations Types of operand Addressing mode
More informationInstruction Sets: Characteristics and Functions Addressing Modes
Instruction Sets: Characteristics and Functions Addressing Modes Chapters 10 and 11, William Stallings Computer Organization and Architecture 7 th Edition What is an Instruction Set? The complete collection
More information17. Instruction Sets: Characteristics and Functions
17. Instruction Sets: Characteristics and Functions Chapter 12 Spring 2016 CS430 - Computer Architecture 1 Introduction Section 12.1, 12.2, and 12.3 pp. 406-418 Computer Designer: Machine instruction set
More informationMicroLogix 1200 Programmable Controllers
Document Update MicroLogix 1200 Programmable Controllers (Catalog Numbers 1762-L24AWA, -L24BWA, - L24BXB, -L40AWA, -L40BWA and -L40BXB; Series C) Purpose of This Document This Document Update revises the
More informationTalen en Compilers. Johan Jeuring , period 2. December 15, Department of Information and Computing Sciences Utrecht University
Talen en Compilers 2016-2017, period 2 Johan Jeuring Department of Information and Computing Sciences Utrecht University December 15, 2016 9 Simple stack machine 9-1 Recap: Semantic functions In the previous
More informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationRun time environment of a MIPS program
Run time environment of a MIPS program Stack pointer Frame pointer Temporary local variables Return address Saved argument registers beyond a0-a3 Low address Growth of stack High address A translation
More informationThe Bluff Machine (Single Module Version)
Purdue University Purdue e-pubs Department of Computer Science Technical Reports Department of Computer Science 1984 The Bluff Machine (Single Module Version) John T. Korb Purdue University, jtk@cs.purdue.edu
More informationMIPS Architecture and Assembly Language Overview
MIPS Architecture and Assembly Language Overview Adapted from: http://edge.mcs.dre.g.el.edu/gicl/people/sevy/architecture/mipsref(spim).html [Register Description] [I/O Description] Data Types and Literals
More informationORG ; TWO. Assembly Language Programming
Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify
More informationCMa simple C Abstract Machine
CMa simple C Abstract Machine CMa architecture An abstract machine has set of instructions which can be executed in an abstract hardware. The abstract hardware may be seen as a collection of certain data
More informationUNIT 3 OPERATORS. [Marks- 12]
1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,
More informationLAB C Translating Utility Classes
LAB C Translating Utility Classes Perform the following groups of tasks: LabC1.s 1. Create a directory to hold the files for this lab. 2. Create and run the following two Java classes: public class IntegerMath
More informationUNIT 4. Modular Programming
1 UNIT 4. Modular Programming Program is composed from several smaller modules. Modules could be developed by separate teams concurrently. The modules are only assembled producing.obj modules (Object modules).
More informationVirtual Machine Tutorial
Virtual Machine Tutorial CSA2201 Compiler Techniques Gordon Mangion Virtual Machine A software implementation of a computing environment in which an operating system or program can be installed and run.
More informationAssembly Language Programming of 8085
Assembly Language Programming of 8085 1. Introduction A microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessor Microprocessor understands
More informationComputer Architecture and System Software Lecture 06: Assembly Language Programming
Computer Architecture and System Software Lecture 06: Assembly Language Programming Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Assignment 3 due thursday Midterm
More informationDr. D.M. Akbar Hussain
1 2 Compiler Construction F6S 1 3 4 Compiler Construction F6S 2 5 6 Compiler Construction F6S 3 7 8 Compiler Construction F6S 4 a=b*- c + b*- c 9 a=b*- c + b*- c 10 Compiler Construction F6S 5 a=b*- c
More informationInformatics Ingeniería en Electrónica y Automática Industrial
Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical
More informationIntermediate Representations
Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationCS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION
CS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION 1. Define System Software. System software consists of a variety of programs that supports the operations of a computer. Eg. Compiler,
More informationCompiling Techniques
Lecture 10: An Introduction to MIPS assembly 18 October 2016 Table of contents 1 Overview 2 3 Assembly program template.data Data segment: constant and variable definitions go here (including statically
More information3.1 DATA MOVEMENT INSTRUCTIONS 45
3.1.1 General-Purpose Data Movement s 45 3.1.2 Stack Manipulation... 46 3.1.3 Type Conversion... 48 3.2.1 Addition and Subtraction... 51 3.1 DATA MOVEMENT INSTRUCTIONS 45 MOV (Move) transfers a byte, word,
More informationCode segment Stack segment
Registers Most of the registers contain data/instruction offsets within 64 KB memory segment. There are four different 64 KB segments for instructions, stack, data and extra data. To specify where in 1
More informationCOMPUTER ORGANIZATION & ARCHITECTURE
COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional
More informationTranslator Design Lecture 22 CMSC 4173 factor Semantics (rules 63-70)
64 factor id [ expression ] 65 factor id ( expression_list ) 66 factor ( expression ) 67 factor not factor 68 factor intlit 69 factor realit 70 factor chrlit 1. Find the symbol descriptor Sym* S in the
More informationMacro Programming Reference Guide. Copyright 2005 Scott Martinez
Macro Programming Reference Guide Copyright 2005 Scott Martinez Section 1. Section 2. Section 3. Section 4. Section 5. Section 6. Section 7. What is macro programming What are Variables What are Expressions
More informationStorage in Programs. largest. address. address
Storage in rograms Almost all operand storage used by programs is provided by memory. Even though registers are more efficiently accessed by instructions, there are too few registers to hold the stored
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 104 Topic: Semantic Analysis 2 / 104 Topic: Code Synthesis 3 / 104 Generating
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationMIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.
MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to
More informationBits, Words, and Integers
Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are
More informationComputer Organisation CS303
Computer Organisation CS303 Module Period Assignments 1 Day 1 to Day 6 1. Write a program to evaluate the arithmetic statement: X=(A-B + C * (D * E-F))/G + H*K a. Using a general register computer with
More informationPractical Malware Analysis
Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the
More informationCSE 3302 Notes 5: Memory Management
CSE 0 Notes 5: Memory Management (Last updated 10/7/15 1:6 PM) References: Gabbrielli-Martini: 5 Wirth: 4 5.1. IMPLEMENTING SIMPLE SUBPROGRAMS Historical FORTRAN and COBOL Simple = no recursion static
More informationInstruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...
Instruction-set Design Issues: what is the format(s) Opcode Dest. Operand Source Operand 1... 1) Which instructions to include: How many? Complexity - simple ADD R1, R2, R3 complex e.g., VAX MATCHC substrlength,
More informationAssembly Language Programming of 8085
Assembly Language Programming of 8085 Topics 1. Introduction 2. Programming model of 8085 3. Instruction set of 8085 4. Example Programs 5. Addressing modes of 8085 6. Instruction & Data Formats of 8085
More informationBasic Assembly SYSC-3006
Basic Assembly Program Development Problem: convert ideas into executing program (binary image in memory) Program Development Process: tools to provide people-friendly way to do it. Tool chain: 1. Programming
More informationEDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION
EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6
More informationMachine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine
Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction
More informationGeneral issues. Section 9.1. Compiler Construction: Code Generation p. 1/18
General issues Section 9.1 Target language: absolute machine language all addresses refer to actual addresses program placed in a fixed location in memory relocatable machine language (object modules)
More informationCompiling Code, Procedures and Stacks
Compiling Code, Procedures and Stacks L03-1 RISC-V Recap Computational Instructions executed by ALU Register-Register: op dest, src1, src2 Register-Immediate: op dest, src1, const Control flow instructions
More informationLanguage Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */
Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,
More informationSummary: Direct Code Generation
Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)
More informationBinghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections
x86 Assembler Computer Systems: Sections 3.1-3.5 Disclaimer I am not an x86 assembler expert. I have never written an x86 assembler program. (I am proficient in IBM S/360 Assembler and LC3 Assembler.)
More informationIntel 8086: Instruction Set
IUST-EE (Chapter 6) Intel 8086: Instruction Set 1 Outline Instruction Set Data Transfer Instructions Arithmetic Instructions Bit Manipulation Instructions String Instructions Unconditional Transfer Instruction
More informationFundamental of C programming. - Ompal Singh
Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE
More informationProblem with Scanning an Infix Expression
Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix
More informationsarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label
sarm User Guide The sarm is program that implements an experimental CPU simulator. It is called experimental because it is not yet complete, and it also incorporates facilities that are not conventionally
More informationCSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1
CSIS1120A 10. Instruction Set & Addressing Mode CSIS1120A 10. Instruction Set & Addressing Mode 1 Elements of a Machine Instruction Operation Code specifies the operation to be performed, e.g. ADD, SUB
More informationCOMPILERS BASIC COMPILER FUNCTIONS
COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,
More informationObjectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8
Objectives ICT106 Fundamentals of Computer Systems Topic 8 Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8 To understand how HLL procedures/functions are actually implemented
More informationComputer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine
Computer Organization & Assembly Language Programming CSE 2312 Lecture 15 Addressing and Subroutine 1 Sections in 8088 Code TEXT section, for the processor instructions. DATA section for the initialization
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationCompilers and Code Optimization EDOARDO FUSELLA
Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of
More informationLecture 04: Machine Instructions
CSCI2510 Computer Organization Lecture 04: Machine Instructions Ming-Chang YANG mcyang@cse.cuhk.edu.hk Reading: Chap. 2.3~2.4, 2.10~2.11 Recall: Instructions & Program A computer is governed by instructions.
More informationEthical Hacking. Assembly Language Tutorial
Ethical Hacking Assembly Language Tutorial Number Systems Memory in a computer consists of numbers Computer memory does not store these numbers in decimal (base 10) Because it greatly simplifies the hardware,
More informationC Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff
C Programming Language 1 C C is better to use than assembly for embedded systems programming. You can program at a higher level of logic than in assembly, so programs are shorter and easier to understand.
More informationQuick Reference Guide
SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Pascal language This reference guide
More informationreply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000
Declaring Variables in Assembly Language As in Java, variables must be declared before they can be used Unlike Java, we do not specify a variable type in the declaration in assembly language Instead we
More information9 Using Equation Networks
9 Using Equation Networks In this chapter Introduction to Equation Networks 244 Equation format 247 Using register address lists 254 Setting up an enable contact 255 Equations displayed within the Network
More informationCompiler construction 2009
Compiler construction 2009 Lecture 2 Code generation 1: Generating Jasmin code JVM and Java bytecode Jasmin Naive code generation The Java Virtual Machine Data types Primitive types, including integer
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More informationInstruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...
Instruction-set Design Issues: what is the format(s) Opcode Dest. Operand Source Operand 1... 1) Which instructions to include: How many? Complexity - simple ADD R1, R2, R3 complex e.g., VAX MATCHC substrlength,
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationSOURCE LANGUAGE DESCRIPTION
1. Simple Integer Language (SIL) SOURCE LANGUAGE DESCRIPTION The language specification given here is informal and gives a lot of flexibility for the designer to write the grammatical specifications to
More informationCSE P 501 Exam 12/1/11
Name There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references:
More informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationCSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature
CSE2421 FINAL EXAM SPRING 2013 Name KEY Instructions: This is a closed-book, closed-notes, closed-neighbor exam. Only a writing utensil is needed for this exam. No calculators allowed. If you need to go
More information2. Define Instruction Set Architecture. What are its two main characteristics? Be precise!
Chapter 1: Computer Abstractions and Technology 1. Assume two processors, a CISC processor and a RISC processor. In order to run a particular program, the CISC processor must execute 10 million instructions
More information2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used
More informationC Programming
204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library
More informationMath 230 Assembly Programming (AKA Computer Organization) Spring 2008
Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1
More informationProgramming the ARM. Computer Design 2002, Lecture 4. Robert Mullins
Programming the ARM Computer Design 2002, Lecture 4 Robert Mullins 2 Quick Recap The Control Flow Model Ordered list of instructions, fetch/execute, PC Instruction Set Architectures Types of internal storage
More informationCMSC 3833 Lecture 64. mov ax, 10 mov ax, 0 mov bx, 5 mov bx, 10 mul bx, ax mov cx, 5 Begin: add ax, bx loop Begin
Reduced Instruction Set Computer (RISC) The underlying philosophy of RISC machines is that a system is better able to manage progm execution when the progm consists of only a few different instructions
More informationSubprograms, Subroutines, and Functions
Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationALT-Assembly Language Tutorial
ALT-Assembly Language Tutorial ASSEMBLY LANGUAGE TUTORIAL Let s Learn in New Look SHAIK BILAL AHMED i A B O U T T H E T U TO R I A L Assembly Programming Tutorial Assembly language is a low-level programming
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationCS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation
CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 NOTHING: A Language for Practice Implementation 1 Introduction NOTHING is a programming language designed
More informationDigital System Design Using Verilog. - Processing Unit Design
Digital System Design Using Verilog - Processing Unit Design 1.1 CPU BASICS A typical CPU has three major components: (1) Register set, (2) Arithmetic logic unit (ALU), and (3) Control unit (CU) The register
More informationCS401 Assembly Language Solved MCQS From Midterm Papers
CS401 Assembly Language Solved MCQS From Midterm Papers May 14,2011 MC100401285 Moaaz.pk@gmail.com MC100401285@gmail.com PSMD01(IEMS) Question No:1 ( Marks: 1 ) - Please choose one The first instruction
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationSRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) UNIT I THE 8086 MICROPROCESSOR PART A (2 MARKS) 1. What are the functional
More informationChapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude
Chapter 2 Positional number systems A positional number system represents numeric values as sequences of one or more digits. Each digit in the representation is weighted according to its position in the
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationELEG3923 Microprocessor Ch.2 Assembly Language Programming
Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.2 Assembly Language Programming Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Inside 8051 Introduction to assembly programming
More information