Faux Midterm 1: Review Session
|
|
- Cynthia Welch
- 6 years ago
- Views:
Transcription
1 CS61C - Machine Structures... Faux Midterm 1: Review Session José María González ( cs61c-td) Electrical Engineering and Computer Science, U.C. Berkeley José María González. CS61C FM1 Review:... p.1/56
2 Outline Number Representation C, Pointers, Memory Management MIPS Programming MIPS Instruction Representation José María González. CS61C FM1 Review:... p.2/56
3 Outline Number Representation C, Pointers, Memory Management MIPS Programming MIPS Instruction Representation José María González. CS61C FM1 Review:... p.3/56
4 Number Representation Different Bases base 10 (Decimal): 0 9 base 16 (Hexadecimal): 0 9 A F 0x0ff00ff0 base 2 (Binary): 0, b José María González. CS61C FM1 Review:... p.4/56
5 Number Representation (cont.) Fixed Number of Digits decimal, 2 digits: 0 99 hexadecimal, 2 digits: 0 0xff (255) binary, 32 digits: (4 billion) Overflow result does not fit in (fixed) number of digits decimal, 2 digits: = 20 binary, 8 digits: b b = b José María González. CS61C FM1 Review:... p.5/56
6 Negative Numbers Use some of the values to represent negative numbers decimal, 2 digits: binary, 32 digits: -2 billion 2 billion Sign and Magnitude one bit for sign, rest for value e.g. +8 = b, -8 = b easy for us, hard for computers two zeros (+0= b, -0= b) José María González. CS61C FM1 Review:... p.6/56
7 Negative Numbers (cont.) One s Complement flip all bits (first bit acts as the sign) e.g. +8 = b, -8 = b hard for us, still hard for computers two zeros (+0= b, -0= b) José María González. CS61C FM1 Review:... p.7/56
8 Negative Numbers (cont.) Two s Complement flip all bits and add one (first bit acts as the sign) e.g. +8 = b, -8 = b hard for us, easy for computers one zero (0= b) more negative than positive numbers (-128= b, +128) José María González. CS61C FM1 Review:... p.8/56
9 Two s Complement Overflow can be positive or negative binary, 8 digits: b b = b rule: if result fits, then no overflow rule: if (operand have different signs) OR (result sign makes sense) then no overflow Sign Extension replicate most significative bit José María González. CS61C FM1 Review:... p.9/56
10 Masks: Extracting Bits Bitwise AND (&) and OR( ) operations AND mask (&) d AND 0 = 0 d AND 1 = d use 0 to zero unwanted values use 1 to keep wanted values OR mask ( ) d OR 0 = d d OR 1 = 1 José María González. CS61C FM1 Review:... p.10/56
11 Masks: Extracting Bits (cont.) AND mask (&) e.g. extract bits 5, 4, 3, and 1 from an 8-bit number d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 (n) & (mask) 0 0 d 5 d 4 d 3 0 d 1 0 (res) res = n & 0x3a; José María González. CS61C FM1 Review:... p.11/56
12 Shifts: Extracting and Locating Bits e.g. extract value of bits 6-3 from an 8-bit number d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 (n) & (mask) 0 d 6 d 5 d 4 d > > d 6 d 5 d 4 d 3 (res) res = (n & 0x78) > > 3; José María González. CS61C FM1 Review:... p.12/56
13 Outline Number Representation C, Pointers, Memory Management MIPS Programming MIPS Instruction Representation José María González. CS61C FM1 Review:... p.13/56
14 Pointer Operations A pointer to type A (A*) is different from a pointer to type B (B*) compiler will warn if assigning an A* to a B* void* is a generic pointer A** (a pointer to a pointer to type A) makes sense, but it s not the same type than B**, or A* José María González. CS61C FM1 Review:... p.14/56
15 Parameters by Reference Use pointers to modify parameters in functions (aka by reference ) example void increment (int x) { void increment (int *x) { x++; (*x)++; } } int j = 3; int j = 3; increment(j); increment(&j); // j is still 3! // j is 4 José María González. CS61C FM1 Review:... p.15/56
16 Pointer Initialization Uninitialized pointers point to nowhere (garbage) example int i = 5, *pi; *pi = i; // segfault? José María González. CS61C FM1 Review:... p.16/56
17 Arrays Arrays don t know their length (bounds are not checked) example int i[10]; i[25] = 23; // segfault? José María González. CS61C FM1 Review:... p.17/56
18 Pointer vs. Arrays Pointers vs. Arrays array is pointer to the first element example int *pi, ai[4] = {9, 7, 3, 5}; pi = ai; // *(pi+2), *(ai+2), pi[2], ai[2] refer to the number 3 José María González. CS61C FM1 Review:... p.18/56
19 Strings C Strings array of char s followed by a nul char (aka \0 or just 0) example char ac[5] = "hello"; // we re running into ac[5]! char ac[6] = "hello"; José María González. CS61C FM1 Review:... p.19/56
20 Pointer Arithmetics Address units are a function of the pointer object example char *pc = 0x ; int *pi = 0x ; // (pc+1), &pc[1] = 0x // (pi+1), or &pi[1] = 0x note that void is considered 1-byte long sizeof() returns size (in bytes) of a type or a variable José María González. CS61C FM1 Review:... p.20/56
21 Memory Management Three pools of memory static storage stack: local variables heap: dynamic memory José María González. CS61C FM1 Review:... p.21/56
22 Scope Static Storage vs. Stack variables declared outside procedures are allocated in static storage variables declared inside procedures are allocated in the stack stack variables are freed when procedure returns int a_global_variable goes_into_static_storage; int a_function () { int a_function_variable goes_into_stack; } José María González. CS61C FM1 Review:... p.22/56
23 Dynamic Memory Managed explicitly, using malloc() and free() ptr = (type_of_object *) malloc (number_of_objects * sizeof(type_of_object)); free(ptr); What you malloc, you must free otherwise you ll leak memory every malloc must have one and only one free José María González. CS61C FM1 Review:... p.23/56
24 Notes on C/malloc Exercise Hash Table your task is to write the create, destroy, insert, delete, and lookup operations for a hash table I provide headers and an implementation skeleton, including a (cheesy) hash_function operation I ll fill the skeleton during the review session José María González. CS61C FM1 Review:... p.24/56
25 Notes on C/malloc Exercise (cont.) Details use chaining to manage collisions that s why hash_node_t has a next field key is used to choose the bucket where the object (aka data) will be stored assume you can use the strings provided by the user (don t need to malloc and strcpy them) number of table buckets (hash t.size) does not change during table life José María González. CS61C FM1 Review:... p.25/56
26 Notes on Hash Tables Hash Table you should remember this from CS61B efficient structure to store {key,object} pairs assume key is a string, object just an integer operations insert(key, object) delete(key) lookup(key) object José María González. CS61C FM1 Review:... p.26/56
27 Notes on Exercises hash_node_t* hash_node_t hash_t size size data string key José María González. CS61C FM1 Review:... p.27/56
28 hash.h struct hash_node_t { int data; /* data in hash node */ const char *key; /* key for hash lookup */ struct hash_node_t *next; /* next node in hash chain */ }; struct hash_t { struct hash_node_t **bucket; /* array of hash nodes */ int size; /* size of the array */ }; #define HASH_FAIL -1 struct hash_t *hash_create (int); void hash_destroy (struct hash_t *); int hash_lookup (struct hash_t *, char *); int hash_insert (struct hash_t *, char *, int); int hash_delete (struct hash_t *, char *); José María González. CS61C FM1 Review:... p.28/56
29 Outline Number Representation C, Pointers, Memory Management MIPS Programming MIPS Instruction Representation José María González. CS61C FM1 Review:... p.29/56
30 MIPS Registers MIPS Registers $0: used to get zero temporal $a0, $a3: used to pass arguments to procs $v0, $v1: used to return results from procs $t0, $t9: temporary (can be modified by anyone) José María González. CS61C FM1 Review:... p.30/56
31 MIPS Registers (cont.) MIPS Registers saved (must be restored on return) $s0, $s7: saved $sp: stack pointer $ra: return address José María González. CS61C FM1 Review:... p.31/56
32 MIPS Etiquette (cont.) MIPS procs prologue body epilogue José María González. CS61C FM1 Review:... p.32/56
33 MIPS Etiquette (cont.) Body do the right thing can use any register, but follow etiquette can call other procs, but they will only respect etiquette temporary registers are saved by the caller saved registers are saved by the callee José María González. CS61C FM1 Review:... p.33/56
34 MIPS Etiquette (cont.) Prologue make space in the stack (move the stack pointer) addui $sp, $sp, -<amount> save $ra in the stack save registers you must restore in the stack José María González. CS61C FM1 Review:... p.34/56
35 MIPS Etiquette (cont.) Epilogue restore registers from the stack restore $ra from the stack fix the stack pointer addui $sp, $sp, +<amount> jr $ra José María González. CS61C FM1 Review:... p.35/56
36 Notes on Exercises strcat.s and bubble_sort.s translate to MIPS assembler Instruction Representation if you re given the instruction, write the machine code if you re given the machine code, disassemble it José María González. CS61C FM1 Review:... p.36/56
37 strcat.c char * strcat(char * dest, const char * src) { char *tmp = dest; while (*dest) dest++; while ((*dest++ = *src++)!= \0 ) ; } return tmp; José María González. CS61C FM1 Review:... p.37/56
38 strcat.s.text strcat: # char * strcat(char * dest, const char * src) # Function Parameters: # $a0 -> dest # $a1 -> src # $v0 <- return value # prologue # body # epilogue.end strcat José María González. CS61C FM1 Review:... p.38/56
39 strcat.s Body # char *tmp = dest; move $v0, $a0 # while (*dest) # dest++; first_while: lbu $t0,0($a0) addui $a0, $a0, 1 bne $t0,$0,first_while addui $a0, $a0, -1 José María González. CS61C FM1 Review:... p.39/56
40 strcat.s Body # while ((*dest++ = *src++)!= \0 ) # ; second_while: lbu $t1,0($a1) sbu $t1,0($a0) addui $a0, $a0, 1 addui $a1, $a1, 1 bne $t1,$0,second_while José María González. CS61C FM1 Review:... p.39/56
41 strcat.s P&E # prologue subu $sp,$sp,4 sw $ra,0($sp) # epilogue lw $ra,0($sp) addu $sp,$sp,4 j $ra José María González. CS61C FM1 Review:... p.40/56
42 bubble_sort.c void swap (int *list, int i, int j) { int tmp; tmp = *(list+i); *(list+i) = *(list+j); *(list+j) = tmp; } return; José María González. CS61C FM1 Review:... p.41/56
43 bubble_sort.c void bubblesort (int *list, int length) { int last_swap = 0; int i; int cur; while (last_swap!= length) { i = length; cur = length; while (i > last_swap) { if (*(list+i) < *(list+i-1)) { swap (list, i, i-1); cur = i; } i = i - 1; } last_swap = cur; } José María González. CS61C FM1 Review:... p.41/56
44 swap.s.text.globl swap swap: # void swap (int *list, int i, int j) # Function Parameters # $a0 -> *list # $a1 -> i # $a2 -> j # no return value # prologue # body # epilogue.end swap José María González. CS61C FM1 Review:... p.42/56
45 swap.s Body sll $a1,$a1,2 sll $a2,$a2,2 addu $t1, $a0, $a1 lw $t3, 0($t1) addu $t2, $a0, $a2 lw $t4, 0($t2) sw $t4, 0($t1) sw $t3, 0($t2) # $t1 <- (list+i) # $t3 <- *(list+i) # $t2 <- (list+j) # $t4 <- *(list+j) José María González. CS61C FM1 Review:... p.43/56
46 swap.s P&E # prologue subu $sp,$sp,4 sw $ra,0($sp) # epilogue lw $ra,0($sp) addu $sp,$sp,4 j $ra José María González. CS61C FM1 Review:... p.44/56
47 bubble_sort.s.text bubblesort: # void bubblesort (int *list, int length) # Function Parameters # $a0 -> list # $a1 -> length # no return value # $s0 <- last_swap # $s1 <- i # $s2 <- cur # prologue # body # epilogue José María González. CS61C FM1 Review:... p.45/56
48 bubble_sort.s Body # int last_swap = 0; move $s0, $zero # while (last_swap!= length) { beq $s0, $a1, epilog # i = length; move $s1, $a1 # cur = length; move $s2, $a1 # while (i > last_swap) { bgt $s1, $s0, out_second_while José María González. CS61C FM1 Review:... p.46/56
49 bubble_sort.s Body # if (*(list+i) < *(list+i-1)) { sll $t0, $s1, 2 addu $t1, $a0, $t0 # $t1 <- (list+i) addu $t2, $t1, -4 # $t2 <- (list+i-1) lw $t1, 0($t1) # $t1 <- *(list+i) lw $t2, 0($t2) # $t2 <- *(list+i-1) bge $t1, $t2, no_if # swap (list, i, i-1); lw $a0,4($sp) # $a0 <- list lw $a1, $s1 # $a1 <- i addu $a2, $a1, -1 # $a2 <- i-1 jal swap lw $a0,4($sp) lw $a1,8($sp) José María González. CS61C FM1 Review:... p.46/56
50 bubble_sort.s Body # cur = i; move $s2, $s1 no_if: # } # i = i - 1; subu $s1, $s1, 1 # } out_second_while: # last_swap = cur; move $s0, $s2 José María González. CS61C FM1 Review:... p.46/56
51 bubble_sort.s P&E # prologue # epilogue subu $sp,$sp,24 epilogue: sw $ra,0($sp) lw $ra,0($sp) sw $a0,4($sp) sw $a1,8($sp) sw $s0,12($sp) lw $s0,12($sp) sw $s1,16($sp) lw $s1,16($sp) sw $s2,20($sp) lw $s2,20($sp) subu $sp,$sp,-24 jr $ra José María González. CS61C FM1 Review:... p.47/56
52 Outline Number Representation C, Pointers, Memory Management MIPS Programming MIPS Instruction Representation José María González. CS61C FM1 Review:... p.48/56
53 R-Type Instructions XXX6XX XX5XX XX5XX XX5XX XX5XX XXX6XX opcode=0 rs rt rd shamt funct opcode is always zero function provides 6 bits to define the operation shamt used only in shift instructions rs, rt are the source registers rd is the destination register José María González. CS61C FM1 Review:... p.49/56
54 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
55 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
56 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
57 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
58 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
59 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
60 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
61 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.50/56
62 R-Type Instruction Example 1 Transform sltu $1, $9, $10 to MAL XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct A B 0x012A082B José María González. CS61C FM1 Review:... p.50/56
63 R-Type Instruction Example 2 Which instruction is 0x ? XXXXXX XXXXX XXXXX XXXXX XXXXX XXXXXX opcode rs rt rd shamt funct José María González. CS61C FM1 Review:... p.51/56
64 R-Type Instruction Example 2 Which instruction is 0x ? opcode rs rt rd shamt funct multu $2, $3 José María González. CS61C FM1 Review:... p.51/56
65 I-Type Instructions XXX6XX XX5XX XX5XX XXXXXXX16XXXXXXX opcode rs rt immediate opcode defines the operation rs are the source (base) registers rt is the target (destination) register immediate provides 16 bits to define immediate (offset) values José María González. CS61C FM1 Review:... p.52/56
66 I-Type Instruction Example 1 Transform lw $a0, -4($a1) to MAL José María González. CS61C FM1 Review:... p.53/56
67 I-Type Instruction Example 1 Transform lw $a0, -4($a1) to MAL lw $5, -4($6) XXXXXX XXXXX XXXXX XXXXXXXXXXXXXXXX opcode rs rt immediate C C 5 F F F C 0x8CC5FFFC José María González. CS61C FM1 Review:... p.53/56
68 I-Type Instruction Example 2 Which instruction is 0x0481FFFD? José María González. CS61C FM1 Review:... p.54/56
69 I-Type Instruction Example 2 Which instruction is 0x0481FFFD? F F F D XXXXXX XXXXX XXXXX XXXXXXXXXXXXXXXX opcode rs rt immediate back:inst inst bgez $4, back [ , -12] José María González. CS61C FM1 Review:... p.54/56
70 Appendix 1: BubbleSort Algorithm to order a list of numbers Input list [703,087,908,275,503] Output list [908,703,503,275,087] José María González. CS61C FM1 Review:... p.55/56
71 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
72 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
73 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
74 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
75 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
76 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
77 Bubble sort How it works Data Pass 1 Pass 2 Pass 3 Pass José María González. CS61C FM1 Review:... p.56/56
Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)
Lecture 2 Instructions: Language of the Computer (Chapter 2 of the textbook) Instructions: tell computers what to do Chapter 2 Instructions: Language of the Computer 2 Introduction Chapter 2.1 Chapter
More informationComputer Organization and Structure. Bing-Yu Chen National Taiwan University
Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing
More informationChapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )
Chapter 2 Computer Abstractions and Technology Lesson 4: MIPS (cont ) Logical Operations Instructions for bitwise manipulation Operation C Java MIPS Shift left >>> srl Bitwise
More informationMIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions
Representing Instructions Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register
More informationCOMPUTER ORGANIZATION AND DESIGN
COMPUTER ORGANIZATION AND DESIGN 5 th The Hardware/Software Interface Edition Chapter 2 Instructions: Language of the Computer 2.1 Introduction Instruction Set The repertoire of instructions of a computer
More informationI-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits
CS61C L10 MIPS Instruction Representation II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #10 Instruction Representation II 2007-7-8 Review There are register calling conventions!
More informationChapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes
Chapter 2 Instructions: Language of the Computer Adapted by Paulo Lopes Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects
More informationMIPS%Assembly% E155%
MIPS%Assembly% E155% Outline MIPS Architecture ISA Instruction types Machine codes Procedure call Stack 2 The MIPS Register Set Name Register Number Usage $0 0 the constant value 0 $at 1 assembler temporary
More informationCENG3420 Lecture 03 Review
CENG3420 Lecture 03 Review Bei Yu byu@cse.cuhk.edu.hk 2017 Spring 1 / 38 CISC vs. RISC Complex Instruction Set Computer (CISC) Lots of instructions of variable size, very memory optimal, typically less
More informationCS 61c: Great Ideas in Computer Architecture
MIPS Instruction Formats July 2, 2014 Review New registers: $a0-$a3, $v0-$v1, $ra, $sp New instructions: slt, la, li, jal, jr Saved registers: $s0-$s7, $sp, $ra Volatile registers: $t0-$t9, $v0-$v1, $a0-$a3
More informationNumbers: positional notation. CS61C Machine Structures. Faux Midterm Review Jaein Jeong Cheng Tien Ee. www-inst.eecs.berkeley.
CS 61C Faux Midterm Review (1) CS61C Machine Structures Faux Midterm Review 2002-09-29 Jaein Jeong Cheng Tien Ee www-inst.eecs.berkeley.edu/~cs61c/ Numbers: positional notation Number Base B B symbols
More informationMIPS Functions and Instruction Formats
MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other
More informationLecture 5: Procedure Calls
Lecture 5: Procedure Calls Today s topics: Memory layout, numbers, control instructions Procedure calls 1 Memory Organization The space allocated on stack by a procedure is termed the activation record
More informationECE 15B Computer Organization Spring 2010
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 7: Procedures I Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy, and classes taught by and
More informationBranch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015
Branch Addressing Branch instructions specify Opcode, two registers, target address Most branch targets are near branch Forward or backward op rs rt constant or address 6 bits 5 bits 5 bits 16 bits PC-relative
More informationInstructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1
Instructions: MIPS ISA Chapter 2 Instructions: Language of the Computer 1 PH Chapter 2 Pt A Instructions: MIPS ISA Based on Text: Patterson Henessey Publisher: Morgan Kaufmann Edited by Y.K. Malaiya for
More informationOverview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)
Introduction to the MIPS ISA Overview Remember that the machine only understands very basic instructions (machine instructions) It is the compiler s job to translate your high-level (e.g. C program) into
More informationIntroduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University
Introduction to the MIPS Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS The Microprocessor without Interlocked Pipeline Stages
More informationControl Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary
Control Instructions Computer Organization Architectures for Embedded Computing Thursday, 26 September 2013 Many slides adapted from: Computer Organization and Design, Patterson & Hennessy 4th Edition,
More informationControl Instructions
Control Instructions Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class Instruction Set
More informationUCB CS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Guest Lecturer Alan Christopher Lecture 08 MIPS Instruction Representation I 2014-02-07 BOINC MORE THAN JUST SETI@HOME BOINC (developed here
More informationCS 110 Computer Architecture MIPS Instruction Formats
CS 110 Computer Architecture MIPS Instruction Formats Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University Slides based
More informationChapter 2. Instructions: Language of the Computer
Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers
More informationReview. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations
CS6C L9 MIPS Logical & Shift Ops, and Instruction Representation I () inst.eecs.berkeley.edu/~cs6c CS6C : Machine Structures Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I 25-9-28
More informationCISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization
CISC 662 Graduate Computer Architecture Lecture 4 - ISA MIPS ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,
More informationUniversity of California, Berkeley College of Engineering
University of California, Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences Fall 2015 Instructors: Vladimir Stojanovic, John Wawrzynek 2015-09-06 L J After the
More informationComputer Organization and Structure. Bing-Yu Chen National Taiwan University
Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing
More informationThomas Polzer Institut für Technische Informatik
Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Branch to a labeled instruction if a condition is true Otherwise, continue sequentially beq rs, rt, L1 if (rs == rt) branch to
More informationChapter 2A Instructions: Language of the Computer
Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction
More informationMachine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine
Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction
More informationCISC 662 Graduate Computer Architecture. Lecture 4 - ISA
CISC 662 Graduate Computer Architecture Lecture 4 - ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,
More informationCOMPSCI 313 S Computer Organization. 7 MIPS Instruction Set
COMPSCI 313 S2 2018 Computer Organization 7 MIPS Instruction Set Agenda & Reading MIPS instruction set MIPS I-format instructions MIPS R-format instructions 2 7.1 MIPS Instruction Set MIPS Instruction
More informationUCB CS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS Procedures I Sr Lecturer SOE Dan Garcia 2014-02-14 If cars broadcast their speeds to other vehicles (and the
More informationCSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.
CSCI 402: Computer Architectures Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI Recall Big endian, little endian Memory alignment Unsigned
More informationMIPS Functions and the Runtime Stack
MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline
More informationCS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.
CS61C Machine Structures Lecture 12 - MIPS Procedures II & Logical Ops 2/13/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L12 MIPS Procedures II / Logical (1)
More informationLecture 4: MIPS Instruction Set
Lecture 4: MIPS Instruction Set No class on Tuesday Today s topic: MIPS instructions Code examples 1 Instruction Set Understanding the language of the hardware is key to understanding the hardware/software
More informationWe will study the MIPS assembly language as an exemplar of the concept.
MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and
More information8*4 + 4 = 36 each int is 4 bytes
CS 61CL (Clancy) Solutions and grading standards for exam 1 Spring 2009 169 students took the exam. The average score was 43.6; the median was 46. Scores ranged from 1 to 59. There were 89 scores between
More informationMemory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention
Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack
More informationcomp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions
Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Procedure Calls A procedure of a subroutine is like an agent which needs certain information to perform a
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #8: MIPS Procedures 2005-06-30 CS 61C L08 MIPS Procedures (1) Andy Carle Topic Outline Functions More Logical Operations CS 61C L08
More informationMIPS Instruction Set Architecture (2)
MIPS Instruction Set Architecture (2) Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu
More informationLecture 7: Procedures
Lecture 7: Procedures CSE 30: Computer Organization and Systems Programming Winter 2010 Rajesh Gupta / Ryan Kastner Dept. of Computer Science and Engineering University of California, San Diego Outline
More informationCourse Administration
Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701
More information101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009
101 Assembly ENGR 3410 Computer Architecture Mark L. Chang Fall 2009 What is assembly? 79 Why are we learning assembly now? 80 Assembly Language Readings: Chapter 2 (2.1-2.6, 2.8, 2.9, 2.13, 2.15), Appendix
More informationUniversity of California, Berkeley College of Engineering
University of California, Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences Fall 2015 Instructors: Vladimir Stojanovic, John Wawrzynek 2015-09-06 After the exam,
More informationUnsigned Binary Integers
Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0
More informationECE260: Fundamentals of Computer Engineering
Accessing and Addressing Memory James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy American
More informationUnsigned Binary Integers
Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0
More informationECE232: Hardware Organization and Design. Computer Organization - Previously covered
ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization
More informationComputer Architecture I Midterm I
Computer Architecture I Midterm I April 11 2017 Computer Architecture I Midterm I Chinese Name: Pinyin Name: E-Mail... @shanghaitech.edu.cn: Question Points Score 1 1 2 12 3 16 4 14 5 18 6 17 7 22 Total:
More informationECE260: Fundamentals of Computer Engineering
MIPS Instruction Set James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy MIPS Registers MIPS
More informationCS 61c: Great Ideas in Computer Architecture
MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures $2M 3D camera Lecture 8 MIPS Instruction Representation I Instructor: Miki Lustig 2014-09-17 August 25: The final ISA showdown: Is ARM, x86, or
More informationEE 361 University of Hawaii Fall
C functions Road Map Computation flow Implementation using MIPS instructions Useful new instructions Addressing modes Stack data structure 1 EE 361 University of Hawaii Implementation of C functions and
More informationInstructions: Language of the Computer
CS359: Computer Architecture Instructions: Language of the Computer Yanyan Shen Department of Computer Science and Engineering 1 The Language a Computer Understands Word a computer understands: instruction
More informationEEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture
EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 Overview Instruction Representation Big idea: stored program consequences of stored program Instructions as numbers Instruction
More informationRui Wang, Assistant professor Dept. of Information and Communication Tongji University.
Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood
More informationReview 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.
CS61C Negative Numbers and Logical Operations cs 61C L7 Number.1 Lecture 7 February 10, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html Review 1/2
More informationReduced Instruction Set Computer (RISC)
Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying
More informationComputer Architecture
Computer Architecture Chapter 2 Instructions: Language of the Computer Fall 2005 Department of Computer Science Kent State University Assembly Language Encodes machine instructions using symbols and numbers
More informationReduced Instruction Set Computer (RISC)
Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the machine. Reduced number of cycles needed per instruction.
More informationComputer Architecture. The Language of the Machine
Computer Architecture The Language of the Machine Instruction Sets Basic ISA Classes, Addressing, Format Administrative Matters Operations, Branching, Calling conventions Break Organization All computers
More informationECE260: Fundamentals of Computer Engineering
MIPS Instruction Set James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy MIPS Registers MIPS
More informationArchitecture II. Computer Systems Laboratory Sungkyunkwan University
MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to a
More informationLevels of Programming. Registers
Levels of Programming COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1. Arithmetic Instructions 2.
More informationENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design
ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer
More informationCS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats
CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats Instructors: Bernhard Boser and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa16 9/15/16 Fall 2016 - Lecture #7 1 Review: Basic
More informationCENG3420 L03: Instruction Set Architecture
CENG3420 L03: Instruction Set Architecture Bei Yu byu@cse.cuhk.edu.hk (Latest update: January 31, 2018) Spring 2018 1 / 49 Overview Introduction Arithmetic & Logical Instructions Data Transfer Instructions
More informationCSCI 402: Computer Architectures
CSCI 402: Computer Architectures Instructions: Language of the Computer (2) Fengguang Song Department of Computer & Information Science IUPUI Memory Operands Two tribes: Big Endian: Most-significant byte
More informationCS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats
CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats Instructor: Justin Hsia 6/27/2012 Summer 2012 Lecture #7 1 Review of Last Lecture New registers: $a0-$a3, $v0-$v1, $ra, $sp Also: $at,
More informationProcedure Call and Return Procedure call
Procedures int len(char *s) { for (int l=0; *s!= \0 ; s++) l++; main return l; } void reverse(char *s, char *r) { char *p, *t; int l = len(s); reverse(s,r) N/A *(r+l) = \0 ; reverse l--; for (p=s+l t=r;
More informationDo-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero
Do-While Example In C++ do { z--; while (a == b); z = b; In assembly language loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero 25 Comparisons Set on less than (slt) compares its source registers
More informationLecture 7: Procedures and Program Execution Preview
Lecture 7: Procedures and Program Execution Preview CSE 30: Computer Organization and Systems Programming Winter 2010 Rajesh Gupta / Ryan Kastner Dept. of Computer Science and Engineering University of
More informationMips Code Examples Peter Rounce
Mips Code Examples Peter Rounce P.Rounce@cs.ucl.ac.uk Some C Examples Assignment : int j = 10 ; // space must be allocated to variable j Possibility 1: j is stored in a register, i.e. register $2 then
More informationProblem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts
University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences CS61c Summer 2001 Woojin Yu Midterm Exam This is a closed-book exam. No calculators
More informationMath 230 Assembly Programming (AKA Computer Organization) Spring 2008
Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1
More informationInstructions: Language of the Computer
Instructions: Language of the Computer Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class
More informationAnd in Review. Register Conventions (2/4) saved. Register Conventions (1/4) Register Conventions (4/4) Register Conventions (3/4) volatile
CS61C L09 Introduction to MIPS : Procedures II, Logical Ops & Inst Fmt I (1) Instructor Paul Pearce inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 9 Introduction to MIPS Procedures
More informationChapter 2. Baback Izadi Division of Engineering Programs
Chapter 2 Baback Izadi Division of Engineering Programs bai@engr.newpaltz.edu Instruction Set Language of the Machine The repertoire of instructions of a computer Different computers have different instruction
More informationComputer Hardware Engineering
2 Course Structure Computer Hardware ngineering IS1200, spring 2015 Lecture 3: Languages Module 4: I/O Systems Module 1: Logic Design L DCÖ1 L DCÖ2 Lab:dicom L7 Module 2: C and Assembly Programming Associate
More informationWawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,
Wawrzynek & Weaver CS 61C Sp 2018 Great Ideas in Computer Architecture MT 1 Print your name:, (last) (first) I am aware of the Berkeley Campus Code of Student Conduct and acknowledge that any academic
More informationInstruction Set Architecture part 1 (Introduction) Mehran Rezaei
Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Overview Last Lecture s Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a
More informationMIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support
Components of an ISA EE 357 Unit 11 MIPS ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible
More informationChapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.
Chapter 2 Instructions: Language of the Computer HW#1: 1.3 all, 1.4 all, 1.6.1, 1.14.4, 1.14.5, 1.14.6, 1.15.1, and 1.15.4 Due date: one week. Practice: 1.5 all, 1.6 all, 1.10 all, 1.11 all, 1.14 all,
More informationComputer Architecture Computer Science & Engineering. Chapter 2. Instructions: Language of the Computer BK TP.HCM
Computer Architecture Computer Science & Engineering Chapter 2 Instructions: Language of the Computer Computer Component 25-Aug-16 Faculty of Computer Science & Engineering 2 Instruction execution process
More informationComputer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:
Computer Science and Engineering 331 Midterm Examination #1 Fall 2000 Name: Solutions S.S.#: 1 41 2 13 3 18 4 28 Total 100 Instructions: This exam contains 4 questions. It is closed book and notes. Calculators
More informationCS3350B Computer Architecture MIPS Instruction Representation
CS3350B Computer Architecture MIPS Instruction Representation Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada
More informationAnnouncements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls
Announcements HW1 is due on this Friday (Sept 12 th ) Appendix A is very helpful to HW1. Check out system calls on Page A-48. Ask TA (Liquan chen: liquan@ece.rutgers.edu) about homework related questions.
More informationMachine Instructions - II. Hwansoo Han
Machine Instructions - II Hwansoo Han Conditional Operations Instructions for making decisions Alter the control flow - change the next instruction to be executed Branch to a labeled instruction if a condition
More informationCS61c MIDTERM EXAM: 3/17/99
CS61c MIDTERM EXAM: 3/17/99 D. A. Patterson Last name Student ID number First name Login: cs61c- Please circle the last two letters of your login name. a b c d e f g h i j k l m n o p q r s t u v w x y
More informationAssembler. Lecture 8 CS301
Assembler Lecture 8 CS301 Discussion Given the following function header, int foo(int a, int b); what will be on the stack before any of the calculations in foo are performed? Assume foo() calls some other
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #9: MIPS Procedures 2006-07-11 CS 61C L09 MIPS Procedures (1) Andy Carle C functions main() { int i,j,k,m;... i = mult(j,k);... m =
More informationComputer Architecture
CS3350B Computer Architecture Winter 2015 Lecture 4.2: MIPS ISA -- Instruction Representation Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted from lectures on Computer Organization and Design,
More informationCS 61C: Great Ideas in Computer Architecture. More MIPS, MIPS Functions
CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions Instructor: Justin Hsia 7/02/2013 Summer 2013 Lecture #6 1 Review of Last Lecture (1/2) RISC Design Principles Smaller is faster:
More informationENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5
ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5 MIPS/SPIM General Purpose Registers Powers of Two 0 $zero all bits are zero 16 $s0 local variable 1 $at assembler temporary 17 $s1 local
More informationComputer Architecture Instruction Set Architecture part 2. Mehran Rezaei
Computer Architecture Instruction Set Architecture part 2 Mehran Rezaei Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a MIPS Interpreter
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 13 Introduction to MIPS Instruction Representation I Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Anyone seen Terminator? Military
More informationMIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types
1 Lecture 08 Introduction to the MIPS ISA + Procedure Calls in MIPS Longer instructions = more bits to address registers MIPS Datapath 6 bit opcodes... 2 MIPS Instructions are 32 bits More ways to address
More information