Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.

Similar presentations


Presentation on theme: "CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina."— Presentation transcript:

1 CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina

2 Overview Levels of programming languages. Their relationship to each other. How they’re converted into executable form. How Java applets are converted to run on a computer. Attributes of assembly language instructions.

3 High- Level Languages Assembly Languages Machine Languages LANGUAGE CATEGORIES

4 platform independent highest level of abstraction Java, C++, FORTRAN High- Level Languages

5 Assembly Languages lower level of abstraction specific to each microprocessor usually backward compatible can directly manipulate data stored in a microprocessors internal components platform-specific

6 contain binary values platform specific each microprocessor has own language may be backward compatible Machine Languages

7 High-level Language Programs are Compiled

8 Assembly Language Programs are Assembled

9 Java Applets are Compiled into Bytecode Applet is a Java program running inside a browser.

10 Bytecode Bytecode is generated by Java compiler to be later interpreted by Java Virtual Machine and translated into machine code at run-time. JVM interprets the bytecode for its specific platform and executes it. Therefore, bytecode is platform independent. JVM can be a hardware chip but usually it is a program, often part of Web browser. Most browsers are Java-enabled and most operating systems have JVM ported on them.

11 Bytecode Bytecode can not be directly executed by microprocessor - code runs much slower Therefore it would not be efficient to do CPU-intensive tasks with JVM interpreter Still Java can easily keep up with the data rate of network connection. Many platforms have just-in-time bytecode compilers that compile code once, cach the results and call it again if needed. Just-in-time compilers will speed up the program 10 - 20 times compare to interpreter.

12 Attributes of Assembly Language Instructions instruction types data types addressing modes instruction formats

13 Assembly Language Instruction Types data transfer instructions data operation instructions program control instructions interrupts halt instruction

14 most common microprocessor operation copy the value to its destination perform following transfers: –Load data from memory into the microprocessor –Store data from microprocessor into memory –Move data within the microprocessor –Input data to the microprocessor –Output data from the microprocessor Data Transfer Instructions

15 Data Operation Instructions Arithmetic, Logic and Shift instructions modify their data values perform operation on one or two data values and store result

16 Program Control Instructions jump or branch instructions used to go to another part of program absolute jump is always taken: jr $ra conditional jump is taken if condition is met: bne $t0, $t1, endloop instructions to call and return from subroutines: jal calcsqrt

17 Interrupts tells microprocessor to stop and execute another instruction software interrupts are generated by assembly language instructions hardware interrupts are triggered by devices outside of microprocessor

18 Halt instruction causes microprocessor to stop executing instructions used at the end of program

19 Most Common Data Types Integers Floating point numbers Boolean values Characters

20 Integers range from 0 to 2^n - 1 for unsigned from -2^n to 2^(n-1)-1 for signed

21 Floating Point Numbers include fractional portion of the value may be assigned special registers and instructions by microprocessor

22 Boolean Type true or false values zero is false, non-zero is true can be used to perform logical operations Ex.: result of 0010 AND 0001 is true

23 Characters stored as binary values encoded using ASCII, EBCDIC, UNICODE or other encoding standard

24 Addressing Modes Direct Mode: LDAC 5 (loads value into accumulator from memory location 5) Indirect Mode: LDAC @5 (loads value from the memory address stored at memory location 5) Register Direct Mode: LDAC R (copies value stored in register R) Register Indirect Mode: LDAC @R (copies value from the memory address stored in register R) Assume LDAC loads data from memory into microprocessor’s AC register.

25 Addressing Modes Immediate Mode: LDAC #5 (moves value 5 into accumulator) Implicit Mode: LDAC (gets an operand from stack, don’t have to specify an operand) Relative Mode: LDAC $5 (the operand supplies offset from the program counter to generate address) Index Mode: LDAC 5(X) (loads the data from X+5 memory location) Address Mode: LDAC 5(X) (loads the data from memory address(X+5))

26 Instruction Formats Instructions code - binary value representing an assembly language instruction after it is converted into machine code. Different instructions may have different formats. Groups of bits in a format correspond to the opcode and the operands.

27 Example for the operation A=B+C This instruction has one operation, two source operands and one destination operand. Microprocessor performing 16 different operations will need 4 bits to specify one operation. Assume bit pattern 1010 corresponds to addition. Assume that there are only 4 possible operands for this operation A, B, C and D. Corresponding bit patterns for the operands: 00 for A, 01 for B, 10 for C and 11 for D.

28 Instruction Formats opcode operand #1 operand #2 4 bits 2 bits 2 bits MOVE A,B (A=B) 1000 00 01 ADD A,C (A=A+C) 1010 00 10 opcode operand #1 operand #2 operand #3 4 bits 2 bits 2 bits 2 bits ADD A,B,C (A=B+C) 1010 00 01 10 assembly code machine code Format for three-operand instruction. Format for two-operand instruction.

29 Instruction Formats opcode operand 4 bits 2 bits LOAD B (Acc=B) 0000 01 ADD C (Acc=Acc+C) 1010 10 STORE A (A=Acc) 0001 00 opcode 4 bits PUSH B (Stack=B) 0101 PUSH C (Stack=C,B) 0110 ADD (Stack=B+C) 1010 POP A (A=Stack) 1100 assembly code machine code One-operand instruction. The accumulator register is always used as destination and one of source registers. Zero-operand instruction. All operands are drawn from the stack.

30 Instruction Formats Microprocessor may be designed to work with instructions that specify 3, 2, 1 or 0 operands. Microprocessor that uses two-operand instructions is more limited than one using three-operand instructions.

31 Microprocessors with Fewer Operand Instructions Drawbacks: more instructions needed for the same task Benefits: instruction codes use fewer bits hardware to implement microprocessor is less complex microprocessors whose instructions specify fewer operands can usually execute instructions more quickly


Download ppt "CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina."

Similar presentations


Ads by Google