Review Reserve exponents, significands: Exponent Significand Object nonzero Denorm anything +/- fl. pt. # /- 255 nonzero NaN

Similar documents
CS61C L12 MIPS Instruction Rep III, Running a Program I (6) Integer mult, div uses hi, lo regs mfhi and mflo copies out.

CS61C : Machine Structures

UCB CS61C : Machine Structures

CS61C : Machine Structures

Lecture 9: Disassembly

UC Berkeley CS61C : Machine Structures

Review. Lecture 18 Running a Program I aka Compiling, Assembling, Linking, Loading

UCB CS61C : Machine Structures

CS61C Machine Structures. Lecture 18 - Running a Program I. 3/1/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C : Machine Structures

CS61C : Machine Structures

Review. Disassembly is simple and starts by decoding opcode field. Lecture #13 Compiling, Assembly, Linking, Loader I

CS61C : Machine Structures

CS61C : Machine Structures

IEEE Standard 754 for Binary Floating-Point Arithmetic.

CS61C : Machine Structures

Assembler. #13 Running a Program II

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions

CS61C : Machine Structures

ECE 15B COMPUTER ORGANIZATION

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

CS 61C: Great Ideas in Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

UC Berkeley CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

ecture 12 From Code to Program: CALL (Compiling, Assembling, Linking, and Loading) Friedland and Weaver Computer Science 61C Spring 2017

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

CS61C : Machine Structures

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o

UCB CS61C : Machine Structures

IEEE Standard 754 for Binary Floating-Point Arithmetic.

Where Are We Now? Linker (1/3) Linker (2/3) Four Types of Addresses we ll discuss. Linker (3/3)

CS 61c: Great Ideas in Computer Architecture

Administrivia. Midterm Exam - You get to bring. What you don t need to bring. Conflicts? DSP accomodations? Head TA

ECE 15B COMPUTER ORGANIZATION

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture. MIPS Instruc,on Representa,on II. Dan Garcia

CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

CS61C : Machine Structures

Outline. Homework. Assembly Language. Instructions. Instruction Set Architectures. Csci 136 Computer Architecture II MIPS Instruction Set Architecture

UCB CS61C : Machine Structures

Brought to you by CalLUG (UC Berkeley GNU/Linux User Group). Tuesday, September 20, 6-8 PM in 100 GPB.

Lecture #6 Intro MIPS; Load & Store Assembly Variables: Registers (1/4) Review. Unlike HLL like C or Java, assembly cannot use variables

Lecture 10: Program Development versus Execution Environment

Administrivia. Translation. Interpretation. Compiler. Steps to Starting a Program (translation)

Lecture 4: MIPS Instruction Set

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

CS 61C: Great Ideas in Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

95% of the folks out there are completely clueless about floating-point.

UCB CS61C : Machine Structures

Outline. Lecture 40 Hardware Parallel Computing Thanks to John Lazarro for his CS152 slides inst.eecs.berkeley.

UC Berkeley CS61C : Machine Structures

UCB CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

Review. Lecture #7 MIPS Decisions So Far...

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

CS 110 Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

CS61C : Machine Structures

CS 110 Computer Architecture MIPS Instruction Formats

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

CS61C : Machine Structures

Topic Notes: MIPS Instruction Set Architecture

UC Berkeley CS61C : Machine Structures

COMP MIPS instructions 2 Feb. 8, f = g + h i;

CS61C : Machine Structures

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE331: Hardware Organization and Design

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CS61C : Machine Structures

Precision and Accuracy

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

CS 61c: Great Ideas in Computer Architecture

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

Instructors: Randy H. Katz David A. PaHerson hhp://inst.eecs.berkeley.edu/~cs61c/fa10. Fall Lecture #6. Agenda

Unsigned Binary Integers

Unsigned Binary Integers

CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

MIPS Instruc,ons CS 64: Computer Organiza,on and Design Logic Lecture #8

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Administrivia. Midterm Exam - You get to bring. What you don t need to bring. Conflicts? DSP accomodations? Head TA

EEC 581 Computer Architecture Lecture 1 Review MIPS

Lecture 5: Procedure Calls

Clever Signed Adder/Subtractor. Five Components of a Computer. The CPU. Stages of the Datapath (1/5) Stages of the Datapath : Overview

Transcription:

CS61C L11 MPS nstruction ep, unning a Program (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #12 MPS nstruction ep, unning a Program aka Compiling, Assembling, Linking, Loading (CALL) 2005-0xA There is one handout today at the front and back of the room! Lecturer PSOE, new dad Dan Garcia www.cs.berkeley.edu/~ddgarcia SF: Tiger over Daly n a treat for the Bay Area, the top golfers descended to Harding Park in SF and saw a treat: the two longest hitters battled in a playoff before Daly choked. sports.espn.go.com/golf/news/story?id=2185968 eview eserve exponents, significands: Exponent Significand Object 0 0 0 0 nonzero Denorm 1-254 anything +/- fl. pt. # 255 0 +/- 255 nonzero NaN nteger mult, div uses hi, lo regs mfhi and mflo copies out. Four rounding modes (to even default) MPS FL ops complicated, expensive CS61C L11 MPS nstruction ep, unning a Program (2) Clarification - EEE Four ounding Modes ound We gave towards examples + in base 10 to show you ALWAYS the 4 modes round up : (only 2.1 apply 3, -2.1 to.5 10 )-2 What really happens is ound towards - 1) in binary, not decimal! 2) at ALWAYS the lowest round bit of down : the mantissa 1.9 with 1, -1.9 the -2 Truncate guard bit(s) as our extra bit(s), and you need to Just decide drop how the these last bits extra (round bit(s) towards affect the 0) result if the guard bits are 100 3) ound f so, you re to (nearest) half-way even between (default) the representable Normal rounding, numbers. almost: 2.5 2, 3.5 4 E.g., Like 0.1010 you is learned 5/8, halfway in grade between school our representable nsures fairness 4/8 [1/2] on calculation and 6/8 [3/4]. Which number Half the do time we we round round to? up, 4 modes! other half down CS61C L11 MPS nstruction ep, unning a Program (3) Decoding Machine Language How do we convert 1s and 0s to C code? Machine language C? For each 32 bits: Look at opcode: 0 means -Format, 2 or 3 mean J-Format, otherwise -Format. Use instruction type to determine which fields exist. Write out MPS assembly code, converting each field to name, register number/name, or decimal/hex number. Logically convert this MPS code into valid C code. Always possible? Unique? CS61C L11 MPS nstruction ep, unning a Program (4) Decoding Example (1/7) Here are six machine language instructions in hexadecimal: 00001025 hex 0005402A hex 11000003 hex 00441020 hex 20A5FFFF hex 08100001 hex Let the first instruction be at address 4,194,304 ten (0x00400000 hex ). Next step: convert hex to binary J Decoding Example (2/7) The six machine language instructions in binary: 00000000000000000001000000100101 00000000000001010100000000101010 00010001000000000000000000000011 00000000010001000001000000100000 00100000101001011111111111111111 00001000000100000000000000000001 Next step: identify opcode and format 0 rs rt rd shamt funct 1, 4-31 rs rt immediate 2 or 3 target address CS61C L11 MPS nstruction ep, unning a Program (5) CS61C L11 MPS nstruction ep, unning a Program (6)

CS61C L11 MPS nstruction ep, unning a Program (7) J Decoding Example (3/7) Select the opcode (first 6 bits) to determine the format: Format: 00000000000000000001000000100101 00000000000001010100000000101010 00010001000000000000000000000011 00000000010001000001000000100000 00100000101001011111111111111111 00001000000100000000000000000001 Look at opcode: 0 means -Format, 2 or 3 mean J-Format, otherwise -Format. Next step: separation of fields J Decoding Example (4/7) Fields separated based on format/opcode: Format: 0 0 0 2 0 37 0 0 5 8 0 42 4 8 0 +3 0 2 4 2 0 32 8 5 5-1 2 1,048,577 Next step: translate ( disassemble ) to MPS assembly instructions CS61C L11 MPS nstruction ep, unning a Program (8) Decoding Example (5/7) MPS Assembly (Part 1): Address: Assembly instructions: 0x00400000 or $2,$0,$0 0x00400004 slt $8,$0,$5 0x00400008 beq $8,$0,3 0x0040000c add $2,$2,$4 0x00400010 addi $5,$5,-1 0x00400014 j 0x100001 Better solution: translate to more meaningful MPS instructions (fix the branch/jump and add labels, registers) Decoding Example (6/7) MPS Assembly (Part 2): or $v0,$0,$0 Next step: translate to C code (be creative!) CS61C L11 MPS nstruction ep, unning a Program (9) CS61C L11 MPS nstruction ep, unning a Program (10) Decoding Example (7/7) Before Hex: 00001025 hex 0005402A hex 11000003 hex 00441020 hex 20A5FFFF hex 08100001 hex or $v0,$0,$0 After C code (Mapping below) $v0: product $a0: multiplicand $a1: multiplier CS61C L11 MPS nstruction ep, unning a Program (11) product = 0; while (multiplier > 0) { product += multiplicand; multiplier -= 1; } Demonstrated Big 61C dea: nstructions are just numbers, code is treated like data Administrivia Midterm in 7 days! Project 2 due Wednesday (ok, Friday) Midterm 2005-10-17 @ 5:30-8:30pm Here! Covers labs,hw,proj,lec up through 7th wk Prev sem midterm + answers on HKN Bring NO backpacks, cells, calculators, pagers, PDAs 2 writing implements (we ll provide write-in exam booklets) pencils ok! One handwritten (both sides) 8.5 x11 paper One green sheet (corrections below to bugs from Core nstruction Set ) 1) Opcode wrong for Load Word. t should say 23hex, not 0 / 23hex. 2) sll and srl should shift values in [rt], not [rs] i.e. sll/srl: [rd] = [rt] << shamt CS61C L11 MPS nstruction ep, unning a Program (12)

CS61C L11 MPS nstruction ep, unning a Program (13) eview from before: lui So how does lui help us? Example: addi becomes: lui ori add $t0,$t0, 0xABABCDCD $at, 0xABAB $at, $at, 0xCDCD $t0,$t0,$at Now each -format instruction has only a 16- bit immediate. Wouldn t it be nice if the assembler would this for us automatically? - f number too big, then just automatically replace addi with lui, ori, add True Assembly Language (1/3) Pseudoinstruction: A MPS instruction that doesn t turn directly into a machine language instruction, but into other MPS instrucitons What happens with pseudoinstructions? They re broken up by the assembler into several real MPS instructions. But what is a real MPS instruction? Answer in a few slides First some examples CS61C L11 MPS nstruction ep, unning a Program (14) Example Pseudoinstructions egister Move move reg2,reg1 Expands to: add reg2,$zero,reg1 Load mmediate li reg,value f value fits in 16 bits: addi reg,$zero,value else: lui reg,upper 16 bits of value ori reg,$zero,lower 16 bits True Assembly Language (2/3) Problem: When breaking up a pseudoinstruction, the assembler may need to use an extra reg. f it uses any regular register, it ll overwrite whatever the program has put into it. Solution: eserve a register ($1, called $at for assembler temporary ) that assembler will use to break up pseudo-instructions. Since the assembler may use this at any time, it s not safe to code with it. CS61C L11 MPS nstruction ep, unning a Program (15) CS61C L11 MPS nstruction ep, unning a Program (16) Example Pseudoinstructions Example Pseudoinstructions otate ight nstruction ror reg, value Expands to: srl $at, reg, value sll reg, reg, 32-value or reg, reg, $at No OPeration instruction nop Expands to instruction = 0 ten, sll $0, $0, 0 0 0 Wrong operation for operand addu reg,reg,value # should be addiu f value fits in 16 bits, addu is changed to: addiu reg,reg,value else: lui $at,upper 16 bits of value ori $at,$at,lower 16 bits addu reg,reg,$at How do we avoid confusion about whether we are talking about MPS assembler with or without pseudoinstructions? CS61C L11 MPS nstruction ep, unning a Program (17) CS61C L11 MPS nstruction ep, unning a Program (18)

CS61C L11 MPS nstruction ep, unning a Program (19) True Assembly Language (3/3) MAL (MPS Assembly Language): the set of instructions that a programmer may use to code in MPS; this includes pseudoinstructions TAL (True Assembly Language): set of instructions that can actually get translated into a single machine language instruction (32-bit binary string) A program must be converted from MAL into TAL before translation into 1s & 0s. Questions on Pseudoinstructions Question: How does MPS recognize pseudoinstructions? Answer: t looks for officially defined pseudoinstructions, such as ror and move t looks for special cases where the operand is incorrect for the operation and tries to handle it gracefully CS61C L11 MPS nstruction ep, unning a Program (20) ewrite TAL as MAL TAL: or $v0,$0,$0 This time convert to MAL t s OK for this exercise to make up MAL instructions ewrite TAL as MAL (Answer) TAL: or $v0,$0,$0 MAL: li $v0,0 Loop: bge $zero,$a1,exit decr $a1, 1 CS61C L11 MPS nstruction ep, unning a Program (21) CS61C L11 MPS nstruction ep, unning a Program (22) Peer nstruction Peer nstruction 1. Converting float -> int -> float produces same float number 2. Converting int -> float -> int produces same int number 3. FP add is associative: (x+y)+z = x+(y+z) ABC 1: FFF 2: FFT 3: FTF 4: FTT 5: TFF 6: TFT 7: TTF 8: TTT Which of the instructions below are MAL and which are TAL? A. addi $t0, $t1, 40000 B. beq $s0, 10, Exit C. sub $t0, $t1, 1 ABC 1: MMM 2: MMT 3: MTM 4: MTT 5: TMM 6: TMT 7: TTM 8: TTT CS61C L11 MPS nstruction ep, unning a Program (23) CS61C L11 MPS nstruction ep, unning a Program (25)

CS61C L11 MPS nstruction ep, unning a Program (27) Upcoming Calendar Week # #7 This week #8 Midterm week (review Sun @ 2pm 10 Evans) Mon MPS unning Program Midterm @ 5:30-8:30pm Here! (155 Dwin) Wed unning Program ntro to SDS Thurs Lab unning Program SDS n semi-conclusion Disassembly is simple and starts by decoding opcode field. Be creative, efficient when authoring C Assembler expands real instruction set (TAL) with pseudoinstructions (MAL) Only TAL can be converted to raw binary Assembler s job to do conversion Assembler uses reserved register $at MAL makes it much easier to write MPS CS61C L11 MPS nstruction ep, unning a Program (28) Overview Language Continuum nterpretation vs Translation Translating C Programs Compiler Assembler (next time) Linker (next time) Loader (next time) An Example (next time) Scheme Java Easy to program nefficient to interpret Java bytecode C++ C Assembly machine language Efficient Difficult to program n general, we interpret a high level language if efficiency is not critical or translated to a lower level language to improve performance CS61C L11 MPS nstruction ep, unning a Program (29) CS61C L11 MPS nstruction ep, unning a Program (30) nterpretation vs Translation nterpretation How do we run a program written in a source language? nterpreter: Directly executes a program in the source language Translator: Converts a program from the source language to an equivalent program in another language For example, consider a Scheme program foo.scm Scheme program: foo.scm Scheme nterpreter CS61C L11 MPS nstruction ep, unning a Program (31) CS61C L11 MPS nstruction ep, unning a Program (32)

CS61C L11 MPS nstruction ep, unning a Program (33) Translation Scheme program: foo.scm Scheme Compiler (+ assembler & linker) Executable(mach lang pgm): a.out Hardware Scheme Compiler is a translator from Scheme to machine language. nterpretation Any good reason to interpret machine language in software? SPM useful for learning / debugging Apple Macintosh conversion Switched from Motorola 680x0 instruction architecture to PowerPC. Could require all programs to be retranslated from high level language nstead, let executables contain old and/or new machine code, interpret old code in software if necessary CS61C L11 MPS nstruction ep, unning a Program (34) nterpretation vs. Translation? Easier to write interpreter nterpreter closer to high-level, so gives better error messages (e.g., SPM) Translator reaction: add extra information to help debugging (line numbers, names) nterpreter slower (10x?) but code is smaller (1.5X to 2X?) nterpreter provides instruction set independence: run on any machine Apple switched to PowerPC. nstead of retranslating all SW, let executables contain old and/or new machine code, Steps to Starting a Program C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o Linker Executable(mach lang pgm): a.out Loader Memory lib.o interpret old code in software if necessary CS61C L11 MPS nstruction ep, unning a Program (35) CS61C L11 MPS nstruction ep, unning a Program (36) Compiler nput: High-Level Language Code (e.g., C, Java such as foo.c) Output: Assembly Language Code (e.g., foo.s for MPS) Note: Output may contain pseudoinstructions Pseudoinstructions: instructions that assembler understands but not in machine. E.g., mov $s1,$s2 or $s1,$s2,$zero CS61C L11 MPS nstruction ep, unning a Program (37) And in conclusion... C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o Linker lib.o Executable(mach lang pgm): a.out Loader Memory CS61C L11 MPS nstruction ep, unning a Program (38)