CSCI206 - Computer Organization & Programming

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
CS/COE0447 Computer Organization & Assembly Language
Branches Two branch instructions:
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
CSCI 136 Lab 1: 135 Review.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
17 - Jumps & Branches. The PC PC marks next location in Fetch, Decode, Execute cycle.
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture & Operations I
CSCI206 - Computer Organization & Programming
Prof. Hsien-Hsin Sean Lee
Lecture 6: Assembly Programs
MIPS Instruction Set Advantages
Example Addiu $t1 $r0 3 Addiu $t1 $t1 5 Addiu $t1 $t1 7.
Morgan Kaufmann Publishers
MIPS Coding Continued.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Lecturer PSOE Dan Garcia
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Pick up the handout on your way in!!
Henk Corporaal TUEindhoven 2010
Computer Architecture & Operations I
MIPS Instructions.
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Lecture 7: Examples, MARS, Arithmetic
Instruction encoding The ISA defines Format = Encoding
MIPS coding.
MIPS Coding.
The University of Adelaide, School of Computer Science
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Flow of Control -- Conditional branch instructions
Instruction encoding The ISA defines Format = Encoding
Lecturer SOE Dan Garcia
Instruction encoding The ISA defines Format = Encoding
The branch instruction
MIPS Assembly.
Flow of Control -- Conditional branch instructions
Instruction encoding The ISA defines Format = Encoding
MIPS Coding Continued.
MIPS assembly.
Program Assembly.
Conditional Control Structure
MIPS instructions.
Conditional Branching (beq)
Control Flow and Arrays
Presentation transcript:

CSCI206 - Computer Organization & Programming Pseudo-Instructions and Addressing Data zyBook: 5.8, 5.9

Pseudo-instructions beq $t, $s, label What is a pseudo-instruction? A pseudo-instruction is not a real MIPS instruction, but one we can use as if it were. For example, we know these two MIPS instructions beq $t, $s, label bne $t, $s, label But we don’t have something like blt $t, $s, label Or the like

MIPS Pseudo-instructions MIPS provides a set of such pseudo-instructions to make programmers’ life easier. Typically these pseudo-instructions are translated into real instruction at the assembly time For example implement the following using slt and bne, blt $t, $s, label Can be implemented as slt $at, $t1, $t2 bne $at, $zero, label

Another example Can be implemented using lui and ori as li $t0, 0x8C828A43 # load immediate Can be implemented using lui and ori as lui $at, 0x8c82 # load upper immediate ori $t0, $at, 0x8a43 # or immediate [let’s do the worksheet]

Registers Addressing data in a register Encode the register number (0-31) in the machine instruction R/I formats

Immediates Immediate data can be encoded in an I type instruction this data is implicitly addressed what are the limitations?

32-bit Values from Immediates step 1: lui - load upper immediate lui $t0, 0x00FF step 2: ori - or immediate ori $t0, $t0, 0xFF00 final result in $t0 0000 0000 1111 1111 1111 1111 0000 0000 which is 0x00FFFF00 MIPS optimizes for the common case, small immediate values two instructions are handle the other (less common) cases.

Basic Program Memory Map Local (automatic) variables inside functions; activation records (recursion); unsafe to share between functions / modules Dynamic (runtime) allocation Dynamically allocated memory; safe to share between functions / modules Global variables Static (compile time) allocation Your program’s compiled machine code

Base + displacement addressing lw/lh/lb sw/sh/sb e.g., lw $t0, 32($s0) # load value at memory address $s0 + 32 onto $t0 Construct a memory address from a base address in a register plus some immediate offset Useful for variables top of stack/heap in $sp/$gp register, immediate value selects offset Useful for arrays beginning of array in a register, immediate value selects the index

PC-Relative Addressing (branches) PC is the Program Counter, it is the address of the instruction being executed. e.g., beq $s0, $s1, label # if $s0 has the same value as $s1, jump to label I-format instruction provides a 16 bit offset, relative to the next instruction. Good for short branches (local loops, if, case, etc). Not enough bits for function calls (can’t jump very far away).

MIPS Branch Distance The branch immediate address is a sign extended (2's complement) value added to the current PC Since we are dealing with instructions that must be word aligned (32-bit), the last 2-bits are assumed to be 00, therefore a branch can reach +0x1fffc or -0x20000 bytes! That is +32767 or -32768 instructions (words) from current instruction address.

MIPS Branch Distance Computation Why between +0x1fffc and -0x20000 bytes? The 16-bit immediate has a range from 0x0000 to 0xFFFF, the largest positive value is 0x7FFF and the smallest negative value (largest in absolute value) is 0x8000. We shift the value to the left by two positions (adding two 0’s) to get the word addresses. 0x7FFF << 2 results in 0x1FFFC 0x8000 << 2 results in 0x20000

Pseudo-direct Addressing J-type instructions contain a 26-bit word address (unsigned) (28-bit byte address), 2^28 == 256 MB range This leaves the upper 4-bits unaccounted for Uses the upper 4-bits of the next PC value This is enough for most programs How could you jump beyond the 256 MB?

MIPS Addressing Summary