1 compilers modern compiler design supplementary note 2 spim overview ncyu c. h. wang

16
1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

Upload: alexina-anderson

Post on 03-Jan-2016

218 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

1

CompilersModern Compiler Design

Supplementary Note 2 SPIM Overview

NCYU C. H. Wang

Page 2: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

2

SPIM Simulator

Spim is a self-contained simulator that will run MIPS32 assembly language programs.

Spim reads and immediately executes assembly language code for this processor.

Spim provides a simple debugger and minimal set of operating system services.

SPIM’s name is just MIPS spelled backwards SPIM can read and immediately execute MIPS

assembly language files or MIPS executable files Web site: http://www.cs.wisc.edu/~larus/spim.html

Page 3: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

3

MIPS Processors MIPS is a load-store architecture, which

means that only load and store instructions access memory

Computation instructions operate only on values in registers

Page 4: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

4

MIPS Registers (1/2)

Page 5: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

5

MIPS Registers (2/2)

Page 6: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

6

Addressing Modes

Page 7: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

7

Assembler Syntax (1)

Comments in assembler les begin with a sharp-sign (#). Everything from the sharp-sign to the end of the line is ignored.

Identifiers are a sequence of alphanumeric characters, underbars (_), and dots (.) that do not begin with a number.

Opcodes for instructions are reserved words that are not valid identifiers.

Labels are declared by putting them at the beginning of a line followed by a colon.

Page 8: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

8

Assembler Syntax (2)

Example

Page 9: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

9

Assembler Syntax (3)

.data <addr> The following data items should be stored in the data

segment. If the optional argument addr is present, the items are stored beginning at address addr.

.text <addr> The next items are put in the user text segment. In

SPIM, these items may only be instructions or words (see the .word directive below). If the optional argument addr is present, the items are stored beginning at address addr.

Page 10: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

10

Assembler Syntax (4) .word w1, ..., wn

Store the n 32-bit quantities in successive memory words. .double d1, ..., dn

Store the n floating point double precision numbers in successive memory locations.

.float f1, ..., fn Store the n floating point single precision numbers in successive

memory locations. .globl sym

Declare that symbol sym is global and can be referenced from other files.

Page 11: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

11

Assembly Instructions (1)

Load, Store and Data Movement li rd, imm rd imm la rd, label rd label lw rd, imm(rs) rd imm(rs) sw rd, imm(rs) imm(rs) rd moverd, rs rd rs

Page 12: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

12

Assembly Instructions (2)

Arithmetic & Logical Instructions add rd, rs, rt rd rs + rt sub rd, rs, rt rd rs – rt mul rd, rs, rt rd rs * rt div rd, rs, rt rd rs / rt rem rd, rs, rt rd rs % rt neg rd, rs rd - rs

Page 13: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

13

Assembly Instructions (3)

Branch & Jump Instructions beq rs, rt, label branch to label if rs == rt bne rs, rt, label branch to label if rs != rt bgt rs, rt, label branch to label if rs > rt bge rs, rt, label branch to label if rs >= rt blt rs, rt, label branch to label if rs < rt ble rs, rt, label branch to label if rs <= rt b label branch to label

Page 14: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

14

Layout of Memory

Page 15: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

15

System Services (1)

Page 16: 1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang

16

System Services (2)

SPIM provides a small set of operating-system-like services through the system call (syscall) instruction.

To request a service, a program loads the system call code (see Table 1) into register $v0 and the arguments into registers $a0: : :$a3 (or $f12 for oating point values).

System calls that return values put their result in register $v0 (or $f0 for oating point results).