Upload
milo-mark-harrell
View
215
Download
1
Tags:
Embed Size (px)
Citation preview
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.
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
• contain binary values
• platform specific
• each microprocessor has own language
• may be backward compatible
Machine Languages
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
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
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.
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.
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.
Attributes of Assembly Language Instructions
• instruction types
• data types
• addressing modes
• instruction formats
Assembly Language Instruction Types
• data transfer instructions
• data operation instructions
• program control instructions
• interrupts
• halt instruction
• 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
Data Operation Instructions
• Arithmetic, Logic and Shift instructions
• modify their data values
• perform operation on one or two data values and store result
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
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
Halt instruction
• causes microprocessor to stop executing instructions
• used at the end of program
Floating Point Numbers
• include fractional portion of the value
• may be assigned special registers
and instructions by microprocessor
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
Characters
• stored as binary values
• encoded using ASCII, EBCDIC, UNICODE or other encoding standard
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.
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))
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.
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.
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.
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.
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.
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