9/14/2004Comp 120 Fall 20041 14 September 2004 First Exam next Tuesday 21 September Programming Questions? All of Chapter 3 and Appendix A are relevant.

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.
CS/COE0447 Computer Organization & Assembly Language
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Computer Architecture CSCE 350
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
Craig Schock, 2003 Binary Numbers Numbering Systems Counting Symbolic Bases Common Bases (10, 2, 8, 16) Representing Information Binary to Decimal Conversions.
L5 – Addressing Modes 1 Comp 411 – Spring /29/08 Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection.
EECC250 - Shaaban #1 lec #13 Winter HEX DEC CHR Ctrl 00 0NUL 01 1 SOH ^A 02 2STX ^B 03 3ETX ^C 04 4EOT ^D 05 5ENQ ^E 06 6ACK ^F 07 7BEL.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
The character data type char
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
Digital Design: From Gates to Intelligent Machines
Decimal Binary Octal Hex
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
Dept. of Computer Science Engineering Islamic Azad University of Mashhad 1 DATA REPRESENTATION Dept. of Computer Science Engineering Islamic Azad University.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Informatics I101 February 25, 2003 John C. Paolillo, Instructor.
Postacademic Interuniversity Course in Information Technology – Module C1p1 Chapter 1 Evolution of Communication Networks.
Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
CSCI 136 Lab 1: 135 Review.
Character Data and 32-bit Constants (Lecture #20) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Lecture 4: MIPS Instruction Set
Computer Organization and Design Addressing Modes Montek Singh Wed, Sep 19, 2012 Lecture 6.
1 Information Representation in Computer Lecture Nine.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic5: Linking José Nelson Amaral.
CS 2130 Lecture 23 Data Types.
Systems Architecture, Fourth Edition 1 Data Representation Chapter 3.
1 CS232 Exam 1 Solutions February 20, 2004 Name:  This exam has 5 pages, including this cover.  There are three questions, worth a total of 100 points.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Programming for GCSE Topic 2.2: Binary Representation T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science.
PRIMITIVE TYPES IN JAVA Primitive Types Operations on Primitive Types.
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Computer Organization and Design Pointers, Arrays and Strings in C
Machine level representation of data Character representation
C Programming Language Review and Dissection
Lecture 6: Assembly Programs
Chapter 2 Data Types and Representations
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Javascript, Loops, and Encryption
CSCI206 - Computer Organization & Programming
Chapter 2 Bits, Data Types, and Operations
ASCII Character Codes nul soh stx etx eot 1 lf vt ff cr so
MIPS Instructions.
Operands and Addressing Modes
October 1 Programming Questions?
September 5 Fang-Yi’s Office Hours Friday 10am  12pm (and another TBD) Programming Language Issues (JAVA vs. C, Pointers vs. Arrays) Representations Instructions.
Cosc 2P12 Week 2.
Part II Instruction-Set Architecture
Number Systems Lecture 2.
Text Encoding.
Lecture 6: Assembly Programs
Introduction to Computer Engineering
Rayat Shikshan Sanstha’s S. M. Joshi College, Hadapsar
Text Representation ASCII Collating Sequence
Computer Organization and Design Addressing Modes
Operands and Addressing Modes
Cosc 2P12 Week 2.
August 31 addresses Drop box Questions? 31 August 2004
Chapter 2 Bits, Data Types, and Operations
Presentation transcript:

9/14/2004Comp 120 Fall September 2004 First Exam next Tuesday 21 September Programming Questions? All of Chapter 3 and Appendix A are relevant and helpful to your programming assignments. More programming issues…

9/14/2004Comp 120 Fall 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; }

9/14/2004Comp 120 Fall clear1 void clear1(int array[], int size) { for(int i=0; i<size; i++) array[i] = 0; } move$t0,$zero# i = 0 for1: slt$t1, $t0, $a1 beq$t1, $zero, for2# break if i >= size muli$t1, $t0, 4# t1 = i*4 add$t1, $a0, $t1# t1 = &array[i] sw$zero, 0($t1)# *t1 = 0 addi$t0, $t0, 1# i++ jfor1 for2: jr $ra

9/14/2004Comp 120 Fall clear2 void clear2(int *array, int size) { for(int *p = &array[0]; p < &array[size]; p++) *p = 0; } move$t0, $a0# p = array for1: muli$t1, $a1, 4# t1 = 4*size add$t1, $a0, $t1# t1 = &array[size] slt$t2, $t0, $t1 beq$t2, $zero, for2# break if p >= t1 sw$zero, 0($t0)# *p = 0; addi$t0, $t0, 4# p++ jfor1 for2: jr$ra

9/14/2004Comp 120 Fall clear2 (slightly smarter) void clear2(int *array, int size) { for(int *p = &array[0]; p < &array[size]; p++) *p = 0; } move$t0, $a0# p = array muli$t1, $a1, 4# t1 = 4*size add$t1, $a0, $t1# t1 = &array[size] for1: slt$t2, $t0, $t1 beq$t2, $zero, for2# break if p >= t1 sw$zero, 0($t0)# *p = 0; addi$t0, $t0, 4# p++ jfor1 for2: jr$ra

9/14/2004Comp 120 Fall clear3 void clear3(int *array, int size) { int *arrayend = array + size; while(array < arrayend) *array++ = 0; } muli$t1, $a1, 4# t1 = 4*size add$t1, $a0, $t1# t1 = &array[size] for1: slt$t2, $a0, $t1 beq$t2, $zero, for2# break if array >= t1 sw$zero, 0($a0)# *array = 0; addi$a0, $a0, 4# array++ jfor1 for2: jr$ra

9/14/2004Comp 120 Fall 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 i th 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)

9/14/2004Comp 120 Fall Big Constants The MIPS architecture only allows immediate constants to be 16 bits So how do we get bigger constants? lui sets the upper 16 bits from the 16 bit immediate field ori will “or” into the lower 16 bits from the immediate field How to break your BIG number into the required two 16 bit chunks? hi = BIG / 64k(e.g. 4,000,000 / 64k == 61) lo = BIG % 64k(e.g. 4,000,000 % 64k == 2304) lui$t0, hi ori$t0, $t0, lo

9/14/2004Comp 120 Fall 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

9/14/2004Comp 120 Fall Endians? Consider the following code foo:.word0# foo is a 32 bit int li$t0, 1# t0 = 1 la$t1, foo# t1 = &foo sb$t0, 0($t1)# stores a byte at foo What is the value of the WORD at foo? In other words what is the value of register t2 after: lw$t2, 0($t1)# what is in t2? Little Endian  t2 == 0x == 1 Big Endian  t2 == 0x == 16M

9/14/2004Comp 120 Fall Endians? Consider the following code foo:.word0# foo is a 32 bit int li$t0, 1# t0 = 1 la$t1, foo# t1 = &foo sb$t0, 1($t1)# stores a byte at foo+1 What is the value of the WORD at foo? In other words what is the value of register t2 after: lw$t2, 0($t1)# what is in t2? Little Endian  t2 == 0x == 256 Big Endian  t2 == 0x == 64k

9/14/2004Comp 120 Fall Endians? Consider the following code foo:.word0# foo is a 32 bit int li$t0, 1# t0 = 1 la$t1, foo# t1 = &foo sb$t0, 2($t1)# stores a byte at foo+2 What is the value of the WORD at foo? In other words what is the value of register t2 after: lw$t2, 0($t1)# what is in t2? Little Endian  t2 == 0x == 64k Big Endian  t2 == 0x == 256

9/14/2004Comp 120 Fall Endians? Consider the following code foo:.word0# foo is a 32 bit int li$t0, 1# t0 = 1 la$t1, foo# t1 = &foo sb$t0, 3($t1)# stores a byte at foo+3 What is the value of the WORD at foo? In other words what is the value of register t2 after: lw$t2, 0($t1)# what is in t2? Little Endian  t2 == 0x == 16M Big Endian  t2 == 0x == 1

9/14/2004Comp 120 Fall Endians? Consider the following code foo:.ascii “Gary” # foo takes 4 bytes, 32 bits la$t1, foo# t1 = &foo What is the value of the WORD at foo? In other words what is the value of register t2 after: lw$t2, 0($t1)# what is in t2? Little Endian  t2 == 0x Big Endian  t2 == 0x On BOTH machines: lb$t3, 0($t1)# t3 == ‘G’

9/14/2004Comp 120 Fall ASCII Chart A B C D E F 0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI 1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 SP ! " # $ % & ' ( ) * +, -. / : ; ? A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h i j k l m n o 7 p q r s t u v w x y z { | } ~ DEL

9/14/2004Comp 120 Fall Hex Numbers in hex are commonly preceded by 0x –0x1 == 1, 0x10 == 16, etc. Hex is cool because each digit corresponds to 4 bits 0x0==0000b, 0x1==0001b, 0x2==0010b, 0x3==0011b 0x4==0100b, 0x5==0101b, 0x6==0110b, 0x7==0111b 0x8==1000b, 0x9==1001b, 0xA==1010b, 0xB==1011b 0xC==1100b, 0xD==1101b, 0xE==1110b, 0xF==1111b So hex to binary is EASY! 0x2A == b 0x8001 == b binary to hex is easy too! b == 0x87A0

9/14/2004Comp 120 Fall Choosing Registers Arguments in $a0-3 Results in $v0-1 In a “leaf” function –use $t0-7 for everything and you won’t have to save and restore anything –if you need more then save $s0-7, use them, and then restore at end In a “non-leaf” function –use $t0-7 for temps that don’t need to be saved across calls –use $s0-7 for variables that you need across calls Always save $s0-7, $ra, $sp if you modify them. Use memory pointed to by $sp to save and restore registers, allocate arrays, etc.

9/14/2004Comp 120 Fall pseudo instructions They aren’t REAL instructions You can think of them as –shorthand –macros –inline functions –syntactic sugar They are supposed to make your life easier and your programs easier to read –move $t1,$t0  add $t1, $t0, $zero –la $t0,foo  lui $t0, UPPER16(foo) ori $t0, LOWER16(foo) –li $t0, 23  addi $t0, $zero, 23 –li $t0, 0x2300AB  lui $t0, 0x23 ori $t0, 0x00AB