Computer Architecture MIPS Simulator and Assembly language 1

  • Slides: 12
Download presentation
Computer Architecture MIPS Simulator and Assembly language. 1

Computer Architecture MIPS Simulator and Assembly language. 1

MIPS AND SPIM • SPIM IS A SIMULATOR THAT RUNS PROGRAMS FOR THE MIPS

MIPS AND SPIM • SPIM IS A SIMULATOR THAT RUNS PROGRAMS FOR THE MIPS R 2000/R 3000 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. 2

MIPS AND SPIM • INFORMATION ON THE ASSEMBLY LANGUAGE CAN BE FOUND IN: –

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 www. cs. wisc. edu/~larus/spim. html AND DOWNLOADING THE PDF FILE OF APPENDIX A OF THE TEXT – THE BACK COVER OF THE TEXT HAS A SYNOPSIS OF THE ASSEMBLY LANGUAGE INSTRUCTIONS. 3

MIPS AND SPIM • Assembler syntax: – Comments start with a #. Everything from

MIPS AND SPIM • Assembler syntax: – Comments start with a #. Everything from 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) 4

MIPS AND SPIM – – . ascii str ---- Store the string in memory,

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 b 1, …. , bn ---- Store the n values in successive bytes in memory. . data <addr> --- The following data items should be stored in the data segment. If the argument addr is present the arguments are stored beginning with address <addr>. –. double d 1, …. . , 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 f 1, …, fn ---- Store the n floating point single precision numbers in successive memory locatoions. 5

MIPS AND SPIM –. globl sym – Declare that symbol sym is global and

MIPS AND SPIM –. globl sym – Declare that symbol sym is global and can be refernced from other files. –. half h 1, … , hn ----Store the n 16 -bit quantities in successive memory halfwords. –. kdata <addr> ---- The following data items should be stored in the kernel data segment. If argument addr is present, the items are stored beginning with address <addr>. –. ktext <addr> ----- 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 <addr>. –. space n ---- Allocate n bytes of space in the current segment (which must be the data segment in SPIM). –. text <addr> ----- 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 <addr>. 6

MIPS AND SPIM –. word w 1, …… , wn ----- Store the n-32

MIPS AND SPIM –. word w 1, …… , 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 $v 0 and the arguments into registers $a 0 …$a 3 (or $f 12 for floating point values): • • • print_int , the code is : 1 , the argument goes in $a 0 = integer print_float, the code is : 2 , the argument goes to $f 12 = float print_double, the code is: 3, the argument goes into $f 12=double print_string, the code is : 4, the argument goes into $a 0=string read_int, the code is: 5, the result goes in $v 0 7

MIPS AND SPIM • • • read_float, the code is: 6, the result goes

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

MIPS REGISTERS • • NAME zero at v 0 NUMBER 0 1 2 •

MIPS REGISTERS • • NAME zero at v 0 NUMBER 0 1 2 • • • a 0 a 1 a 2 a 3 to-t 7 4 5 6 7 8 -15 USAGE Constant 0 Reserved for assembler Expression evaluation and result of a function Argument 1 Argument 2 Argument 3 Argument 4 Temporary (not preserved across call). 9

MIPS REGISTERS • s 0 - s 7 16 -23 • t 8 and

MIPS REGISTERS • s 0 - s 7 16 -23 • t 8 and t 9 24, 25 • • • 26, 27 28 29 30 31 k 0, k 1 gp sp fp ra Saved Temporary (preserved across call) Temporary (not preserved across call) Reserved for OS kernel Pointer to global area Stack Pointer Frame pointer Return address (used by function call) 10

MIPS REGISTERS • MIPS CONTAINS 32 GENERAL PURPOSE REGISTERS. • REGISTER $0 ALWAYS CONATINS

MIPS REGISTERS • MIPS CONTAINS 32 GENERAL PURPOSE REGISTERS. • REGISTER $0 ALWAYS CONATINS THE HARDWIRED 0 VALUE. • REGISTERS $at, $k 0, $k 1 ARE RESERVED FOR USE BY THE ASSEMBLER AND THE OS. • REGISTERS $a 0 -$a 3 ARE USED TO PASS THE FIRST 4 ARGUMENTS TO ROUTINES (REMAINING ARGUMENTS ARE PASSED ON THE STACK). • REGISTERS $v 0 - $ v 1 ARE USED TO RETURN VALUES FROM FUNCTIONS. • REGISTERS $to - $t 9 ARE CALLER SAVED REGISTERS FOR TEMPORARY QUANTITIES 9 NOT PRESERVED ACROSS CALLS) 11

MIPS REGISTERS • REGISTERS $s 0 - $s 7 ARE CALLEE SAVED REGISTERS THAT

MIPS REGISTERS • REGISTERS $s 0 - $s 7 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 E 64 K BLOCK MEMORY OF THE HEAP THAT HOLDS GLOBAL VARIABLES AND CONSTANTS. 12