Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Computer Architecture MIPS Simulator and Assembly language.

Similar presentations


Presentation on theme: "1 Computer Architecture MIPS Simulator and Assembly language."— Presentation transcript:

1 1 Computer Architecture MIPS Simulator and Assembly language.

2 2 MIPS AND SPIM SPIM IS A SIMULATOR THAT RUNS PROGRAMS FOR THE MIPS R2000/R3000 RISC (REDUCED INSTRUCTIONS SET COMPUTER). SPIM IS BASED ON A VIRTUAL MACHINE ( A SIMULATION OF THE ACTUAL MICROPROCESSOR). SINCE SPIM IS A SIMULATOR CERTAIN THINGS ARE NOT IDENTICAL TO THE ACTUAL COMPUTER: –TIMING. –MEMORY CACHES OR MEMORY LATENCY. –DELAYS FOR FLOATING POINT OPERATIONS OR MULTIPLICATIONS OR DIVISIONS.

3 3 MIPS AND SPIM INFORMATION ON THE ASSEMBLY LANGUAGE CAN BE FOUND IN: –APPENDIX A OF THE TEXT FOR COMPUTER ARCHITECTURE –BY GOING TO THE WEB SITE AND DOWNLOADING THE PDF FILE OF APPENDIX A OF THE TEXTwww.cs.wisc.edu/~larus/spim.html –THE BACK COVER OF THE TEXT HAS A SYNOPSIS OF THE ASSEMBLY LANGUAGE INSTRUCTIONS.

4 4 MIPS AND SPIM Assembler syntax: –Comments start with a #. Everything from the the sharp sign to the end of the line is ignored. –Identifiers are a sequence of alphanumeric characters, underbars ( _ ) and (. ) that do not begin with a number. –Opcodes for instructions are reserved words that are not valid identifiers. –Labels are declared at the beginning of a line followed by a colon Item:.word 1 –Strings are enclosed in double quotes. Special characters follow C, newline \n, tab \t, quote \”. –.align n --- Align the next data on a 2 raised to the n power bytes boundary..align 2 means aligns the next value on a word boundary (4 bytes)

5 5 MIPS AND SPIM –.ascii str ---- Store the string in memory, but do not null-terminate it. –.asciiz str ---- Store the string in memory and null terminate it. –.byte b1, …., bn ---- Store the n values in successive bytes in memory. –.data --- The following data items should be stored in the data segment. If the argument addr is present the arguments are stored beginning with address. –.double d1, ….., dn ---- Store the n floating point double precision numbers in successive memory locations. –.extern sym size Declare that the data stored in sym is “size” bytes large and it is a global symbol. This directive allows the assembler to store the datum in a portion of the data segment that is efficiently accessed via register $gp. –.float f1, …,fn ---- Store the n floating point single precision numbers in successive memory locatoions.

6 6 MIPS AND SPIM –.globl sym – Declare that symbol sym is global and can be refernced from other files. –.half h1, …, hn ----Store the n 16-bit quantities in successive memory halfwords. –.kdata ---- The following data items should be stored in the kernel data segment. If argument addr is present, the items are stored beginning with address. –.ktext The next items are put in the kernel text segment. In SPIM these items may only be instructions or words. If the argument addr is there, the items are stored beginning with address. –.space n ---- Allocate n bytes of space in the current segment (which must be the data segment in SPIM). –.text The next items are put in the user text segment. In SPIM these items may only be instructions or words. If the argument addr is there, the items are stored beginning with address.

7 7 MIPS AND SPIM –.word w1, ……, wn Store the n-32 bit quantities in successive memory words. SYSTEM CALLS –SPIM provides a small set of operating-system like services through the system call instruction. To request a service a program loads the system call code into register $v0 and the arguments into registers $a0 …$a3 (or $f12 for floating point values): print_int, the code is : 1, the argument goes in $a0 = integer print_float, the code is : 2, the argument goes to $f12 = float print_double, the code is: 3, the argument goes into $f12=double print_string, the code is : 4, the argument goes into $a0=string read_int, the code is: 5, the result goes in $v0

8 8 MIPS AND SPIM read_float, the code is: 6, the result goes in $f0 read_double, the code is : 7, the result goes in $f0 read_string, the code is : 8, the argument is $a0=buffer, $a1=length sbrk, the code is: 9, the argument is $a0=amount, the result is : address in $v0 exit, the code is : 10 –For example to print “the answer = 5”, use:.data str:.asciiz “the answer =.text li $v0, 4 la $a0, str syscall li $v0, 1 li $a0, 5 syscall

9 9 MIPS REGISTERS NAMENUMBERUSAGE zero0Constant 0 at1Reserved for assembler v02Expression evaluation and result of a function a04Argument 1 a15Argument 2 a26Argument 3 a37Argument 4 to-t78-15Temporary (not preserved across call).

10 10 MIPS REGISTERS s0- s716-23Saved Temporary (preserved across call) t8 and t924, 25Temporary (not preserved across call) k0, k126, 27Reserved for OS kernel gp28Pointer to global area sp29Stack Pointer fp30Frame pointer ra31Return address (used by function call)

11 11 MIPS REGISTERS MIPS CONTAINS 32 GENERAL PURPOSE REGISTERS. REGISTER $0 ALWAYS CONATINS THE HARDWIRED 0 VALUE. REGISTERS $at, $k0, $k1 ARE RESERVED FOR USE BY THE ASSEMBLER AND THE OS. REGISTERS $a0-$a3 ARE USED TO PASS THE FIRST 4 ARGUMENTS TO ROUTINES (REMAINING ARGUMENTS ARE PASSED ON THE STACK). REGISTERS $v0 - $ v1 ARE USED TO RETURN VALUES FROM FUNCTIONS. REGISTERS $to - $t9 ARE CALLER SAVED REGISTERS FOR TEMPORARY QUANTITIES 9NOT PRESERVED ACROSS CALLS)

12 12 MIPS REGISTERS REGISTERS $s0 - $s7 ARE CALLEE SAVED REGISTERS THAT HOLD LONG LIVED VALUES THAT SHOULD BE PRESERVED ACROSS CALLS. REGISTER $sp POINTS TO THE FIRST FREE LOCATION ON THE STACK. REGISTER $fp IS THE FRAME POINTER. REGISTER $ra HAS THE RETURN ADDRESS FOR A CALL REGISTER $gp POINTS TO THE MIDDLE OF TH E64 K BLOCK MEMORY OF THE HEAP THAT HOLDS GLOBAL VARIABLES AND CONSTANTS.


Download ppt "1 Computer Architecture MIPS Simulator and Assembly language."

Similar presentations


Ads by Google