Sparc Architecture Overview

Slides:



Advertisements
Similar presentations
Chapter 5 The LC-3 Instruction Set Architecture l ISA Overview l Operate instructions l Data Movement instructions l Control Instructions l LC-3 data path.
Advertisements

SPARC Architecture & Assembly Language
ELEN 468 Advanced Logic Design
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
CSC 3210 Computer Organization and Programming Introduction and Overview Dr. Anu Bourgeois.
Lab6 – Debug Assembly Language Lab
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Chapter 6 Programming in Machine Language The LC-3 Simulator
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Computer Science 210 Computer Organization The Instruction Execution Cycle.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
CSC 3210 Computer Organization and Programming Chapter 2 SPARC Architecture Dr. Anu Bourgeois 1.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
ITEC 352 Lecture 12 ISA(3). Review Buses Memory ALU Registers Process of compiling.
Computer Architecture and the Fetch-Execute Cycle
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.
Chapter 4 The Von Neumann Model
CSC 3210 Computer Organization and Programming Chapter 2 SPARC Architecture Dr. Anu Bourgeois 1.
Natawut NupairojAssembly Language1 Memory and Stack.
Natawut NupairojAssembly Language1 Arithmetic Operations.
DH2T 34 – HNC Computer Architecture 1 Lecture 14 The Fetch-Decode-Execute Cycle [1]. © C Nyssen/Aberdeen College 2003 All images © C Nyssen/Aberdeen College.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
by Richard P. Paul, 2nd edition, 2000.
D75P 34 – HNC Computer Architecture
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
CSC 235 Computer Organization. Computer Organizaton ä Top_Level Structure ä The von-Neumann Machine ä Stack Machine ä Accumulator Machine ä Load/Store.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
CSC 3210 Computer Organization and Programming Chapter 2 SPARC ARCHITECTURE D.M. Rasanjalee Himali.
Microarchitecture. Outline Architecture vs. Microarchitecture Components MIPS Datapath 1.
Dale & Lewis Chapter 5 Computing components
Von Neumann Model Computer Organization I 1 September 2009 © McQuain, Feng & Ribbens The Stored Program Computer 1945: John von Neumann –
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Natawut NupairojAssembly Language1 Pipelining Processor.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Chapter 2 SPARC Architecture Chinua Umoja 1.  SPARC is a load/store architecture  Registers used for all arithmetic and logical operations  32 registers.
Assembly language.
Computer Organization
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Chapter 4 The Von Neumann Model
ELEN 468 Advanced Logic Design
Chapter 4 The Von Neumann Model
Chapter 4 The Von Neumann Model
Assembly Programming using MIPS R3000 CPU
The Processor and Machine Language
Chapter 4 The Von Neumann Model
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
CSC 3210 Computer Organization and Programming
The University of Adelaide, School of Computer Science
von Neumann Architecture CPU
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Chapter 4 The Von Neumann Model
COMS 361 Computer Organization
The Stored Program Computer
Assembly Programming using MIPS R3000 CPU
Program Execution.
Basic components Instruction processing
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Chapter 4 The Von Neumann Model
Presentation transcript:

Sparc Architecture Overview Natawut Nupairoj Assembly Language

Von Neumann Architecture Designed by John von Neumann in 1949. Machine = CPU + Memory Program is stored in memory along with data. CPU has Program Counter (PC) and Instruction Register (IR) Use PC to keep the current location of instruction being executed. Natawut Nupairoj Assembly Language

Von Neumann Architecture Control unit fetches an instruction from memory (located by PC) and stores in IR. Memory = Memory Address Register (MAR) + Memory Data Register (MDR) CPU puts an address in MAR and load/store from/to MDR. Natawut Nupairoj Assembly Language

Machine Organization Diagram Natawut Nupairoj Assembly Language

Instruction Execution Fetch-Decode-Execute cycles: Fetch the next instruction from memory. Change PC to point to next instruction. Determine the type of the instruction fetched. Find where the data being used by the instruction is kept. Fetch the data, if required. Execute the instruction. Store the results in the appropriate place. Go to step 1 and start all over again. Natawut Nupairoj Assembly Language

Instruction Cycles pc = 0; do { ir := memory[pc]; { Fetch the instruction. } pc := pc + INSTR_SIZE; { Move PC to next instruction. } decode(ir); { Decode the instruction. } fetch(operands); { Fetch the operands. } execute; { Execute the instruction. } store(results); { store the results. } } while(ir != HALT); Natawut Nupairoj Assembly Language

Sparc Architecture Overview Load/Store architecture ALU cannot access data from memory directly. Data must be loaded into registers before computing. RISC (Reduced Instruction Set Computer) architecture All instructions are one word (32 bits). 5-stage Pipelining CPU. Natawut Nupairoj Assembly Language

Sparc Registers There are 32 registers (%r0 - %r31). Each register is 64-bit for UltraSparc (128-bit for UltraSparc III). Registers are logically divided into 4 sets: global (%gx), in (%ix), local (%lx), and out (%ox). All registers are equal, can perform any operations. Special register: %g0 (%r0) - always discards writes and return zero. Natawut Nupairoj Assembly Language

Sparc Registers Global Output %g0 %r0 readonly / return zero %g1 %r1 %o0 %r8 %o1 %r9 %o2 %r10 %o3 %r11 %o4 %r12 %o5 %r13 %o6 %r14 %sp stack pointer %o7 %r15 called sub ret addr Natawut Nupairoj Assembly Language

Sparc Registers Local Input %l0 %r16 %l1 %r17 %l2 %r18 %l3 %r19 %i0 %r24 %i1 %r25 %i2 %r26 %i3 %r27 %i4 %r28 %i5 %r29 %i6 %r30 %fp frame pointer %i7 %r31 sub return addr Natawut Nupairoj Assembly Language

Format of Instructions Any instruction is made up of two parts: Opcode (the name of the instruction) Operands (the values or data manipulated by the instruction) -- can be omitted. L1: add %i2, 0x80, %o1 ! Add two numbers label opcode operands comment Natawut Nupairoj Assembly Language

Label Define the location of data or instruction. Start with: letter (A-Z and a-z), _, $, or . Followed by: letter (A-Z and a-z), number (0-9), _, $, or . Must end with color (:). Natawut Nupairoj Assembly Language

Operands Most instructions have three operands: three registers op reg, reg, reg add %g1, %i2, %g2 ! G2 is the destination. two registers and a literal constant op reg, imm, reg add %o1, 30, %o2 ! O2 is the destination. two registers op reg, reg mov %o4, %l3 ! L3 is the destination. Natawut Nupairoj Assembly Language

Operands a constant and a register op imm, reg mov 453, %g1 ! G1 is the destination. a register op reg clr %l2 a constant op imm call myfunc Notice: Last one is usually the destination. Natawut Nupairoj Assembly Language

Constant in Operand Constant (imm) must be 13-bit signed number: Format of constant ??? Natawut Nupairoj Assembly Language

Comment Inline comment (!): C-style comment (/* … */): ignore to the end of line. ! Inline comment here. Ignore to end of line. C-style comment (/* … */): ignore anything between the comment markers. /* comment here and it can be multiple line. */ Natawut Nupairoj Assembly Language

Our First Program Let try some simple C program (but not hello world !). /* first.c -- not hello world ! as usual */ main() { int x, y; x = 9; y = (x - 2)*(x + 14)/(x + 1); printf(“x = %d, y = %d\n”, x, y); } Natawut Nupairoj Assembly Language

printf(“x = %d, y = %d\n”, x, y); printf Function var1 printf(“x = %d, y = %d\n”, x, y); Display information formatted by the first string. Format: %d = integer %s = string %f = floating point \n = newline format var2 Natawut Nupairoj Assembly Language

Our First Program generate first.s gcc -S first.c .file "first.c" gcc2_compiled.: .global .umul .global .div .section ".rodata" .align 8 .LLC0: .asciz "x = %d and y = %d\n" .section ".text" .align 4 .global main .type main,#function .proc 04 main: !#PROLOGUE# 0 save %sp, -120, %sp !#PROLOGUE# 1 mov 9, %o0 st %o0, [%fp-20] ld [%fp-20], %o1 add %o1, -2, %o0 ld [%fp-20], %o2 add %o2, 14, %o1 call .umul, 0 nop add %o2, 1, %o1 call .div, 0 ... Natawut Nupairoj Assembly Language

Sparc Basic Assembly Instructions Load/Store Operations mov 75, %o2 ! %o2 = 75 mov %o2, %i3 ! %i3 = %o2 clr %l4 ! %l4 = 0 Arithmetics add %o1, %l2, %l3 ! %l3 = %o1 + %l2 add %o3, 19, %g4 ! %g4 = %o3 + 19 sub %i0, %g2, %o5 ! %o5 = %i0 + %g2 Natawut Nupairoj Assembly Language

Sparc Basic Assembly Instructions Multiply / Divide To multiply: 24 * %i2 mov 24, %o0 ! First operand mov %i2, %o1 ! Second operand call .mul ! Result stored in %o0 nop ! Delay slot, discussed later ! %o0 := %o0 * %o1 To divide: %o2 / %g3 mov %o2, %o0 ! First operand mov %g3, %o1 ! Second operand call .div ! Result stored in %o0 ! %o0 = %o0 / %o1 Natawut Nupairoj Assembly Language

Our First Program (Revisited) /* first.m */ /* * This programs compute: * y = (x - 2) * (x + 14) / (x + 8) * for x = 9 */ /* use %l0 and %l1 to store x and y */ define(x_r, l0) define(y_r, l1) /* define constants */ define(c1, 2) Natawut Nupairoj Assembly Language

Our First Program (Revisited) fmt: .asciz "x = %d and y = %d\n" .align 4 .global main main: save %sp, -64, %sp mov 9, %x_r ! x = 9 sub %x_r, c1, %o0 ! %o0 = x - 2 add %x_r, 14, %o1 ! %o1 = x + 14 call .mul ! %o0 = %o0 * %o1 nop add %x_r, 1, %o1 ! %o1 = x + 1 call .div ! %o0 = %o0 / %o1 mov %o0, %y_r ! store result in y Natawut Nupairoj Assembly Language

Our First Program (Revisited) set fmt, %o0 ! first argument for printf mov %x_r, %o1 ! second argument for printf mov %y_r, %o2 ! third argument for printf call printf ! print them out nop mov 1, %g1 ! prepare to exit ta 0 ! normal exit Natawut Nupairoj Assembly Language

Directives Information for the assembler. .global - tell the assembler the name of this function. .asciz - define a string. .align - align a location counter on a boundary. Natawut Nupairoj Assembly Language

Creating Executable File Use M4 macro-processor m4 < first.m > first.s (M4 produces first.s. Notice macro expansion.) Compile first.s gcc -S first.s -o first (this produces an executable file “first”.) Natawut Nupairoj Assembly Language

Running our First Program Run first first x = 9 and y = 16 Using printf to trace a program is not convenient. Natawut Nupairoj Assembly Language

The gdb Debugger To check the result, we will use a debugger. Run: gdb <filename> gdb first (gdb) Run your program: (gdb)r Starting program: /usr3/faculty/natawut/Class/Assembly/first ... Program exited with code 011. Natawut Nupairoj Assembly Language

Breakpoint Set a breakpoint: (gdb) b main Breakpoint 1 at 0x105a4 (gdb) r Starting program: /usr3/faculty/natawut/Class/Assembly/first ... Breakpoint 1, 0x105a4 in main () (gdb) Natawut Nupairoj Assembly Language

Print an Instruction We can examine memory by typing “x”. (gdb) x/i $pc 0x105a4 <main+4>: mov 9, %l0 (gdb) 0x105a8 <main+8>: sub %l0, 2, %o0 We can examine memory by typing “x”. Tell gdb to interpret the current memory as an instruction. Use current location pointed by %pc. Repeat last command by hitting enter key. Natawut Nupairoj Assembly Language

Print the Entire Program Assembley Language First Semester 2542 Print the Entire Program (gdb) disassemble Dump of assembler code for function main: 0x105a0 <main>: save %sp, -64, %sp 0x105a4 <main+4>: mov 9, %l0 0x105a8 <main+8>: sub %l0, 2, %o0 0x105ac <main+12>: add %l0, 0xe, %o1 0x105b0 <main+16>: call 0x2069c <.mul> 0x105b4 <main+20>: nop ... 0x105d4 <main+52>: add %o7, %l7, %l7 End of assembler dump. (gdb) Natawut Nupairoj Assembly Language Natawut Nupairoj

More Debugging Commands Advance breakpoint: (gdb) b *& main+16 Breakpoint 3 at 0x105cc (gdb) c Continuing. Breakpoint 3, 0x105cc in main () (gdb) We use “c” to continue execution after stopping at a breakpoint. Natawut Nupairoj Assembly Language

More Debugging Commands Print out the contents of a register: (gdb) p $l0 $1 = 9 (gdb) Automatically print out contents: (gdb) display/i $pc 1: x/i $pc 0x105a4 <main+4>: mov 9, %l0 (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /usr3/faculty/natawut/Class/Assembly/first Natawut Nupairoj Assembly Language

More Debugging Commands Breakpoint 2, 0x105a4 in main () 1: x/i $pc 0x105a4 <main+4>: mov 9, %l0 (gdb) ni 0x105a8 in main () 1: x/i $pc 0x105a8 <main+8>: sub %l0, 2, %o0 (gdb) We use “r” to restart execution from the beginning and “ni” to execute the next instruction. Natawut Nupairoj Assembly Language

More Debugging Commands For other commands, try: help To exit from gdb: q Natawut Nupairoj Assembly Language