Memory. CS 447, Spring /25/16. Memory. Processor (CPU) transfer

Similar documents
syscall takes a service ID (number) in $v0 Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard

Five classic components

2.1 DOWNLOAD AND INSTALL MARS

Course Administration

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

CSCI 402: Computer Architectures

MIPS ProgramTemplate

Computer Organization Lab #3.

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

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

Reduced Instruction Set Computer (RISC)

3. Instruction Set Architecture The MIPS architecture

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

CS3350B Computer Architecture MIPS Instruction Representation

Instruction encoding. MIPS Instruction encoding

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

instructions aligned is little-endian

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

Computer Architecture. MIPS Instruction Set Architecture

Computer Architecture

The MIPS Instruction Set Architecture

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Programming in MIPS. Tutorial

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

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

ECE 154A Introduction to. Fall 2012

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

Reduced Instruction Set Computer (RISC)

MIPS Hello World. MIPS Assembly 1. # PROGRAM: Hello, World! # Data declaration section. out_string:.asciiz "\nhello, World!\n"

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

EE 352 Homework 1 Redekopp Name:

Lecture #6 Intro MIPS; Load & Store

Assembler. Lecture 8 CS301

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

EE108B Lecture 3. MIPS Assembly Language II

EE 109 Unit 8 MIPS Instruction Set

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

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

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

CS 430 Computer Architecture. C/Assembler Arithmetic and Memory Access William J. Taffe. David Patterson

CSSE 232 Computer Architecture I. I/O and Addressing

Compiling Techniques

MIPS Instruction Set

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

Instructions: Language of the Computer

CS 4200/5200 Computer Architecture I

Lecture 7: Examples, MARS, Arithmetic

Chapter 2. Instruction Set Design. Computer Architectures. software. hardware. Which is easier to change/design??? Tien-Fu Chen

EC 413 Computer Organization

TSK3000A - Generic Instructions

Q1: /30 Q2: /25 Q3: /45. Total: /100

CPS311 - COMPUTER ORGANIZATION. A bit of history

MIPS Instruction Format

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

Review: ISA. Review: Compiling Applications. Computer Architecture ELEC3441. Instruction Set Architecture (1) Computer Architecture: HW/SW Interface

Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

MIPS Memory Access Instructions

CPU Architecture and Instruction Sets Chapter 1

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

ECE 486/586. Computer Architecture. Lecture # 6

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

MIPS Assembly Language Programming

ISA: The Hardware Software Interface

MIPS Assembly Language Programming

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

Operations, Operands, and Instructions

Instructions: Language of the Computer

Control MIPS unconditional branch instruction (i.e., jump)

EEC 581 Computer Architecture Lecture 1 Review MIPS

Chapter 2. Instructions:

ECE260: Fundamentals of Computer Engineering

Lecture 2: RISC V Instruction Set Architecture. Housekeeping

מבנה מחשבים Amar Lior Based on lectures notes from Arie Schlesinger

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

MIPS Reference Guide

CENG3420 Lecture 03 Review

Processor design - MIPS

MIPS Assembly Language. Today s Lecture

MIPS Assembly Programming

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

Lecture 2: RISC V Instruction Set Architecture. James C. Hoe Department of ECE Carnegie Mellon University

Reminder: tutorials start next week!

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Midterm. Sticker winners: if you got >= 50 / 67

CSE 2021: Computer Organization

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Transcription:

CS 447, Spring 2016 small number of registers instrucfons operate on operands in registers need memory space to hold data and text 1

Fetch, Execute fetch s (reads) instrucfon from memory to CPU Where is next instrucfon? Text (InstrucFons) Fetch, Execute fetch s (reads) instrucfon from memory to CPU Address A locafon to refer to some locafon in the memory : 0000000c 34240000 Where is next instrucfon? 24020004 2

Fetch, Execute fetch s (reads) instrucfon from memory to CPU : 0000000c 34240000 Where is next instrucfon? 24020004 Fetch, Execute fetch s (reads) instrucfon from memory to CPU : 0000000c 34240000 Where is next instrucfon? 24020004 3

Text (InstrucFons) Text (InstrucFons) 4

Load, Store instruc0ons Load: Read data from the memory Store: Write data to the memory Specifiy register and address Load: DesFnaFon reg ç MEM[address] Store: MEM[address] ç Source reg Specify type (byte, halfword, word) Text (InstrucFons) Load, Store instruc0ons Load: Read data from the memory Store: Write data to the memory Specifiy register and address Load: DesFnaFon reg ç MEM[address] Store: MEM[address] ç Source reg Specify type (byte, halfword, word) Text (InstrucFons) 5

Load, Store instruc0ons Load: Read data from the memory Store: Write data to the memory Specifiy register and address Load: DesFnaFon reg ç MEM[address] Store: MEM[address] ç Source reg Specify type (byte, halfword, word) Text (InstrucFons) Example: Load Word at into $t0 la $t1,0x ABCD1234 Text (InstrucFons) 6

Example: Load Word at into $t0 la $t1,0x ABCD1234 Example: Load Word at into $t0 la $t1,0x address ABCD1234 oper (l) type (w) dest 7

$t0:0 $t1:0 : Example: Load Word at into $t0 la $t1,0x ABCD1234 $t0:0 $t1: : Example: Load Word at into $t0 la $t1,0x ABCD1234 8

$t0:0 $t1: : Example: Load Word at into $t0 la $t1,0x ABCD1234 $t0:abcd1234 $t1: : Example: Load Word at into $t0 la $t1,0x ABCD1234 9

$t0:abcd1234 $t1: $t2:ffffffff : Example: Load Word at into $t0 la $t1,0x Store $t2 to 0 Suppose $t2=fffffff sw $t2,0($t1) ABCD1234 $t0:abcd1234 $t1: $t2:ffffffff :xxxxxxxxx Example: Load Word at into $t0 la $t1,0x Store $t2 to 0 Suppose $t2=ffffffff sw $t2,0($t1) ABCD1234 10

$t0:abcd1234 $t1: :xxxxxxxxx Example: Load Word at into $t0 la $t1,0x Store $t2 to 0 Suppose $t2=ffffffff sw $t2,0($t1) FFFFFFFF $t0:abcd1234 $t1: :xxxxxxxxx Example: Load Word at into $t0 la $t1,0x Store $t2 to 0 Suppose $t2=ffffffff sw $t2,0($t1) Yuck!! Absolute addresses? Labels!!! FFFFFFFF 11

$t0:abcd1234 $t1: :xxxxxxxxx Example: Load Word at into $t0 la $t1,0x Store $t2 to 0 Suppose $t2=ffffffff sw $t2,0($t1) Yuck!! Absolute addresses? Labels!!! FFFFFFFF foo: $t0:abcd1234 $t1: :xxxxxxxxx Example: Load Word at foo into $t0 la $t1,foo Store $t2 to foo Suppose $t2=ffffffff sw $t2,0($t1) FFFFFFFF foo: 12

This is a word: 4 bytes 0xAB,0xCD,0x12,0x34 $t0:0 $t1:0 :xxxxxxxxx ABCD1234 This is a word: 4 bytes 0xAB,0xCD,0x12,0x34 $t0:0 $t1:0 :xxxxxxxxx AB CD 12 34 13

instructions How to get to/from memory? Also called memory access instructions Only two types of instructions Load: move data from memory to register ( load the register ) " e.g., lw $s5, 4($t6) # $s5 memory[$t6 + 4] Store: move data from register to memory ( save the register ) " e.g., sw $s7, 16($t3) # memory[$t3+16] $s7 In MIPS (32-bit architecture) there are memory instructions for 32-bit word: int type in C (lw, sw) 16-bit half-word: short type in C (lh, sh; also unsigned lhu) 8-bit byte: char type in C (lb, sb; also unsigned lbu) 27 view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array 0 BYTE #0 1 2 3 4 5 6 7 8 BYTE #1 BYTE #2 BYTE #3 BYTE #4 BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) loads and stores give the index (address) to access 28 14

view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array lb $t1, 0($t0) loads and stores give the index (address) to access 0 BYTE #0 1 BYTE #1 operation: Load 2 from memory BYTE #2 type: Byte 3 BYTE #3 4 5 6 7 8 BYTE #4 BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) 29 view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array lb $t1, 0($t0) loads and stores give the index (address) to access 0 BYTE #0 1 BYTE #1 determines 2 address BYTE #2 address = 0 + $t0 = 0 + 4 3 BYTE #3 4 5 6 7 8 BYTE #4 BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) 30 15

view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array lb $t1, 0($t0) loads and stores give the index (address) to access 0 BYTE #0 1 BYTE #1 load has destination register $t1 will 2 have contents BYTE #2 at address 4 $t1 will 3 be 0xAB BYTE #3 4 5 6 7 8 BYTE #4 VAL=AB BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) 31 view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array sb $t2, 0($t0) loads and stores give the index (address) to access 0 BYTE #0 1 BYTE #1 store byte register 2 $t2 is source BYTE #2 register suppose 3 $t2=0xfe BYTE #3 4 5 6 7 8 BYTE #4 VAL=AB BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) 32 16

view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array sb $t2, 0($t0) loads and stores give the index (address) to access 0 BYTE #0 1 BYTE #1 store byte register 2 $t2 is source BYTE #2 register suppose 3 $t2=0xfe BYTE #3 4 5 6 7 8 BYTE #4 VAL=FE BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this byte $t0 = 4 lb $t1,0($t0) sb $t2,0($t0) 33 view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array 0 BYTE #0 1 2 3 4 5 6 7 8 BYTE #1 BYTE #2 BYTE #3 BYTE #4 BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this halfword $t0 = 4 lh $t1,0($t0) sh $t2,0($t0) loads and stores give the index (address) to access 34 17

view is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array 0 BYTE #0 1 2 3 4 5 6 7 8 BYTE #1 BYTE #2 BYTE #3 BYTE #4 BYTE #5 BYTE #6 BYTE #7 BYTE #8 address 4 gets this word $t0 = 4 lw $t1,0($t0) sw $t2,0($t0) loads and stores give the index (address) to access 35 Effective Address calculation Effective memory address specified as immediate($register) Register to keep the base address Immediate to determine an offset from the base address Thus, address is contents of register + immediate The offset can be positive or negative, 16-bit value (uses I-format) Suppose base register $t1=64, then: lw $t0, 12($t1) address = 64 + 12 = 76 lw $t0, -12($t1) address = 64-12 = 52 MIPS uses this simple address calculation; other architectures such as Power and x86 support different methods 36 18

Hint on addresses (la - load address) Often, you need to reference a particular variable..data var:.word 0x1000, 0x2000 assembler directive to declare data (word) How to reference var? la $t0,var lw $t1,0($t0) lw $t2,4($t0) puts the address of variable var into $t0 value at the address in $t0 is loaded ino $t1 la is a pseudo-instruction. It is turned into a sequence to put a large address constant into $t0. lui $at,upperbitsofaddres ori $t0,$1,lowerbitsofaddress 37 Let s try an in-class exercise together! Create a word (integer) variable myvar Give the variable the value 20 Print the value to the console (Run I/O window) Terminate the program Extension: Add 10 to the value, store it to myvar, print it To do this, we ll need to use: segment declaration with a word variable type Instruction segment declaration Load word instruction Syscall instruction Assorted la and li instructions 38 19

In-class Example set myvar=20, print myvar, terminate.data myvar:.word 20.text la $t0,myvar # address of myvar lw $a0,0($t0) # load value into $a0 li $v0,1 # print integer service syscall # call operating system li $v0,10 # terminate service syscall # call operating system 39 Another example What about an array? A sequence of data elements Each element can be accessed ( references ) by an index 10 elements: Index 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 E.g., declare a C array of integers with 5 numbers int A[5]; 5elements: A[0], A[1], A[2], A[3], A[4] This is data. How is it represented? 5 integers in memory; an integer is a word in MIPS (4 bytes) Element 0: at lowest address Element 4: at highest address 40 20

50d 40d 10010018 10010014 30d 10010010 20d 10d Text (Instructions) 50d 40d 10010018 A[4] 10010014 A[3] 30d 10010010 A[2] 20d 10d A[1] A[0] Text (Instructions) 21

50d 40d 10010018 10010014 A[4] A[3] 30d 10010010 A[2] 20d 10d A[1] A[0] Example: Write a program to Add 10 to A[0] Text (Instructions) # Example: add 10 to A[0].data array_a:.word 10,20,30,40,50.text la $t0,array_a lw $t1,0($t0) add $t1,$t1,10 sw $t1,0($t0) Use label to reference array load A[0] s value into register store new A[0] s value in memory 22

50d 40d 10010018 10010014 A[4] A[3] 30d 10010010 A[2] 20d 10d A[1] A[0] Example: Write a program to add A[0] and A[1] putting the result in A[3] Text (Instructions) # Example: Write a program to add A[0] and A[1] # putting the result in A[3].data array_a:.word 10,20,30,40,50.text la $t0,array_a lw $t1,0($t0) lw $t2,4($t0) add $t1,$t1,$t2 sw $t1,12($t0) Use label to reference array load A[0] s value into register load A[1] s value into register $t0+4 is next array element Why $t0+12???? A[3] is 12 bytes from A[0] 3 integers * 4 bytes each = 12 23

Organization 32-bit byte address: 2 32 bytes with byte addresses from 0 to 2 32-1 2 30 words with byte addresses 0, 4, 8,, 2 32-4 Words are aligned 2 least significant bits (LSBs) of an address are 0s Half words are aligned LSB of an address is 0 Addressing within a word: Which byte appears first and which byte last? Big-endian vs. little-endian Little end (LSB) comes first (at low address) Big end (MSB) comes first (at low address) 0" 4" 8" 12" 16" 20" Low Address 0" 0" WORD #0" WORD #1" WORD #2" WORD #3" WORD #4" WORD #5" 0 1 2 3 Little Endian Big Endian High Address 3 2 1 0 Alignment A misaligned access Assume $t0=0, then lw $s4, 3($t0) How do we define a word at an address? 0" 0 1 2 3 in byte 0, 1, 2, 3 4" 4 5 6 7 If you meant this, use the address 0, not 3. 8" in byte 3, 4, 5, 6 8 9 10 11 If you meant this, it is indeed misaligned! Certain hardware implementation may support this; usually not. If you still want to obtain a word starting from the address 3 get a byte from address 3, a word from address 4 and manipulate the two data to get what you want Alignment issue does not exist for byte access. Easy rule: Aligned if: ADDRESS mod TYPESIZE == 0 E.g., Is 13 aligned for a word? 13 mod 4!= 0 è not aligned Is 14 aligned for a halfword? 14 mod 2 == 0 è aligned 24