DOC PREVIEW
Berkeley COMPSCI 61C - Lecture 10

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS61C Starting a Program Lecture 10 February 19 1999 Dave Patterson http cs berkeley edu patterson www inst eecs berkeley edu cs61c schedule html cs 61C L10 Start 1 Patterson Spring 99 UCB Review 2 2 Review New MIPS arithmetic instructions Example Meaning Comments mult 2 3 Hi Lo 2 x 3 64 bit signed product multu 2 3 Hi Lo 2 x 3 64 bit unsigned product div 2 3 Lo 2 3 Lo quotient Hi rem divu 2 3 Lo 2 3 Unsigned quotient rem mfhi 1 1 Hi Used to get copy of Hi mflo 1 1 Lo Used to get copy of Lo add s 0 1 2 f0 f1 f2 Fl Pt Add single add d 0 2 4 f0 f2 f4 Fl Pt Add double sub s 0 1 2 f0 f1 f2 Fl Pt Subtract single sub d 0 2 4 f0 f2 f4 Fl Pt Subtract double mul s 0 1 2 f0 f1x f2 Fl Pt Multiply single mul d 0 2 4 f0 f2x f4 Fl Pt Multiply double div s 0 1 2 f0 f1 f2 Fl Pt Divide single div d 0 2 4 f0 f2 f4 Fl Pt Divide double c X s 0 1 flag1 f0 X f1 Fl Pt Compare single c X d 0 2 flag1 f0 X f2 Fl Pt Compare double cs 61C L10 Start 2 X is eq lt le bc1t bc1f tests flag Patterson Spring 99 UCB Outline IEEE 754 Floating Point standard accuracy first class citizen Floating Point Questions and Answers Multiply product 2n bits Divide produces both n bit quotient and n bit remainder Administrivia Computers in the News Computer numbers have limited size limited precision underflow too small for Fl Pt bigger negative exponent than can represent overflow too big for Fl Pt or integer bigger positive exponent than can represent or bigger integer than fits in word Programmers beware cs 61C L10 Start 3 Patterson Spring 99 UCB Compiling Assembling a Program Linking Loading a Program An Example Conclusion cs 61C L10 Start 4 Patterson Spring 99 UCB Floating Point Questions Negative 0 Big Idea Levels of Abstaction Unix DOS C program foo c foo txt What is result of this program main float i j Output i 1 0 j 0 0 Inf printf 3 1f n i j printf 3 1f n i j Inf printf 3 1f n j i j 0 0 if j i j 0 0 printf 0 0 0 0 n 0 0 0 0 else printf 0 0 0 0 n NaN printf 3 1f n i j i j printf 3 1f n i j i j i NaN Compiler Assembly program foo s foo asm Assembler Object mach lang module foo o foo obj Linker lib o lib obj Executable mach lang pgm a out foo exe Loader cs 61C L10 Start 5 Patterson Spring 99 UCB Assembler Memory Patterson Spring 99 UCB Example Assembly Program Directives Follow Directions Replace Pseudoinstructions Find list of labels addresses Produce machine language Creates Object File cs 61C L10 Start 7 cs 61C L10 Start 6 Patterson Spring 99 UCB addu t0 t6 1 text sw t0 28 sp align 2 ble t0 100 loop globl main la a0 str main lw a1 24 sp subu sp sp 32 jal printf sw ra 20 sp move v0 0 sd a0 32 sp lw ra 20 sp sw 0 24 sp addiu sp sp 32 sw 0 28 sp j ra loop data lw t6 28 sp align 0 mul t7 t6 t6 lw t8 24 sp str asciiz The sum addu t9 t8 t7 from 0 100 is sw t9 24 sp d n cs 61C L10 Start 8 Patterson Spring 99 UCB Assembler Directives p A 51 to A 53 Tell assembler how to translate program but do not produce machine instructions text addr Subsequent items put in user text segment starting at addr align n Align the next data on a 2n byte boundary align 2 next word boundary globl sym declares sym global and can be referenced from other files data addr Subsequent items put in user data segment starting at addr asciiz str Store the string str in memory and null terminate it cs 61C L10 Start 9 Patterson Spring 99 UCB Pseudoinstruction replacements Asm treats common variations of machine language instructions as if real instructions subu sp sp 32 addiu sp sp 32 sd a0 32 sp sw a0 32 sp sw a1 36 sp mul t7 t6 t6 mul t6 t6 mflo t7 addu t0 t6 1 addiu t0 t6 1 ble t0 100 loop slti at t0 101 bne at 0 loop la a0 str lui at left str ori a0 at right str move v0 0 cs 61C L10 Start 11 add v0 0 0 Patterson Spring 99 UCB Example Assembly Program PseudoInstr text align 2 globl main main subu sp sp 32 sw ra 20 sp sd a0 32 sp sw 0 24 sp sw 0 28 sp loop lw t6 28 sp mul t7 t6 t6 lw t8 24 sp addu t9 t8 t7 sw t9 24 sp cs 61C L10 Start 10 addu t0 t6 1 sw t0 28 sp ble t0 100 loop la a0 str lw a1 24 sp jal printf move v0 0 lw ra 20 sp addiu sp sp 32 j ra data align 0 str asciiz The sum from 0 100 is d n Patterson Spring 99 UCB Example Assembly Program Labels text align 2 globl main main subu sp sp 32 sw ra 20 sp sd a0 32 sp sw 0 24 sp sw 0 28 sp loop lw t6 28 sp mul t7 t6 t6 lw t8 24 sp addu t9 t8 t7 sw t9 24 sp cs 61C L10 Start 12 addu t0 t6 1 sw t0 28 sp ble t0 100 loop la a0 str lw a1 24 sp jal printf move v0 0 lw ra 20 sp addiu sp sp 32 j ra data align 0 str asciiz The sum from 0 100 is d n Patterson Spring 99 UCB Addresses Main job of Assembler Administrivia Readings 3 9 A 2 A 3 A 4 3 10 3 11 1 Find list of labels and their addresses 5th homework Due 2 24 7PM Exercises 4 21 4 25 4 28 2 Produce machine language Puts label and memory address of that instruction in Symbol Table Can use a name before it is defined forward reference e g str in example Note Must declare before use in C Patterson Spring 99 UCB Computers in the News Microsoft Denies Rumors That It Is Crafting a Language Like Java NY Times 2 15 99 Microsoft Corp is playing down a report in PC Week that it has been briefing software developers on a new programming language code named Cool that would be similar to Sun s Java software Java SW not binaries Cross platform means that a developer can write one version of a program in Java which can then run on Windows Macintosh Unix and other software operating systems A compiler …


View Full Document

Berkeley COMPSCI 61C - Lecture 10

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Loading Unlocking...
Login

Join to view Lecture 10 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 10 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?