计算机组成与设计-11

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Review
Disassembly is simple and starts by
decoding opcode field.
Be creative, efficient when authoring C
Assembler expands real instruction set
(TAL) with pseudoinstructions (MAL)
program.
CS61C L18 Running a Program I (6) Garcia, Spring 2008 © UCB
Translation
Scheme Compiler is a translator from
Scheme to machine language. The processor is a hardware interpeter of machine language.
Compiler
Input: High-Level Language Code
(e.g., C, Java such as foo.c)
Output: Assembly Language Code
(e.g., foo.s for MIPS)
Note: Output maycontain pseudoinstructions
Language translation gives us another option. In general, we interpret a high level language when efficiency is not critical and translate to a lower level language to up performance
executes other programs.
Scheme Java C C++ Easy to program Inefficient to interpret Java bytecode Assembly machine language Efficient to interpret Difficult to program
CS61C L18 Running a Program I (2)
Garcia, Spring 2008 © UCB
Overview
Interpretation vs Translation
Translating C Programs
Compiler Assembler
Linker (next time)
marketplace (eg. Microsoft keeps all their source code secret) Alternative model, “open source”, creates value by publishing the source code and fostering a community of developers.
Garcia, Spring 2008 © UCB
Assembler Directives (p. A-51 to A-53) directions to assembler, but do Give
not produce machine instructions
.text: Subsequent items put in user text segment (machine code) .data: Subsequent items put in user data segment (binary rep of data in source file) .globlsym: declares sym global and can be referenced from other files .asciizstr: Store the string str in memory and null-terminate it .word w1…wn: Store the n 32-bit quantities in successive memory words
the source language Translator: Converts a program from the source language to an equivalent program in another language
For example, consider a Scheme program
CS61C L18 Running a Program I (8) Garcia, Spring 2008 © UCB
Interpretation vs. Translation? (1/2) Generally easier to write interpreter
Interpreter closer to high-level, so can give better error messages (e.g., SPIM)
UCB CS61C : Machine Structures
Lecture18 – Running a Program I
Lecturer SOE Dan Garcia
inst.eecs.berkeley.edu/~cs61c
(Compiling, Assembling, Linking, Loading)
CS61C L18 Running a Program I (7)
Garcia, Spring 2008 © UCB
Interpretation
Any good reason to interpret machine
language in software? SPIM – useful for learning / debugging Apple Macintosh conversion
CS61C L18 Running a Program I (10) Garcia, Spring 2008 © UCB
Steps to Starting a Program (translation)
CS61C L18 Running a Program I (11)
Garcia, Spring 2008 © UCB
CS61C L18 Running a Program I (4) Garcia, Spring 2008 © UCB
Interpretation vs Translation
How do we run a program written in a
source language?
Interpreter: Directly executes a program in
CS61C L18 Running a Program I (9) Garcia, Spring 2008 © UCB
Interpretation vs. Translation? (2/2) Translated/compiled code almost always
more efficient and therefore higher performance:
TINY ETCH-A-SKETCH
Researchers at the University of Pittsburgh have used an atomic force microscope (AFM) to draw tiny, electrically conductive paths (ala wires) on a special material. The lines were as thin as 3 nm, making this one of the most precise techniques for etching devices out of silicon. Rewritable logic circuits? www.technologyreview.com/Nanotech/20362/ High-density memory? Very cool!
Pseudoinstructions: instructions that
assembler understands but not in machine (last lecture) For example: mov $s1,$s2or $s1,$s2,$zero
CS61C L18 Running a Program I (12) Garcia, Spring 2008 © UCB
Important for many applications,
particularly operating systems.
Translation/compilation helps “hide” the program “source” from the users:
One model for creating value in the
Where Are We Now?
CS164
CS61C L18 Running a Program I (13)
Garcia, Spring 2008 © UCB
Assembler
Input: Assembly Language Code
(e.g., foo.s for MIPS)
Output: Object Code, information tables
(e.g., foo.o for MIPS)
Reads and Uses Directives
Replace Pseudoinstructions Produce Machine Language Creates Object File
CS61C L18 Running a Program I (14)
Loader (next time)
An Example (next time)
CS61C L18 Running a Program I (3)
Garcia, Spring 2008 ©源自文库UCB
Language Execution Continuum
An Interpreter is a program that
Assembler’s job to do conversion Assembler uses reserved register $at MAL makes it much easier to write MIPS
Only TAL can be converted to raw binary
Translator reaction: add extra information
to help debugging (line numbers, names)
Interpreter slower (10x?), code smaller
(2X?) Interpreter provides instruction set independence: run on any machine
foo.scm
CS61C L18 Running a Program I (5)
Garcia, Spring 2008 © UCB
Interpretation
Scheme Interpreter is just a program that reads a scheme program and performs the functions of that scheme
Switched from Motorola 680x0 instruction
architecture to PowerPC.
Similar issue with switch to x86.
Could require all programs to be re-
translated from high level language Instead, let executables contain old and/or new machine code, interpret old code in software if necessary (emulation)
相关文档
最新文档