Top Banner
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina
31

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

Jan 01, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.

CS 147

June 13, 2001

Levels of Programming Languages

Svetlana Velyutina

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

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.

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

• High- Level Languages

• Assembly Languages

• Machine Languages

LANGUAGE CATEGORIES

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

• platform independent

• highest level of abstraction

• Java, C++, FORTRAN

High- Level Languages

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

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

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

• contain binary values

• platform specific

• each microprocessor has own language

• may be backward compatible

Machine Languages

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

High-level Language Programs are Compiled

Other Pentiumobject files

W indow sPentium PC

Pentuimexecutable file

Pentium linker

Pentium object code

Com piler for PentiumW indow s PC

Other G 4object files

G 4Pow er M ac

G 4executable file

G 4 linker

G 4 object code

Com piler for G 4Pow er M ac Com puter

Other SPARCobject files

SPARCUNIX w orkstation

SPARCexecutable file

SPARC linker

SPARC object code

Com piler for SPARCUNIX w orkstation

High level-languagesourse code

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

Assembly Language Programs are Assembled

Other processor X object files

Com puter w ith processor X

Processor Xexecutable file

Processor X linker

Processor X object code

Assem bler forprocessor X

Assem bly languageprogram for processor X

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

Java Applets are Compiled into Bytecode

W indow sPentium PC

Java VM forW indow s Pentium PC

G4Pow er M ac

Java VM forG4 Pow er M ac

SPARCUNIX w orkstation

Java VM forSPARC UNIX w orkstation

Bytecode

Java com piler

Java appletsource code

Applet is a Java program running inside a browser.

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

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.

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

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.

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

Attributes of Assembly Language Instructions

• instruction types

• data types

• addressing modes

• instruction formats

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

Assembly Language Instruction Types

• data transfer instructions

• data operation instructions

• program control instructions

• interrupts

• halt instruction

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

• 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

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

Data Operation Instructions

• Arithmetic, Logic and Shift instructions

• modify their data values

• perform operation on one or two data values and store result

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

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

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

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

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

Halt instruction

• causes microprocessor to stop executing instructions

• used at the end of program

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

Most Common Data Types

• Integers

• Floating point numbers

• Boolean values

• Characters

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

Integers

• range from 0 to 2^n - 1 for unsigned

• from -2^n to 2^(n-1)-1 for signed

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

Floating Point Numbers

• include fractional portion of the value

• may be assigned special registers

and instructions by microprocessor

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

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

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

Characters

• stored as binary values

• encoded using ASCII, EBCDIC, UNICODE or other encoding standard

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

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.

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

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))

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

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.

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

Example for the operation A=B+CThis 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.

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

Instruction Formats

opcode operand #1 operand #2

4 bits 2 bits 2 bitsMOVE 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.

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

Instruction Formats

opcode operand

4 bits 2 bits

LOAD B (Acc=B) 0000 01ADD C (Acc=Acc+C) 1010 10STORE A (A=Acc) 0001 00

opcode

4 bits PUSH B (Stack=B) 0101PUSH C (Stack=C,B) 0110ADD (Stack=B+C) 1010POP 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.

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

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.

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

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