September 5 Fang-Yi’s Office Hours Friday 10am  12pm (and another TBD) Programming Language Issues (JAVA vs. C, Pointers vs. Arrays) Representations Instructions.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
The University of Adelaide, School of Computer Science
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
The University of Adelaide, School of Computer Science
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Systems Architecture Lecture 5: MIPS Instruction Set
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
The University of Adelaide, School of Computer Science
Procedure call frame: Hold values passed to a procedure as arguments
L5 – Addressing Modes 1 Comp 411 – Spring /29/08 Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection.
CS 536 Spring Code generation I Lecture 20.
Intro to Computer Architecture
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
August 26 TA: Angela Van Osdol Questions?. What is a computer? Tape drives? Big box with lots of lights? Display with huge letters? Little box with no.
9/14/2004Comp 120 Fall September 2004 First Exam next Tuesday 21 September Programming Questions? All of Chapter 3 and Appendix A are relevant.
1 CS/COE0447 Computer Organization & Assembly Language Pre-Chapter 2.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Character Data and 32-bit Constants (Lecture #20) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 4: MIPS Instruction Set
Computer Organization and Design Addressing Modes Montek Singh Wed, Sep 19, 2012 Lecture 6.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Computer Organization and Design Pointers, Arrays and Strings in C
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
Lecture 6: Assembly Programs
CS2100 Computer Organisation
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
The University of Adelaide, School of Computer Science
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
ECE/CS 552: Instruction Sets – MIPS
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Systems Architecture Lecture 5: MIPS Instruction Set
Computer Organization and Design Addressing Modes
Henk Corporaal TUEindhoven 2010
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Operands and Addressing Modes
October 1 Programming Questions?
The University of Adelaide, School of Computer Science
CS/COE0447 Computer Organization & Assembly Language
August 29 New address for Fang-Yi
Computer Instructions
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Lecture 6: Assembly Programs
Instructions in Machine Language
COMS 361 Computer Organization
January 16 The books are here. Assignment 1 now due Thursday 18 Jan.
Computer Organization and Design Addressing Modes
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Operands and Addressing Modes
9/27: Lecture Topics Memory Data transfer instructions
7/6/
August 31 addresses Drop box Questions? 31 August 2004
9/13/
MIPS Assembly.
Presentation transcript:

September 5 Fang-Yi’s Office Hours Friday 10am  12pm (and another TBD) Programming Language Issues (JAVA vs. C, Pointers vs. Arrays) Representations Instructions 12/5/2018 Comp 120 Fall 2001

Just enough C For our purposes C is almost identical to JAVA except: C has “functions”, JAVA has “methods”. function == method without “class”. A global method. C has “pointers” explicitly. JAVA has them but hides them under the covers. 12/5/2018 Comp 120 Fall 2001

C pointers int i; // simple integer variable int a[10]; // array of integers int *p; // pointer to integer(s) *(expression) is content of address computed by expression. a[k] == *(a+k) a is a constant of type “int *” a[k] = a[k+1] EQUIV *(a+k) = *(a+k+1) 12/5/2018 Comp 120 Fall 2001

Legal uses of C Pointers p = &i; // & means address of p = a; // no need for & on a p = &a[5]; // address of 6th element of a *p // value of location pointed by p *p = 1; // change value of that location *(p+1) = 1; // change value of next location p[1] = 1; // exactly the same as above p++; // step pointer to the next element So what happens when p = &i; What is value of p[0]? What is value of p[1]? 12/5/2018 Comp 120 Fall 2001

C Pointers vs. object size Does “p++” really add 1 to the pointer? NO! It adds 4. Why 4? char *q; ... q++; // really does add 1 12/5/2018 Comp 120 Fall 2001

Clear123 void clear1(int array[], int size) { for(int i=0; i<size; i++) array[i] = 0; } void clear2(int *array, int size) { for(int *p = &array[0]; p < &array[size]; p++) *p = 0; void clear3(int *array, int size) { int *arrayend = array + size; while(array < arrayend) *array++ = 0; 12/5/2018 Comp 120 Fall 2001

Pointer summary In the “C” world and in the “machine” world: a pointer is just the address of an object in memory size of pointer is fixed regardless of size of object to get to the next object increment by the objects size in bytes to get the the ith object add i*sizeof(object) More details: int R[5]  R is int* constant address of 20 bytes R[i]  *(R+i) int *p = &R[3]  p = (R+3) (p points 12 bytes after R) 12/5/2018 Comp 120 Fall 2001

Representations You need to know your powers of 2! 1 2 4 8 16 32 64 2^0 2^1 2^2 2^3 2^4 2^5 2^6 2^7 2^8 2^9 2^10 2^20 2^30 1 2 4 8 16 32 64 128 256 512 1k=1024 1M 1G 12/5/2018 Comp 120 Fall 2001

Pointer Size vs. Addressable Space Pointers ARE addresses Number of unique addresses for N bits is 2^N With addresses that are 32 bits long you can address 4G bytes With addresses that are 13 bits long you can address 8k bytes that’s 2k words 12/5/2018 Comp 120 Fall 2001

C versus ASM Swap: muli $t0, $a1, 4 add $t0, $a0, $t0 lw $t1, 0($t0) lw $t2, 4($t0) sw $t2, 0($t0) sw $t1, 4($t0) jr $ra Swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } 12/5/2018 Comp 120 Fall 2001

Form of the Instructions Opcode Register (usually result destination) Operand 1 Operand 2 e.g. add $t0, $a0, $t0 12/5/2018 Comp 120 Fall 2001

This is all just software “convention” Naming Registers This is all just software “convention” $a0 - $a3 arguments to functions $v0 - $v1 results from functions $ra return address $s0 - $s7 “saved” registers $t0 - $t9 “temporary” registers $sp stack pointer 12/5/2018 Comp 120 Fall 2001

What are the operands? Registers e.g. $a0 With load and store this is logical enough But small constants are VERY common So, some instructions allow “immediate” operands. E.g. muli $t0, $a1, 4 Where do we get big constants? 12/5/2018 Comp 120 Fall 2001

C versus ASM Swap: muli $t0, $a1, 4 add $t0, $a0, $t0 lw $t1, 0($t0) lw $t2, 4($t0) sw $t2, 0($t0) sw $t1, 4($t0) jr $ra Swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } 12/5/2018 Comp 120 Fall 2001

Next: Performance Measure, Report, and Summarize Make intelligent choices See through the marketing hype Key to understanding underlying organizational motivation Why is some hardware better than others for different programs? What factors of system performance are hardware related? (e.g., Do we need a new machine, or a new operating system?) How does the machine's instruction set affect performance? 12/5/2018 Comp 120 Fall 2001