Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists.

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
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
Chapter 3 Instruction Set Architecture Advanced Computer Architecture COE 501.
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.
10/6: Lecture Topics Procedure call Calling conventions The stack
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
ELEN 468 Advanced Logic Design
Chapter 2.
Computer Architecture CSCE 350
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
CS153 Greg Morrisett. Quick overview of the MIPS instruction set.  We're going to be compiling to MIPS assembly language.  So you need to know how to.
CS 536 Spring Code generation I Lecture 20.
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
RISC Concepts, MIPS ISA and the Mini–MIPS project
RISC. Rational Behind RISC Few of the complex instructions were used –data movement – 45% –ALU ops – 25% –branching – 30% Cheaper memory VLSI technology.
4/6/08Prof. Hilfinger CS164 Lecture 291 Code Generation Lecture 29 (based on slides by R. Bodik)
6.828: PC hardware and x86 Frans Kaashoek
Processor Architecture: The Y86 Instruction Set Architecture
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1 CS232: Computer Architecture II Fall 2011 Intel i7 Quad-core.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Oct. 25, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Alternative Instruction Sets * Jeremy R. Johnson Wed. Oct. 25, 2000.
CHAPTER 6 Instruction Set Architecture 12/7/
MS108 Computer System I Lecture 3 ISA Prof. Xiaoyao Liang 2015/3/13 1.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
1 CS232: Computer Architecture II Fall 2010 AMD dual-core Opteron.
ISA's, Compilers, and Assembly
CS232: Computer Architecture II
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
Computer Organization Instructions Language of The Computer (MIPS) 2.
ARM (Advanced RISC Machine; initially Acorn RISC Machine) Load/store architecture 65 instructions (all fixed length – one word each = 32 bits) 16 registers.
Computer Architecture & Operations I
A job ad at a game programming company
Function Calls in MIPS To call a function: jal func
Assembly language.
Prof. Hsien-Hsin Sean Lee
Lecture 6: Assembly Programs
A Closer Look at Instruction Set Architectures
Instruction Set Architecture
Function Calls in MIPS To call a function: jal func
ISA's, Compilers, and Assembly
Announcements MP 3 CS296 (Chase Geigle
ELEN 468 Advanced Logic Design
Computer skills CPU Jakub Yaghob.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
A Closer Look at Instruction Set Architectures
Basics Of X86 Architecture
MIPS Assembly.
Computer Architecture adapted by Jason Fritts then by David Ferry
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Lecture 30 (based on slides by R. Bodik)
MIPS Procedure Calls CSE 378 – Section 3.
MIPS function continued
Computer Instructions
Introduction to Microprocessor Programming
COMS 361 Computer Organization
CPU Structure CPU must:
Lecture 4: Instruction Set Design/Pipelining
9/27: Lecture Topics Memory Data transfer instructions
Instruction Set Architecture
Presentation transcript:

Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists of 8 bytes: the first 4 bytes contain the int data the next 4 bytes contain a pointer to the next node in the list the last node’s next pointer is NULL (zero) Suppose $a0 points to the first node in the list ($a0 = 1000) C/C++ MIPS t0 = a0->data lw $t0, 0($a0) t1 = a0->next lw $t1, 4($a0) 1000 1008 1016 1024 3 2 1

Setting the next pointers Suppose we want the links to point as follows: Again, suppose $a0 points to the first node in the list ($a0 = 1000) addi $t1, $a0, 16 addi $t2, $a0, 8 sw $t1, 4($a0) sw $t2, 4($t1) sw $0, 4($t2) 1000 1008 1016 1024 3 2 1 NULL

Printing the elements of a linked list Translate the following code into MIPS // head points to the first node in the list while(head != NULL) { print(head->data); head = head->next; } loop: # assume $t0 = head (WARNING: errors!!) beq $t0, $0, done lw $a0, 0($t0) jal print lw $t0, 4($t0) j loop done:

Recursive Functions Recall that recursive functions have one or more base-cases, and one or more recursive calls. Example: int length(node *head) { if(head == NULL) return 0; return 1 + length(head->next); } Useful tip: Translate the base case first (rarely needs the stack) length: # $a0 = head bne $a0, $0, rec_case li $v0, 0 # return-value = NULL = 0 jr $ra rec_case: ...

The Recursive Case Let’s examine the recursive step more carefully: return 1 + length(head->next); Useful tip: Apart from $ra, what else must be preserved across the function call? Here: nothing rec_case: addi $sp, $sp, -4 # save space for $ra sw $ra, 0($sp) lw $a0, 4($a0) jal length # recursive call addi $v0, $v0, 1 lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra

Instruction Set Architecture (ISA) The ISA is an abstraction layer between hardware and software Software doesn’t need to know how the processor is implemented Processors that implement the same ISA appears equivalent An ISA enables processor innovation without changing software This is how Intel has made billions of dollars Before ISAs, software was re-written/re-compiled for each new machine Software Proc #1 ISA Proc #2

ISA history: RISC vs. CISC 1964: IBM System/360, the first computer family IBM wanted to sell a range of machines that ran the same software 1960’s, 1970’s: Complex Instruction Set Computer (CISC) era Much assembly programming, compiler technology immature Hard to optimize, guarantee correctness, teach 1980’s: Reduced Instruction Set Computer (RISC) era Most programming in high-level languages, mature compilers Simpler, cleaner ISA’s facilitated pipelining, high clock frequencies 1990’s: Post-RISC era ISA compatibility outweighs any RISC advantage in general purpose CISC and RISC chips use same techniques (pipelining, superscalar, ..) Embedded processors prefer RISC for lower power, cost 2000’s: Multi-core era

Comparing x86 and MIPS x86 is a typical CISC ISA, MIPS is a typical RISC ISA Much more is similar than different: Both use registers and have byte-addressable memories Same basic types of instructions (arithmetic, branches, memory) A few of the differences: Fewer registers: 8 (vs. 32 for MIPS) 2-register instruction formats (vs. 3-register format for MIPS) Additional, complex addressing modes Variable-length instruction encoding (vs. fixed 32-bit length for MIPS)

x86 Registers Few, and special purpose 8 integer registers two used only for stack not all instructions can use all registers Little room for temporary values x86 uses “two-address code” op x, y # y = y op x Rarely can the compiler fit everything in registers Stack is used much more heavily, so it is architected (not just a convention) The esp register is the stack pointer Explicit push and pop instructions %eax %edx %ecx %ebx %esi %edi %esp %ebp

Memory Operands Most instructions can include a memory operand addl -8(%ebp), %eax # equivalent MIPS code: # lw $t0, -8($ebp) # add $eax, $eax, $t0 MIPS supports just one addressing mode: offset($reg) refers to Mem[$reg + offset] X86 supports complex addressing modes: offset(%rb,%ri,scale) refers to Mem[%rb + %ri*scale + offset]

Variable Length Instructions 08048344 <sum>: 8048344: 55 push %ebp 8048345: 89 e5 mov %esp,%ebp 8048347: 8b 4d 08 mov 0x8(%ebp),%ecx 804834a: ba 01 00 00 00 mov $0x1,%edx Instructions range in size from 1 to 17 bytes Commonly used instructions are short (think Huffman Codes) In general, x86 has smaller code than MIPS Many different instruction formats, plus prefixes, suffixes Harder to decode for the machine

Why did Intel win? x86 won because it was the first 16-bit chip by two years IBM put it in PCs because there was no competing choice Rest is inertia and “financial feedback” x86 is most difficult ISA to implement for high performance, but Because Intel sells the most processors ... It has the most money ... Which it uses to hire more and better engineers ... Which is uses to maintain competitive performance ... And given equal performance, compatibility wins ... So Intel sells the most processors!