Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2
Typical machine design Two cycles: Fetch cycle - get instruction Execute cycle - do operation
Typical machine execution Typical fetch cycle: (M(x) means contents of x) 1. M(IC) MAR [Memory Address register] 2. IC +1 IC [Instruction Counter] 3. Read memory into MDR [Memory Data Register] 4. MDR IR [Instruction Register for decoding] Typical execute cycle: (OP R,X, DISP is instruction) 1. IR decoded into OP R, EA OP is operation code (e.g., 8 bits) R is register (e.g., 4 bits -- 16 registers) EA is effective address (e.g., 20 bits) 2. M(X)+DISP MAR (EA MAR) 3. Read memory into MDR 4. M(R) ALU; M(MDR) ALU 5. Do operation OP in ALU; ALU R For 500 MHZ: Each instruction 9-10 cycles (50 MIPS) By overlapping fetch and execute cycles, get 60-70 MIPS
Typical machine translation For example in C: As we see later, memory for data in blocks of storage pointed to by a register: X = Y + Z could be translated as: load R1, R2, 28 [Location of Y] add R1, R2, 40 [Location of Z] store R1, R2, 24 [Location of X] Instruction format: Opcode register, index, offset load R1, R2, 24
Software architectures Previously Build program to use hardware efficiently. Often use of machine language for efficiency. Today No longer write directly in machine language. Use of layers of software. Concept of virtual machines. Each layer is a machine that provides functions for the next layer.
Example: Web application Virtual Machines Example: Web application
Binding and Binding Time Binding : program element에 속성 또는 수행에 필요한 요소를 연결하는 것 예 :: 변수 형(type), 기억장소 (memory) , 값, … Binding time : Binding이 일어나는 시간 Execution time (run time) :: 기억장소나 값 On entry to a subprogram or block :: C, C++의 형식인자와 실질인자의 연결 At arbitrary points during execution ::: LIS, SMALLTALK, ML, Java Translation time Bindings chosen by the programmer ::: 변수이름, 형, Bindings chosen by the translator ::: C의 integer 크기, memory class에 따른 기억위치, array의 저장방법 ??? Bindings chosen by the loader (linker) ::: external 변수의 참조
Binding time (Cont.) Language Implementation time One’s complement ? 2’s complement 연산자의 구현 방법, …. Language Definition time Data structure types, statement forms, .. 예 ::: X=X+10 X의 형 translation time C, C++, Java, Ada Run time LISP, SMALLTALK, PERL X에 넣을 수 있는 값의 집합 X의 값 10의 표현 … 언어정의 시 (10 정수, ’10’), 언어구현 시 (10의 표현) ‘+’의 의미 ‘+’ addition(언어정의 시), overload 해결 (compile 시), 더하기가 구현되는 방법 (implementation time), 실제연산 (execution time)
Binding time and languages C, C++, Ada, FORTRAN translation time binding (early binding) LISP, ML, Perl, HTML runtime binding (late binding) Binding and scope rule 숙제 2장 연습문제 3번, 5번, 6번