Part II InstructionSet Architecture June 2005 Computer Architecture














- Slides: 14

Part II Instruction-Set Architecture June 2005 Computer Architecture, Instruction-Set Architecture 1

II Instruction Set Architecture Introduce machine “words” and its “vocabulary, ” learning: • A simple, yet realistic and useful instruction set • Machine language programs; how they are executed • RISC vs CISC instruction-set design philosophy Topics in This Part Chapter 5 Instructions and Addressing Chapter 6 Procedures and Data Chapter 7 Assembly Language Programs Chapter 8 Instruction Set Variations June 2005 Computer Architecture, Instruction-Set Architecture 2

7 Assembly Language Programs Everything else needed to build and run assembly programs: • Supply info to assembler about program and its data • Non-hardware-supported instructions for convenience Topics in This Chapter 7. 1 Machine and Assembly Languages 7. 2 Assembler Directives 7. 3 Pseudoinstructions 7. 4 Macroinstructions 7. 5 Linking and Loading 7. 6 Running Assembler Programs June 2005 Computer Architecture, Instruction-Set Architecture 3

7. 1 Machine and Assembly Languages Figure 7. 1 Steps in transforming an assembly language program to an executable program residing in memory. June 2005 Computer Architecture, Instruction-Set Architecture 4

Symbol Table byte 0 byte 1 byte 2 byte 3 Figure 7. 2 An assembly-language program, its machine-language version, and the symbol table created during the assembly process. June 2005 Computer Architecture, Instruction-Set Architecture 5

7. 2 Assembler Directives (See P&H App. A, §A. 10, pp. A-47 to A-49 for more details) Assembler directives provide the assembler with info on how to translate the program but do not lead to the generation of machine instructions tiny: max: small: big: array: str 1: str 2: . macro. end_macro. text. . data. byte 156, 0 x 7 a. word 35000. float 2 E-3. double 2 E-3. align 2. space 600. ascii “a*b”. asciiz “xyz”. global main June 2005 # # # start macro (see Section 7. 4) end macro (see Section 7. 4) start program’s text segment program text goes here start program’s data segment name & initialize data byte(s) name & initialize data word(s) # name short float (see Chapter # name long float (see Chapter align next item on word boundary reserve 600 bytes = 150 words name & initialize ASCII string null-terminated ASCII string # consider “main” a global name Computer Architecture, Instruction-Set Architecture 6

Composing Simple Assembler Directives Example 7. 1 Write assembler directive to achieve each of the following objectives: a. Put the error message “Warning: The printer is out of paper!” in memory. b. Set up a constant called “size” with the value 4. c. Set up an integer variable called “width” and initialize it to 4. d. Set up a constant called “mill” with the value 1, 000 (one million). e. Reserve space for an integer vector “vect” of length 250. Solution: a. noppr: b. size: c. width: d. mill: e. vect: June 2005 . asciiz “Warning: The printer is out of paper!”. byte 4 # small constant fits in one byte. word 4 # byte could be enough, but. . word 1000000 # constant too large for byte. space 1000 # 250 words = 1000 bytes Computer Architecture, Instruction-Set Architecture 7

7. 3 Pseudoinstructions Example of one-to-one pseudoinstruction: The following not $s 0 # complement ($s 0) is converted to the real instruction: nor $s 0, $zero # complement ($s 0) Example of one-to-several pseudoinstruction: The following abs $t 0, $s 0 # put |($s 0)| into $t 0 is converted to the sequence of real instructions: add slt beq sub June 2005 $t 0, $s 0, $zero $at, $t 0, $zero $at, $zero, +4 $t 0, $zero, $s 0 # # copy x into $t 0 is x negative? if not, skip next instr the result is 0 – x Computer Architecture, Instruction-Set Architecture 8

Mini. MIPS Pseudoinstructions Copy Arithmetic Table 7. 1 Shift Logic Memory access Control transfer June 2005 Pseudoinstruction Usage Move Load address Load immediate Absolute value Negate Multiply (into register) Divide (into register) Remainder Set greater than Set less or equal Set greater or equal Rotate left Rotate right NOT Load doubleword Store doubleword Branch less than Branch greater than Branch less or equal Branch greater or equal move la li abs neg mul div rem sgt sle sge rol ror not ld sd blt bgt ble bge Computer Architecture, Instruction-Set Architecture regd, regs regd, address regd, anyimm regd, regs regd, reg 1, reg 2 regd, reg 1, reg 2 regd, address reg 1, reg 2, L reg 1, reg 2, L 9

7. 4 Macroinstructions A macro is a mechanism to give a name to an oft-used sequence of instructions (shorthand notation) . macro name(args). . end_macro # macro and arguments named # instr’s defining the macro # macro terminator How is a macro different from a pseudoinstruction? Pseudos are predefined, fixed, and look like machine instructions Macros are user-defined and resemble procedures (have arguments) How is a macro different from a procedure? Control is transferred to and returns from a procedure After a macro has been replaced, no trace of it remains June 2005 Computer Architecture, Instruction-Set Architecture 10

7. 5 Linking and Loading The linker has the following responsibilities: • Ensuring correct interpretation (resolution) of labels in all modules • Determining the placement of text and data segments in memory • Evaluating all data addresses and instruction labels • Forming an executable program with no unresolved references The loader is in charge of the following: • Determining the memory needs of the program from its header • Copying text and data from the executable program file into memory • Modifying (shifting) addresses, where needed, during copying • Placing program parameters onto the stack (as in a procedure call) • Initializing all machine registers, including the stack pointer • Jumping to a start-up routine that calls the program’s main routine June 2005 Computer Architecture, Instruction-Set Architecture 11

7. 6 Running Assembler Programs Spim is a simulator that can run Mini. MIPS programs The name Spim comes from reversing MIPS Three versions of Spim are available for free downloading: PCSpim for Windows machines xspim for X-windows spim for Unix systems You can download SPIM by visiting: http: //www. cs. wisc. edu/~larus/spim. html June 2005 Computer Architecture, Instruction-Set Architecture 12

Input/Output Conventions for Mini. MIPS Table 7. 2 Input/output and control functions of syscall in PCSpim. ($v 0) Function Output 1 Print integer Input Result Integer in $a 0 Integer displayed 2 Print point floating- Float in $f 12 3 Print float double- Double-float Float displayed in Double-float displayed $f 12, $f 13 Pointer in $a 0 4 Print string Cntl Arguments Null-terminated string displayed 5 Read integer Integer returned in $v 0 6 Read floatingpoint Float returned in $f 0 7 Read float Double-float returned in double- 8 Read string June 2005 $f 0, $f 1 Pointer in $a 0, length in String returned in buffer at Computer Architecture, Instruction-Set Architecture 13 $a 1 pointer

PCSpim User Interface Figure 7. 3 June 2005 Computer Architecture, Instruction-Set Architecture 14