Learning Outcomes. System Calls. System Calls. The System Call Interface: A Brief Overview. System Calls. The Structure of a Computer System

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Learning Outcomes. System Calls. System Calls. The System Call Interface: A Brief Overview. System Calls. The Structure of a Computer System"

Transcription

1 Learning Outcomes System Calls Interface and Implementation A high-level understanding of System Call interface Mostly from the user s perspective From textbook (section.6) Understanding of how the application-kernel boundary is crossed with system calls in general Including an appreciation of the relationship between a case study (OS/6 system call handling) and the general case. Exposure architectural details of the MIPS R3 Detailed understanding of the of exception handling mechanism From Hardware Guide on class web site Understanding of the existence of compiler function calling conventions Including details of the MIPS C compiler calling convention 2 The Structure of a Computer System System Calls Interface Application System Libraries User Mode Kernel Mode Device OS Device Interaction via System Calls Memory 3 4 System Calls Can be viewed as special function calls Provides for a controlled entry into the kernel While in kernel, they perform a privileged operation Returns to original caller with the result The system call interface represents the abstract machine provided by the operating system. The System Call Interface: A Brief Overview From the user s perspective Process Management File I/O Directories management Some other selected Calls There are many more On Linux, see man syscalls for a list 5 6

2 Some System Calls For Process Management Some System Calls For File Management 7 8 Some System Calls For Directory Management Some System Calls For Miscellaneous Tasks 9 A stripped down shell: System Calls System Calls while (TRUE) { /* repeat forever */ type_prompt( ); /* display prompt */ read_command (command, parameters) /* input from terminal */ if (fork()!= ) { /* fork off child process */ /* Parent code */ waitpid( -, &status, ); /* wait for child to exit */ } else { /* Child code */ execve (command, parameters, ); /* execute command */ } } Some Win32 API calls 2 2

3 System Call Implementation Crossing user-kernel boundary A Simple Model of CPU Computation The fetch-execute cycle Load memory contents from address in program counter () The instruction Execute the instruction Increment Repeat CPU Registers : x3 3 4 A Simple Model of CPU Computation Stack Pointer Register Condition codes Positive result Zero result Negative result General Purpose Registers Holds operands of most instructions Enables programmers (compiler) to minimise memory references. CPU Registers : x3 SP: xcbf3 R Rn Privileged-mode Operation To protect operating system execution, two or more CPU modes of operation exist Privileged mode (system-, kernelmode) All instructions and registers are available User-mode Uses safe subset of the instruction set Only affects the state of the application itself They cannot be used to uncontrollably interfere with OS Only safe registers are accessible CPU Registers Interrupt Mask Exception Type MMU regs Others : x3 SP: xcbf3 R Rn 5 6 Example Unsafe Instruction cli instruction on x86 architecture Disables interrupts Example exploit cli /* disable interrupts */ while (true) /* loop forever */; 7 Privileged-mode Operation The accessibility of addresses within an address space changes depending on operating mode To protect kernel code and data Note: The exact memory ranges are usually configurable, and vary between CPU architectures and/or operating systems. xffffffff x8 x Memory Address Space Accessible only to Kernel-mode Accessible to User- and Kernel-mode 8 3

4 System Call Questions we ll answer User Mode Kernel Mode System call mechanism securely transfers from user execution to kernel execution and back. Application System Call Handler 9 There is only one register set How is register use managed What does an application expect a system call to look like How is the transition to kernel mode triggered Where is the OS entry point (system call handler) How does the OS know what to do 2 System Call Mechanism Overview System call transitions triggered by special processor instructions User to Kernel System call instruction Kernel to User Return from privileged mode instruction System Call Mechanism Overview Processor mode Switched from user-mode to kernel-mode Switched back when returning to user mode SP User-level SP is saved and a kernel SP is initialised User-level SP restored when returning to user-mode User-level is saved and set to kernel entry point User-level restored when returning to user-level Kernel entry via the designated entry point must be strictly enforced 2 22 System Call Mechanism Overview Registers Set at user-level to indicate system call type and its arguments A convention between applications and the kernel Some registers are preserved at user-level or kernellevel in order to restart user-level execution Depends on language calling convention etc. Result of system call placed in registers when returning to user-level Another convention Why do we need system calls Why not simply jump into the kernel via a function call Function calls do not Change from user to kernel mode and eventually back again Restrict possible entry points to secure locations To prevent entering after any security checks

5 Steps in Making a System Call The MIPS R2/R3 Before looking at system call mechanics in some detail, we need a basic understanding of the MIPS R3 There are steps in making the system call read (fd, buffer, nbytes) MIPS R3 Load/store architecture No instructions that operate on memory except load and store Simple load/stores to/from memory from/to registers Store word: sw r4, (r5) Store contents of r4 in memory using address contained in register r5 Load word: lw r3,(r7) Load contents of memory into r3 using address contained in r7 Delay of one instruction after load before data available in destination register» Must always an instruction between a load from memory and the subsequent use of the register. lw, sw, lb, sb, lh, sh,. MIPS R3 Arithmetic and logical operations are register to register operations E.g., add r3, r2, r No arithmetic operations on memory Example add r3, r2, r r3 = r2 + r Some other instructions add, sub, and, or, xor, sll, srl move r2, r r2 = r MIPS R3 All instructions are encoded in 32-bit Some instructions have immediate operands Immediate values are constants encoded in the instruction itself Only 6-bit value Examples Add Immediate: addi r2, r, 248 r2 = r Load Immediate : li r2, 234 r2 = 234 Example code Simple code example: a = a + lw r4,32(r29) li r5, add r4, r4, r5 sw r4,32(r29) // r29 = stack pointer Offset(Address)

6 MIPS Registers User-mode accessible registers 32 general purpose registers r hardwired to zero r3 the link register for jumpand-link (JAL) instruction HI/LO 2 * 32-bits for multiply and divide Not directly visible Modified implicitly by jump and branch instructions Branching and Jumping Branching and jumping have a branch delay slot li r2, sw r,(r3) The instruction li r2, 2 following a branch li r2, 3 or jump is always : sw r2, (r3) executed prior to destination of jump j f 3 32 MIPS R3 RISC architecture 5 stage pipeline Instruction partially through pipeline prior to jmp having an effect Jump and Link Instruction JAL is used to implement function calls r3 = +8 Return Address register (RA) is used to return from function call x x4 x8 : x2a jal f nop lw r4,(r6) sw r2, (r3) 33 x38 x3a jr r3 nop 34 Compiler Register Conventions Compiler Register Conventions Given 32 registers, which registers are used for Local variables Argument passing Function call results Stack Pointer

7 int fact(int n) { int r = ; int i; for (i = ; i < n+; i++) { r = r * i; } return r; } Simple factorial : 88b blez a,3 <fact+x3> 4: 2484 addiu a,a, 8: 243 li v, c: 242 li v, : 438 mult v,v 4: 2463 addiu v,v, 8: 2 mflo v c: nop 2: 464fffc bne v,a,4 <fact+x4> 24: 438 mult v,v 28: 3e8 jr ra 2c: nop 3: 3e8 jr ra 34: 242 li v, Function Stack Frames Each function call allocates a new stack frame for local variables, the return address, previous frame pointer etc. Frame pointer: start of current stack frame Stack pointer: end of current stack frame Example: assume f() calls f2(), which calls f3(). Frame Pointer Stack Pointer Stack f() stack frame Function Stack Frames Each function call allocates a new stack frame for local variables, the return address, previous frame pointer etc. Frame pointer: start of current stack frame Stack pointer: end of current stack frame Example: assume f() calls f2(), which calls f3(). Frame Pointer Stack Pointer Stack f() stack frame f2() stack frame Function Stack Frames Each function call allocates a new stack frame for local variables, the return address, previous frame pointer etc. Frame pointer: start of current stack frame Stack pointer: end of current stack frame Example: assume f() calls f2(), which calls f3(). Frame Pointer Stack Pointer Stack f() stack frame f2() stack frame f3() stack frame 39 4 Stack Frame Example Code MIPS calling convention for gcc Args -4 have space reserved for them main () { int i; } i = sixargs(,2,3,4,5,6); int sixargs(int a, int b, int c, int d, int e, int f) { return a + b + c + d + e + f; }

8 4c <main>: 4c: 27bdffd8 addiu sp,sp,-4 42: afbf24 sw ra,36(sp) 424: afbe2 sw s8,32(sp) 428: 3af2 move s8,sp 42c: 2425 li v,5 43: afa2 sw v,6(sp) 434: 2426 li v,6 438: afa24 sw v,2(sp) 43c: 244 li a, 44: 2452 li a,2 444: 2463 li a2,3 448: c2c jal 4b <sixargs> 44c: 2474 li a3,4 45: afc28 sw v,24(s8) 454: 3ce82 move sp,s8 458: 8fbf24 lw ra,36(sp) 45c: 8fbe2 lw s8,32(sp) 46: 3e8 jr ra 464: 27bd28 addiu sp,sp,4... 4b <sixargs>: 4b: 27bdfff8 addiu sp,sp,-8 4b4: afbe sw s8,(sp) 4b8: 3af2 move s8,sp 4bc: afc48 sw a,8(s8) 4c: afc5c sw a,2(s8) 4c4: afc6 sw a2,6(s8) 4c8: afc74 sw a3,2(s8) 4cc: 8fc38 lw v,8(s8) 4d: 8fc2c lw v,2(s8) 4d4: nop 4d8: 622 addu v,v,v 4dc: 8fc3 lw v,6(s8) 4e: nop 4e4: 432 addu v,v,v 4e8: 8fc34 lw v,2(s8) 4ec: nop 4f: 432 addu v,v,v 4f4: 8fc38 lw v,24(s8) 4f8: nop fc: 432 addu v,v,v 4: 8fc3c lw v,28(s8) 44: nop 48: 432 addu v,v,v 4c: 3ce82 move sp,s8 4: 8fbe lw s8,(sp) 44: 3e8 jr ra 48: 27bd8 addiu sp,sp,8 Coprocessor The processor control registers are located in CP Exception/Interrupt management registers Translation management registers CP is manipulated using mtc (move to) and mfc (move from) instructions mtc/mfc are only accessible in kernel mode. CP CP (floating point) : x3 HI/LO R Rn CP Registers c_status Exception Management c_cause of the recent exception c_status Current status of the CPU c_epc Address of the instruction that caused the exception c_badvaddr Address accessed that caused the exception Miscellaneous c_prid Processor Identifier Memory Management c_index c_random c_entryhi c_entrylo c_context More about these later in course For practical purposes, you can ignore most bits Green background is the focus

9 c_status c_cause IM Individual interrupt mask bits 6 external 2 software KU = kernel = user mode IE = all interrupts masked = interrupts enable Mask determined via IM bits c, p, o = current, previous, old 49 IP Interrupts pending 8 bits indicating current state of interrupt lines CE Coprocessor error Attempt to access disabled Copro. BD If set, the instruction that caused the exception was in a branch delay slot ExcCode The code number of the exception taken 5 Exception Codes Exception Codes 5 52 c_epc Exception Vectors The Exception Program Counter Points to address of where to restart execution after handling the exception or interrupt Example Assume sw r3,(r4) causes a restartable fault exception Aside: We are ignore BD-bit in c_cause which is also used in reality on rare occasions. nop sw r3 (r4) nop C_epc C_cause C_status CP (floating point) : x3 HI/LO R Rn

10 Simple Exception Walk-through Application User Mode Kernel Mode Interrupt Handler 55 Hardware exception handling x Let s now walk through an exception Assume an interrupt occurred as the previous instruction completed Note: We are in user mode with interrupts enabled 56 Hardware exception handling x Instruction address at which to restart after the interrupt is transferred to x Hardware exception handling x Kernel Mode is set, and previous mode shifted along Interrupts disabled and previous x state shifted along Hardware exception handling x Code for the exception placed in. Note Interrupt code = x Hardware exception handling x88 Address of general exception vector placed in x

11 Hardware exception handling x88 CPU is now running in kernel mode at x88, with interrupts disabled All information required to Find out what caused the exception Restart after exception handling is in coprocessor registers Badvaddr x Returning from an exception For now, lets ignore how the exception is actually handled how user-level registers are preserved Let s simply look at how we return from the exception 62 Returning from an exception x8234 This code to return is lw r27, saved_epc nop jr r27 rfe x Load the contents of which is usually moved earlier to somewhere in memory by the exception handler 63 Returning from an exception x This code to return is lw r27, saved_epc nop jr r27 rfe x Store the back in the 64 Returning from an exception x In the branch delay x slot, execute a restore from This code to return is exception instruction lw r27, saved_epc nop jr r27 rfe Returning from an exception x We are now back in the same state we were in when the exception happened x

12 MIPS System Calls System calls are invoked via a syscall instruction. The syscall instruction causes an exception and transfers control to the general exception handler A convention (an agreement between the kernel and applications) is required as to how user-level software indicates Which system call is required Where its arguments are Where the result should go 67 OS/6 Systems Calls OS/6 uses the following conventions Arguments are passed and returned via the normal C function calling convention Additionally Reg v contains the system call number On return, reg a3 contains : if success, v contains successful result not : if failure, v has the errno.» v stored in errno» - returned in v 68 Convention for kernel entry ra fp sp gp k k s7 s t9 t a3 a2 a a v v AT zero Args in Preserved Preserved for C calling convention Preserved SysCall No. Success Result ra fp sp gp k k s7 s t9 t a3 a2 a a v v AT zero Convention for kernel exit 69 Seriously lowlevel code follows This code is not for the faint hearted move a,s3 addiu a,sp,6 jal 468c <read> li a2,24 move s,v blez s,494 <docat+x9 7 User-Level System Call Walk Through Calling read() int read(int filehandle, void *buffer, size_t size) Three arguments, one return value Code fragment calling the read function 424: 2622 move a,s3 428: 27a5 addiu a,sp,6 42c: ca3 jal 468c <read> 43: 2464 li a2,24 434: 482 move s,v 438: a6 blez s,494 <docat+x94> Args are loaded, return value is tested Inside the read() syscall function part 468c <read>: 468c: 89 j 464 < syscall> 469: 2425 li v,5 Appropriate registers are preserved Arguments (a-a3), return address (ra), etc. The syscall number (5) is loaded into v Jump (not jump and link) to the common syscall routine

13 The read() syscall function part 2 Generate a syscall exception 464 < syscall>: 464: c syscall 4644: e5 beqz a3,465c < syscall+xc> 4648: nop 464c: 3c lui at,x 465: ac22 sw v,(at) 4654: 243ffff li v,- 4658: 242ffff li v,- 465c: 3e8 jr ra 466: nop The read() syscall function part 2 Test success, if yes, branch to return from function 464 < syscall>: 464: c syscall 4644: e5 beqz a3,465c < syscall+xc> 4648: nop 464c: 3c lui at,x 465: ac22 sw v,(at) 4654: 243ffff li v,- 4658: 242ffff li v,- 465c: 3e8 jr ra 466: nop The read() syscall function part < syscall>: If failure, store code 464: c syscall in errno 4644: e5 beqz a3,465c < syscall+xc> 4648: nop 464c: 3c lui at,x 465: ac22 sw v,(at) 4654: 243ffff li v,- 4658: 242ffff li v,- 465c: 3e8 jr ra 466: nop The read() syscall function part < syscall>: Set read() result to 464: c syscall : e5 beqz a3,465c < syscall+xc> 4648: nop 464c: 3c lui at,x 465: ac22 sw v,(at) 4654: 243ffff li v,- 4658: 242ffff li v,- 465c: 3e8 jr ra 466: nop The read() syscall function part < syscall>: 464: c syscall Return to location after where read() was called 4644: e5 beqz a3,465c < syscall+xc> 4648: nop 464c: 3c lui at,x 465: ac22 sw v,(at) 4654: 243ffff li v,- 4658: 242ffff li v,- 465c: 3e8 jr ra 466: nop Summary From the caller s perspective, the read() system call behaves like a normal function call It preserves the calling convention of the language However, the actual function implements its own convention by agreement with the kernel Our OS/6 example assumes the kernel preserves appropriate registers(s-s8, sp, gp, ra). Most languages have similar libraries that interface with the operating system

14 System Calls - Kernel Side OS/6 Exception Handling Things left to do Change to kernel stack Preserve registers by saving to memory (on the kernel stack) Leave saved registers somewhere accessible to Read arguments Store return values Do the read() Restore registers Switch back to user stack Return to application 79 Note: The following code is from the uniprocessor variant of OS6 (v.x). Simpler, but broadly similar. 8 exception: move k, sp /* Save previous stack pointer in k */ mfc k, c_status /* Get status register */ andi k, k, CST_Kup /* Check the we-were-in-user-mode bit */ beq k, $, f /* If clear, from kernel, already have stack */ nop /* delay slot */ /* Coming from user mode - load kernel stack into sp */ la k, curkstack /* get address of "curkstack" */ lw sp, (k) /* get its value */ nop /* delay slot for the load */ Note k, k registers : available for mfc k, c_cause /* Now, load the exception cause. */ j common_exception /* kernel Skip to use common code */ nop /* delay slot */ exception: move k, sp /* Save previous stack pointer in k */ mfc k, c_status /* Get status register */ andi k, k, CST_Kup /* Check the we-were-in-user-mode bit */ beq k, $, f /* If clear, from kernel, already have stack */ nop /* delay slot */ : /* Coming from user mode - load kernel stack into sp */ la k, curkstack /* get address of "curkstack" */ lw sp, (k) /* get its value */ nop /* delay slot for the load */ mfc k, c_cause /* Now, load the exception cause. */ j common_exception /* Skip to common code */ nop /* delay slot */ 8 82 common_exception: /* * At this point: * Interrupts are off. (The processor did this for us.) * k contains the exception cause value. * k contains the old stack pointer. * sp points into the kernel stack. * All other registers are untouched. */ /* * Allocate stack space for 37 words to hold the trap frame, * plus four more words for a minimal argument block. */ addi sp, sp, -64 /* The order here must match mips/include/trapframe.h. */ sw ra, 6(sp) /* dummy for gdb */ sw s8, 56(sp) /* save s8 */ sw sp, 52(sp) /* dummy for gdb */ sw gp, 48(sp) /* save gp */ sw k, 44(sp) /* dummy for gdb */ sw k, 4(sp) /* dummy for gdb */ These six stores are a hack to avoid sw k, 52(sp) /* real saved sp */ confusing GDB nop /* delay slot for store */ You can ignore the details of why and mfc k, c_epc /* Copr. reg 3 == for exception */ sw k, 6(sp) /* real saved */ how

15 /* The order here must match mips/include/trapframe.h. */ sw ra, 6(sp) /* dummy for gdb */ sw s8, 56(sp) /* save s8 */ sw sp, 52(sp) /* dummy for gdb */ sw gp, 48(sp) /* save gp */ sw k, 44(sp) /* dummy for gdb */ sw k, 4(sp) /* dummy for gdb */ sw k, 52(sp) /* real saved sp */ nop /* delay slot for store */ The real work starts here mfc k, c_epc /* Copr. reg 3 == for exception */ sw k, 6(sp) /* real saved */ 85 sw t9, 36(sp) sw t8, 32(sp) sw s7, 28(sp) sw s6, 24(sp) sw s5, 2(sp) sw s4, 6(sp) sw s3, 2(sp) sw s2, 8(sp) sw s, 4(sp) sw s, (sp) sw t7, 96(sp) sw t6, 92(sp) sw t5, 88(sp) sw t4, 84(sp) sw t3, 8(sp) sw t2, 76(sp) sw t, 72(sp) sw t, 68(sp) sw a3, 64(sp) sw a2, 6(sp) sw a, 56(sp) sw a, 52(sp) sw v, 48(sp) sw v, 44(sp) sw AT, 4(sp) sw ra, 36(sp) Save all the registers on the kernel stack 86 /* * Save special registers. */ mfhi t mflo t sw t, 32(sp) sw t, 28(sp) /* * Save remaining exception context information. */ sw k, 24(sp) /* k was loaded with cause earlier */ mfc t, c_status /* Copr. reg == status */ sw t, 2(sp) mfc t2, c_vaddr /* Copr. reg 8 == faulting vaddr */ sw t2, 6(sp) /* * Pretend to save $ for gdb's benefit. */ sw $, 2(sp) We can now use the other registers (t, t) that we have preserved on the stack 87 /* * Prepare to call mips_trap(struct trapframe *) */ addiu a, sp, 6 /* set argument */ jal mips_trap /* call it */ nop /* delay slot */ Create a pointer to the base of the saved registers and state in the first argument register 88 struct trapframe { }; u_int32_t tf_vaddr; /* vaddr register */ u_int32_t tf_status; /* status register */ u_int32_t tf_cause; /* cause register */ u_int32_t tf_lo; u_int32_t tf_hi; u_int32_t tf_ra;/* Saved register 3 */ u_int32_t tf_at;/* Saved register (AT) */ u_int32_t tf_v;/* Saved register 2 (v) */ u_int32_t tf_v;/* etc. */ u_int32_t tf_a; u_int32_t tf_a; u_int32_t tf_a2; u_int32_t tf_a3; u_int32_t tf_t; u_int32_t tf_t7; u_int32_t tf_s; u_int32_t tf_s7; u_int32_t tf_t8; u_int32_t tf_t9; u_int32_t tf_k;/* dummy (see exception.s comments) */ u_int32_t tf_k;/* dummy */ u_int32_t tf_gp; u_int32_t tf_sp; u_int32_t tf_s8; u_int32_t tf_epc; */ By creating a pointer to here of type struct trapframe *, we can access the user s saved registers as normal variables within C /* coprocessor epc register Kernel Stack epc s8 sp gp k k t9 t8 at ra hi lo cause status vaddr 89 Now we arrive in the C kernel /* * General trap (exception) handling function for mips. * This is called by the assembly-language exception handler once * the trapframe has been set up. */ void mips_trap(struct trapframe *tf) { u_int32_t code, isutlb, iskern; int savespl; /* The trap frame is supposed to be 37 registers long. */ assert(sizeof(struct trapframe)==(37*4)); /* Save the value of curspl, which belongs to the old context. */ savespl = curspl; /* Right now, interrupts should be off. */ curspl = SPL_HIGH; 9 5

16 What happens next The kernel deals with whatever caused the exception Syscall Interrupt Page fault It potentially modifies the trapframe, etc E.g., Store return code in v, zero in a3 mips_trap eventually returns exception_return: /* 6(sp) no need to restore tf_vaddr */ lw t, 2(sp) /* load status register value into t */ nop /* load delay slot */ mtc t, c_status /* store it back to coprocessor */ /* 24(sp) no need to restore tf_cause */ /* restore special registers */ lw t, 28(sp) lw t, 32(sp) mtlo t mthi t /* load the general registers */ lw ra, 36(sp) lw AT, 4(sp) lw v, 44(sp) lw v, 48(sp) lw a, 52(sp) lw a, 56(sp) lw a2, 6(sp) lw a3, 64(sp) 9 92 lw t, 68(sp) lw t, 72(sp) lw t2, 76(sp) lw t3, 8(sp) lw t4, 84(sp) lw t5, 88(sp) lw t6, 92(sp) lw t7, 96(sp) lw s, (sp) lw s, 4(sp) lw s2, 8(sp) lw s3, 2(sp) lw s4, 6(sp) lw s5, 2(sp) lw s6, 24(sp) lw s7, 28(sp) lw t8, 32(sp) lw t9, 36(sp) /* 4(sp) "saved" k was dummy garbage anyway */ /* 44(sp) "saved" k was dummy garbage anyway */ lw gp, 48(sp) /* restore gp */ /* 52(sp) stack pointer - below */ lw s8, 56(sp) /* restore s8 */ lw k, 6(sp) /* fetch exception return into k */ lw sp, 52(sp) /* fetch saved sp (must be last) */ /* done */ jr k /* jump back */ rfe /* in delay slot */.end common_exception Note again that only k, k have been trashed

What is a Process? Answer 1: a process is an abstraction of a program in execution

What is a Process? Answer 1: a process is an abstraction of a program in execution Processes and the Kernel 1 What is a Process? Answer 1: a process is an abstraction of a program in execution Answer 2: a process consists of an address space, which represents the memory that holds the

More information

µ-kernel Construction

µ-kernel Construction µ-kernel Construction Fundamental Abstractions Thread Address Space What is a thread? How to implement? What conclusions can we draw from our analysis with respect to µk construction? Processor? IP SP

More information

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

ECE232: Hardware Organization and Design. Computer Organization - Previously covered ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

More information

SPIM Instruction Set

SPIM Instruction Set SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

More information

Compiling Techniques

Compiling Techniques Lecture 10: An Introduction to MIPS assembly 18 October 2016 Table of contents 1 Overview 2 3 Assembly program template.data Data segment: constant and variable definitions go here (including statically

More information

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

MIPS Reference Guide

MIPS Reference Guide MIPS Reference Guide Free at PushingButtons.net 2 Table of Contents I. Data Registers 3 II. Instruction Register Formats 4 III. MIPS Instruction Set 5 IV. MIPS Instruction Set (Extended) 6 V. SPIM Programming

More information

ECE Exam I February 19 th, :00 pm 4:25pm

ECE Exam I February 19 th, :00 pm 4:25pm ECE 3056 Exam I February 19 th, 2015 3:00 pm 4:25pm 1. The exam is closed, notes, closed text, and no calculators. 2. The Georgia Tech Honor Code governs this examination. 3. There are 4 questions and

More information

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA. Today s topics CS/COE1541: Introduction to Computer Architecture MIPS operations and operands MIPS registers Memory view Instruction encoding A Review of MIPS ISA Sangyeun Cho Arithmetic operations Logic

More information

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers CSE 675.02: Introduction to Computer Architecture MIPS Processor Memory Instruction Set Architecture of MIPS Processor CPU Arithmetic Logic unit Registers $0 $31 Multiply divide Coprocessor 1 (FPU) Registers

More information

MIPS Instruction Format

MIPS Instruction Format MIPS Instruction Format MIPS uses a 32-bit fixed-length instruction format. only three different instruction word formats: There are Register format Op-code Rs Rt Rd Function code 000000 sssss ttttt ddddd

More information

We will study the MIPS assembly language as an exemplar of the concept.

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

More information

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda MIPS ISA and MIPS Assembly CS301 Prof. Szajda Administrative HW #2 due Wednesday (9/11) at 5pm Lab #2 due Friday (9/13) 1:30pm Read Appendix B5, B6, B.9 and Chapter 2.5-2.9 (if you have not already done

More information

EE 109 Unit 15 Subroutines and Stacks

EE 109 Unit 15 Subroutines and Stacks 1 EE 109 Unit 15 Subroutines and Stacks 2 Program Counter and GPRs (especially $sp, $ra, and $fp) REVIEW OF RELEVANT CONCEPTS 3 Review of Program Counter PC is used to fetch an instruction PC contains

More information

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer

More information

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong 1 EE 457 Unit 8 Exceptions What Happens When Things Go Wrong 2 What are Exceptions? Exceptions are rare events triggered by the hardware and forcing the processor to execute a software handler HW Interrupts

More information

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero Do-While Example In C++ do { z--; while (a == b); z = b; In assembly language loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero 25 Comparisons Set on less than (slt) compares its source registers

More information

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop Chapter 3 3.7 loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop Instructions Format OP rs rt Imm lw $v1, 0($a0) I 35 4 3 0 addi $v0, $v0, 1 I 8

More information

Lecture 6: Assembly Programs

Lecture 6: Assembly Programs Lecture 6: Assembly Programs Today s topics: Procedures Examples Large constants The compilation process A full example 1 Procedures Local variables, AR, $fp, $sp Scratchpad and saves/restores, $fp Arguments

More information

MIPS Instruction Reference

MIPS Instruction Reference Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly

More information

Exceptions, MIPS-Style

Exceptions, MIPS-Style Exceptions, MIPS-Style Reminder: MIPS CPU deals with exceptions. Interrupts are just a special case of exceptions. The MIPS Architecture has no interrupt-vector table! All exceptions trigger a jump to

More information

MIPS%Assembly% E155%

MIPS%Assembly% E155% MIPS%Assembly% E155% Outline MIPS Architecture ISA Instruction types Machine codes Procedure call Stack 2 The MIPS Register Set Name Register Number Usage $0 0 the constant value 0 $at 1 assembler temporary

More information

Shift and Rotate Instructions

Shift and Rotate Instructions Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a

More information

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary Announcements EE108B Lecture MIPS Assembly Language III Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b PA1 available, due on Thursday 2/8 Work on you own (no groups) Homework

More information

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3 A Processor Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 2.16-20, 4.1-3 Let s build a MIPS CPU but using Harvard architecture Basic Computer System Registers ALU

More information

Mark Redekopp, All rights reserved. EE 352 Unit 6. Stack Frames Recursive Routines

Mark Redekopp, All rights reserved. EE 352 Unit 6. Stack Frames Recursive Routines EE 352 Unit 6 Stack Frames Recursive Routines Arguments and Return Values MIPS convention is to use certain registers for this task $a0 - $a3 used to pass up to 4 arguments. If more arguments, use the

More information

MIPS PROJECT INSTRUCTION SET and FORMAT

MIPS PROJECT INSTRUCTION SET and FORMAT ECE 312: Semester Project MIPS PROJECT INSTRUCTION SET FORMAT This is a description of the required MIPS instruction set, their meanings, syntax, semantics, bit encodings. The syntax given for each instruction

More information

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

More information

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Instructions 1 1 Topics: Assembly language, assemblers MIPS R2000 Assembly language Instruction set

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture Computer Science 324 Computer Architecture Mount Holyoke College Fall 2009 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

More information

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology Computer Organization MIPS Architecture Department of Computer Science Missouri University of Science & Technology hurson@mst.edu Computer Organization Note, this unit will be covered in three lectures.

More information

CSE Lecture In Class Example Handout

CSE Lecture In Class Example Handout CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

More information

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University. Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood

More information

MIPS Procedure Calls. Lecture 6 CS301

MIPS Procedure Calls. Lecture 6 CS301 MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #9: MIPS Procedures 2006-07-11 CS 61C L09 MIPS Procedures (1) Andy Carle C functions main() { int i,j,k,m;... i = mult(j,k);... m =

More information

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction page 1 Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... A General-Purpose Computer The von Neumann Model Many architectural approaches

More information

COMP 303 MIPS Processor Design Project 3: Simple Execution Loop

COMP 303 MIPS Processor Design Project 3: Simple Execution Loop COMP 303 MIPS Processor Design Project 3: Simple Execution Loop Due date: November 20, 23:59 Overview: In the first three projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

More information

Instruction Set Architecture of MIPS Processor

Instruction Set Architecture of MIPS Processor CSE 3421/5421: Introduction to Computer Architecture Instruction Set Architecture of MIPS Processor Presentation B Study: 2.1 2.3, 2.4 2.7, 2.10 and Handout MIPS Instructions: 32-bit Core Subset Read:

More information

Patterson PII. Solutions

Patterson PII. Solutions Patterson-1610874 978-0-12-407726-3 PII 2 Solutions Chapter 2 Solutions S-3 2.1 addi f, h, -5 (note, no subi) add f, f, g 2.2 f = g + h + i 2.3 sub $t0, $s3, $s4 add $t0, $s6, $t0 lw $t1, 16($t0) sw $t1,

More information

EE108B Lecture 3. MIPS Assembly Language II

EE108B Lecture 3. MIPS Assembly Language II EE108B Lecture 3 MIPS Assembly Language II Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b 1 Announcements Urgent: sign up at EEclass and say if you are taking 3 or 4 units Homework

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

More information

Implementing Procedure Calls

Implementing Procedure Calls 1 / 39 Implementing Procedure Calls February 18 22, 2013 2 / 39 Outline Intro to procedure calls Caller vs. callee Procedure call basics Calling conventions The stack Interacting with the stack Structure

More information

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Architecture II. Computer Systems Laboratory Sungkyunkwan University MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to a

More information

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information

CS3350B Computer Architecture

CS3350B Computer Architecture CS3350B Computer Architecture Winter 2015 Lecture 4.1: MIPS ISA: Introduction Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted d from lectures on Computer Organization and Design, Patterson & Hennessy,

More information

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions Part Part Part What if we need to call a function inside of a function? Will this work? int twofun(int a, int b) { int res; res = addfun(a, b) a / ; return res; } twofun: addi $sp, $sp, -4 sw $s0, 0($sp)

More information

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b; HW2 solutions 3.10 Pseuodinstructions What is accomplished Minimum sequence of Mips Move $t5, $t3 $t5=$t3 Add $t5, $t3, $0 Clear $t5 $t5=0 Xor $t5, $t5, $t5 Li $t5, small $t5=small Addi $t5, $0, small

More information

All instructions have 3 operands Operand order is fixed (destination first)

All instructions have 3 operands Operand order is fixed (destination first) Instruction Set Architecture for MIPS Processors Overview Dr. Arjan Durresi Louisiana State University Baton Rouge, LA 70803 durresi@csc.lsu.edu These slides are available at: http://www.csc.lsu.edu/~durresi/_07/

More information

CS 4200/5200 Computer Architecture I

CS 4200/5200 Computer Architecture I CS 4200/5200 Computer Architecture I MIPS Instruction Set Architecture Dr. Xiaobo Zhou Department of Computer Science CS420/520 Lec3.1 UC. Colorado Springs Adapted from UCB97 & UCB03 Review: Organizational

More information

CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14

CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14 CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 13 & 14 Dr. Kinga Lipskoch Fall 2017 Frame Pointer (1) The stack is also used to store variables that are local to function, but

More information

SMIPS Processor Specification

SMIPS Processor Specification SMIPS Processor Specification CS250 VLSI Systems Design September 25, 2009 SMIPS is the version of the MIPS instruction set architecture (ISA) we ll be using for the processors we implement in 6.884. SMIPS

More information

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage. CS3410 Spring 2015 Problem Set 2 (version 3) Due Saturday, April 25, 11:59 PM (Due date for Problem-5 is April 20, 11:59 PM) NetID: Name: 200 points total. Start early! This is a big problem set. Problem

More information

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

More information

Stacks and Procedures

Stacks and Procedures Stacks and Procedures I forgot, am I the Caller or Callee? Don t know. But, if you PUSH again I m gonna POP you. Support for High-Level Language constructs are an integral part of modern computer organization.

More information

MIPS Assembly Programming

MIPS Assembly Programming COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

More information

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline. The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

More information

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week

More information

Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values

Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values 1 Arguments and Return Values 2 EE 109 Unit 16 Stack Frames MIPS convention is to use certain registers for this task used to pass up to 4 arguments. If more arguments, use the stack used for return value

More information

MIPS Procedure Calls - Review

MIPS Procedure Calls - Review MIPS Stacks and Subroutine Calls Cptr280 Dr Curtis Nelson MIPS Procedure Calls - Review When making a procedure or function call, it is necessary to: Place parameters you wish to pass where they can be

More information

Lecture 6 Decision + Shift + I/O

Lecture 6 Decision + Shift + I/O Lecture 6 Decision + Shift + I/O Instructions so far MIPS C Program add, sub, addi, multi, div lw $t0,12($s0) sw $t0, 12($s0) beq $s0, $s1, L1 bne $s0, $s1, L1 j L1 (unconditional branch) slt reg1,reg2,reg3

More information

Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures

Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures CS61C L8 Introduction to MIPS : Decisions II & Procedures I (1) Instructor Paul Pearce inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures http://www.xkcd.org/627/ Lecture 8 Decisions & and Introduction

More information

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

CSc 256 Final Spring 2011

CSc 256 Final Spring 2011 CSc 256 Final Spring 2011 NAME: Problem1: Convertthedecimalfloatingpointnumber 4.3toa32 bitfloat(inbinary)inieee 754standardrepresentation.Showworkforpartialcredit.10points Hint:IEEE754formatfor32 bitfloatsconsistsofs

More information

Operands and Addressing Modes

Operands and Addressing Modes Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection L5 Addressing Modes 1 Assembly Exercise Let s write some assembly language programs Program #1: Write a function

More information

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Review: Program Execution. Memory program code program data program stack containing procedure activation records Threads and Concurrency 1 Review: Program Execution Registers program counter, stack pointer,... Memory program code program data program stack containing procedure activation records CPU fetches and executes

More information

ISA: The Hardware Software Interface

ISA: The Hardware Software Interface ISA: The Hardware Software Interface Instruction Set Architecture (ISA) is where software meets hardware In embedded systems, this boundary is often flexible Understanding of ISA design is therefore important

More information

COMP2611: Computer Organization MIPS function and recursion

COMP2611: Computer Organization MIPS function and recursion COMP2611 Fall2015 COMP2611: Computer Organization MIPS function and recursion Overview 2 You will learn the following in this lab: how to use MIPS functions in a program; the concept of recursion; how

More information

MIPS (SPIM) Assembler Syntax

MIPS (SPIM) Assembler Syntax MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS Procedures I Sr Lecturer SOE Dan Garcia 2014-02-14 If cars broadcast their speeds to other vehicles (and the

More information

Chapter 2. Instruction Set Architecture (ISA)

Chapter 2. Instruction Set Architecture (ISA) Chapter 2 Instruction Set Architecture (ISA) MIPS arithmetic Design Principle: simplicity favors regularity. Why? Of course this complicates some things... C code: A = B + C + D; E = F - A; MIPS code:

More information

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A. MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention

More information

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures Review (1/2) CS61C - Machine Structures Lecture 11 - Starting a Program October 4, 2000 David Patterson http://www-inst.eecs.berkeley.edu/~cs61c/ IEEE 754 Floating Point Standard: Kahan pack as much in

More information

MIPS Processor Overview

MIPS Processor Overview MIPS Processor Cptr280 Dr Curtis Nelson MIPS Processor Overview Hardware Design philosophy Architecture Software Assembly language program structure QTSpim simulator Example programs 1 MIPS Processor Power

More information

The MIPS R2000 Instruction Set

The MIPS R2000 Instruction Set The MIPS R2000 Instruction Set Arithmetic and Logical Instructions In all instructions below, Src2 can either be a register or an immediate value (a 16 bit integer). The immediate forms of the instructions

More information

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Review: Program Execution. Memory program code program data program stack containing procedure activation records Threads and Concurrency 1 Review: Program Execution Registers program counter, stack pointer,... Memory program code program data program stack containing procedure activation records CPU fetches and executes

More information

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1

More information

Review: Program Execution. Memory program code program data program stack containing procedure activiation records

Review: Program Execution. Memory program code program data program stack containing procedure activiation records Threads and Concurrency 1 Review: Program Execution Registers program counter, stack pointer,... Memory program code program data program stack containing procedure activiation records CPU fetches and

More information

Lab 4 : MIPS Function Calls

Lab 4 : MIPS Function Calls Lab 4 : MIPS Function Calls Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The objective of this lab

More information

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Architecture I. Computer Systems Laboratory Sungkyunkwan University MIPS Instruction ti Set Architecture I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Architecture (1) the attributes of a system as seen by the

More information

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.) Lecture 3: The Instruction Set Architecture (cont.) COS / ELE 375 Computer Architecture and Organization Princeton University Fall 2015 Prof. David August 1 Review: Instructions Computers process information

More information

4.2: MIPS function calls

4.2: MIPS function calls 4.2: MIPS function calls Topics: Nested function calls: poly() and pow() Saving the return address ($31) Saving temporary registers Looking at activation records on the stack Introduction: In CSc 256 lectures,

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 1, 2014 at 12:03 CS429 Slideset 6: 1 Topics

More information

Lecture 2: RISC V Instruction Set Architecture. Housekeeping

Lecture 2: RISC V Instruction Set Architecture. Housekeeping S 17 L2 1 18 447 Lecture 2: RISC V Instruction Set Architecture James C. Hoe Department of ECE Carnegie Mellon University Housekeeping S 17 L2 2 Your goal today get bootstrapped on RISC V RV32I to start

More information

Procedure Call Instructions

Procedure Call Instructions Procedure Calling Steps required 1. Place parameters in registers x10 to x17 2. Transfer control to procedure 3. Acquire storage for procedure 4. Perform procedure s operations 5. Place result in register

More information

The Program Counter. QtSPIM Register Display (Fixed-Point Registers) Erik Jonsson School of Engineering and Computer Science

The Program Counter. QtSPIM Register Display (Fixed-Point Registers) Erik Jonsson School of Engineering and Computer Science The Program Counter PC = 400064 EPC = 0 Cause = 0 BadVAddr = 0 Status = 3000ff10 1 The program counter is a register that always contains the memory address of the next instruction (i.e., the instruction

More information

8*4 + 4 = 36 each int is 4 bytes

8*4 + 4 = 36 each int is 4 bytes CS 61CL (Clancy) Solutions and grading standards for exam 1 Spring 2009 169 students took the exam. The average score was 43.6; the median was 46. Scores ranged from 1 to 59. There were 89 scores between

More information

Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles.

Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles. ECE 486/586 Computer Architecture Lecture # 8 Spring 2015 Portland State University Instruction Set Principles MIPS Control flow instructions Dealing with constants IA-32 Fallacies and Pitfalls Reference:

More information

Concocting an Instruction Set

Concocting an Instruction Set Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Lab is posted. Do your prelab! Stay tuned for the first problem set. L04 Instruction

More information

Supplement for MIPS (Section 4.14 of the textbook)

Supplement for MIPS (Section 4.14 of the textbook) Supplement for MIPS (Section 44 of the textbook) Section 44 does a good job emphasizing that MARIE is a toy architecture that lacks key feature of real-world computer architectures Most noticable, MARIE

More information

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) Instruction Set Architecture (ISA)... the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data

More information

Recitation 5: Recitation 5: MIPS Interrupts and Floating Point

Recitation 5: Recitation 5: MIPS Interrupts and Floating Point Float Operations We will write a full program to read in two floats, perform an add, subtract, multiply, and divide, printing out each result Let s attempt in C (using blocking IO) Float Operations We

More information

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats Instructors: Vladimir Stojanovic and Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Machine Interpretation Levels of Representation/Interpretation

More information

Threads and Concurrency

Threads and Concurrency Threads and Concurrency 1 Threads and Concurrency key concepts threads, concurrent execution, timesharing, context switch, interrupts, preemption reading Three Easy Pieces: Chapter 26 (Concurrency and

More information

Programming with QtSpim: A User s Manual

Programming with QtSpim: A User s Manual Programming with QtSpim: A User s Manual John McCranie November 15, 2013 1 1 Introduction to SPIM Spim is a self-contained simulator that runs MIPS32 programs. It utilizes the instruction set originally

More information

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences CS61c Summer 2001 Woojin Yu Midterm Exam This is a closed-book exam. No calculators

More information

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h) Problem 1 (20 points) Compilation Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version (in C) to the right. Assume f is a pure function

More information

CSE 305 Introduc0on to Programming Languages Lecture 4. SUNY- Buffalo Zhi Yang Courtesy of Google

CSE 305 Introduc0on to Programming Languages Lecture 4. SUNY- Buffalo Zhi Yang Courtesy of Google CSE 305 Introduc0on to Programming Languages Lecture 4 CSE @ SUNY- Buffalo Zhi Yang Courtesy of Google No0ce Board Homework2 is posted, it is due on June 17, 2013(Monday). You can schedule your 0me working

More information

Instruction Set Architecture (Contd)

Instruction Set Architecture (Contd) Instruction Set Architecture (Contd) Lecture 3 (Chapter 2) EEC170 FQ 2005 Review: MIPS Architecture Good example of RISC processor: Reduced Instruction-Set Computer RISC really a misnomer: architecture

More information

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer Instructions (354 Review) Forecast Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary With a few other things, this defines the interface of computers But implementations

More information