精简指令集

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
transistors
Low level
Hierarchy of Programming Languages
Degree of abstraction HiHale Waihona Puke Baiduh-level
operand Java, C++ C objects
operation method
variables
registers
arithmetic op. functions instruction set
“A new book was just released which is
based on a new concept - teaching computer science through assembly language (Linux x86 assembly language, to be exact). This book teaches how the machine itself operates, rather than just the language. I've found that the key difference between mediocre and excellent programmers is whether or not they know assembly language. Those that do tend to understand computers themselves at a much deeper level. Although [almost!] unheard of today, this concept isn't really all that new -- there used to not be much choice in years past. Apple computers came with only BASIC and assembly language, and there were books available on assembly language for kids. This is why the old-timers are often viewed as 'wizards': they had to know assembly language programming.” -- slashdot.org comment, 2004-02-05
swc0 swc1 swc2 swc3
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
rs (25:21) mfcz cfcz mtcz ctcz
0 1
(16:16) bczt bczt
Laboratory #1: next Monday (3/13)
° MIPS simulator – SPIM
° Download the SPIM
• CD in the textbook • http://www.cs.wisc.edu/~larus/spim.html
° Read SPIM document
10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Application (programs) Operating Compiler System (Windows 98) Instruction Set Architecture
Software Hardware
Assembler
Processor Memory I/O system Datapath & Control Digital Design Circuit Design
16 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
- vs. CISC (Complex Instruction Set)
° Why MIPS instead of Intel 80x86?
• MIPS is simple, elegant. Don’t want to get bogged down in gritty details. • MIPS widely used in embedded apps, x86 little used in embedded, and more embedded computers than PCs
funct(5:0) add.f sub.f mul.f div.f abs.f mov.f neg.f
cvt.s.f cvt.d.f
cvt.w.f
c.f.f c.un.f c.eq.f c.ueq.f c.olt.f c.ult.f c.ole.f c.ule.f c.st.f c.ngle.f c.seq.f c.ngl.f c.lt.f c.nge.f c.le.f c.ngt.f
MIPS CPU
Memory
CPU Registers $0
Coprocessor 1 (FPU) Registers $0
Floating point
$31 Arithmetic unit Multiply divide
$31
Lo
Hi
Arithmetic unit
Coprocessor 0 (traps and memory) Registers BadVAddr Status Cause EPC
funct(5:0) sll srl sra
srlv srav jr jalr
syscall break
mfhi mthi mflo mtlo
mult multu div divu
add addu sub subu and or xor nor
slt sltu
10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Assembly
Low-level
machine
registers
binary operation code
Assembly Language
° Basic job of a CPU
• execute lots of instructions.
° Instructions are the primitive operations that the CPU may execute. ° Different CPUs implement different sets of instructions.
op(31:26)
j jal beq bne blez bgtz addi addiu slti sltiu andi ori xori lui z = 0 z = 1 z = 2 z = 3
lb lh lwl lw lbu lhu lwr sb sh swl sw
swr lwc0 lwc1 lwc2 lwc3
From C to Assembly Language Jen-Chang Liu, Spring 2006
Adapted from
http://www-inst.eecs.berkeley.edu/~cs61c/
Hierarchy of Computer Organization
High level
° The set of instructions a particular CPU implements is an Instruction Set Architecture (ISA).
• Examples: Intel 80x86 (Pentium 4), IBM/Motorola PowerPC (Macintosh), MIPS, Intel IA64, ...
° Assignment Statement: Variable = expression
• Examples: celsius = 5*(fahr-32)/9; a = b+c+d-e;
C Operators/Operands (2/2)
° C (and most High Level Languages) In variables declared first and given a type
funct (4:0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 tlbr tlbwi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
• On-line document
• Textbook Appendix A
° Try a simple program
Outline ° operators, operands C
° Variables in Assembly: Registers
° Comments in Assembly
° Addition and Subtraction in Assembly
Purpose of learning assembly
° Understanding of the underlying hardware ° Assembly program is smaller and faster
• Ex. Embedded applications
Book: Programming From the Ground Up
We are going from C to assembly
° Target machine architecture for assembly code: MIPS
• Designed in early 1980s • Used by NEC, Nintendo, Silicon Graphics, Sony, etc. • RISC architecture (Reduced Instruction Set) 精簡指令集
° Memory Access in Assembly
Review C Operators/Operands (1/2)
° Operators: +, -, *, /, % (mod);
•7/4==1, 7%4==3
° Operands:
• Variables: lower, upper, fahr, celsius • Constants: 0, 1000, -17, 15.4
rt (20:16) bltz bgez
tlbwr tlbp
if z = 0 copz copz if z = l, if z = l, f = d f = s
rte
bltzal bgezal
10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
相关文档
最新文档