1 / 11

Chapter 2 Part I SPARC ARCHITECTURE Dr. A.P. Preethy

Chapter 2 Part I SPARC ARCHITECTURE Dr. A.P. Preethy. 2.1 Introduction SPARC architecture is a load/store architecture, and the load and store instructions move data between registers and memory.

dscalf
Download Presentation

Chapter 2 Part I SPARC ARCHITECTURE Dr. A.P. Preethy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 Part ISPARC ARCHITECTUREDr. A.P. Preethy 2.1 Introduction • SPARC architecture is a load/store architecture, and the load and store instructions move data between registers and memory. • The machine has 32 data lines, 30 address lines (addressable memory size of 230 ) and 32 registers. 2.2 Registers Registers provide for rapid, direct access in computation. • The registers are logically divided into four sets: • Global : for global register data, valid in the entire body of the program, and accessible from any part of the program. • In : for storing the calling function arguments. • Local : for storing local function variables. • Out : act as temporary registers, passing arguments to and from the functions. • Please refer to the table of registers given on the next page.  CSC3210: Chapter#2

  2. Table of Registers CSC3210: Chapter#2

  3. 2.3 SPARC Assembly Language Programming • The SPARC assembler is in effect a two-pass assemble. In the first pass the assembler updates the location counter as it process machine statements, without paying attention to undefined labels that might be used as operands. • The program is then read a second time; this time, whenever a label is encountered, its value is substituted for symbol. CSC3210: Chapter#2

  4. Assembly language programs are line based • Statements may be labeled using a colon after an identifier • Tabs can be used appropriately • For commenting ‘C style’ /* can be used For example : /* instruction to add and to subtract the contents of registers %o0 and %o1 storing the result into %l0 and %l1 */ start: add %o0, %o1, %l0 !l0 = o0 + 01 sub %o0, %o1, %l1 !l1 = o0 – o1 CSC3210: Chapter#2

  5. Instructions use mnemonics, which generate machine code upon assembling e.g. add, sub • Certain instructions do not generate machine code, and are known as pseudo-ops. e.g. .word, .global • .global pseudo-op defines a label to be accessible outside the program in which it is defined. For example, to define the label main to be global, we would write, .global main Main: CSC3210: Chapter#2

  6. Assembling using C compiler • Using a –S switch, the C compiler translates the c program into assembly language with a .s extension %gcc –S program.c • The C compiler then calls the assembler as and produces files of the same name but with an “.o” extension – the object file. These files are the machine code corresponding to the C code for each file. After the C compiler has produced all the “ .o ” files, it calls the linker to combine all the object files with library routines, such as the input/output functions, to make an executable program. This executable program is by default stored in a file called “a.out”. CSC3210: Chapter#2

  7. To evaluate the expression in Eq. (1.1) in a file expr.s, to have this assembled and made ready for execution, we would type %gcc expr.s –o expr This will assemble our program and place it in a file called expr ready for execution. CSC3210: Chapter#2

  8. When we assemble and load our program we must also specify the starting address. The C compiler expects to start execution at an address main. This label must appear in our program at the first statement we want executed, and furthermore, it must be declared global by using the .global pseudo-op. The first instruction to be executed should be .global main main: save %sp, -96, %sp The save instruction provides space to save registers when the debugger is running • To expand macros, run the program with a .m extension, using m4 to produce the .s file. %m4 expr.m > expr.s %gcc expr.s –o expr CSC3210: Chapter#2

  9. 2.4 An Example To evaluate the expression in Chapter 1, we will use two of the local register, %l0 and %l1, to store x and y respectively. We will use the polynomial coefficients directly as literals. /* This program computes the expression : y = (x-1) * (x-7) / (x-11) The polynomial coefficients are: */ define(a2, 1) define(a1, 7) define(a0, 11) /* variables x and y are stored in %l0 and %l1 */ define(x_r, l0) define(y_r, l1) .global main main: save %sp, -96, %sp CSC3210: Chapter#2

  10. Most of the SPARC instructions takes three operands: two registers and a literal constant, or three registers: Op regrs1, reg_or_imm, regrd A literal constant c must have the range : –4096 c<4096 Other instructions: clr regrd mov reg reg_or_immed , regrd add regrs1, reg_or_imm, regrd sub regrs1, reg_or_imm, regrd CSC3210: Chapter#2

  11. Being a RISC architecture, SPARC does not have multiply and divide instructions. These operations are done by call instruction. E.g. For evaluating a= b*c, use: mov b, %o0 mov c, %o1 call .mul To divide a= b/c, use: mov b, %o0 mov c, %o1 call .div Six out registers %o0 through %o5 are used for storing temporary results, and their contents are not preserved over function calls. CSC3210: Chapter#2

More Related