Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
INSTRUCTION SET ARCHITECTURES
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
1 Registers and MAL - Part I. Motivation So far there are some details that we have ignored instructions can have different formats most computers have.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Execution of an instruction
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
State Machines Timing Computer Bus Computer Performance Instruction Set Architectures RISC / CISC Machines.
Part II: Addressing Modes
MIPS Instruction Set Advantages
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
MIPS assembly. Computer What’s in a computer? Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
1 Appendix B Classifying Instruction Set Architecture Memory addressing mode Operations in the instruction set Control flow instructions Instruction format.
Memory and Addressing How and Where Information is Stored.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
CSCI 136 Lab 1: 135 Review.
Execution of an instruction
Computer Organization – Memory Access David Monismith Jan. 30, 2015 Based upon notes by Dr. Bill Siever and the Patterson and Hennessy Text.
CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Computer Architecture Lecture 03 Fasih ur Rehman.
Computer Organization Rabie A. Ramadan Lecture 3.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
Data Structures - Part I CS 215 Lecture 7. Motivation  Real programs use abstractions like lists, trees, stacks, and queues.  The data associated with.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Memory Access Instructions Load and Store Addressing Modes Memory Addressing. Base addressing mode. Load byte and store byte: lb, lbu, sb Address alignment.
CS 312 Computer Architecture & Organization
CS/COE 0447 (term 2181) Jarrett Billingsley
Memory Access Instructions
MIPS Instruction Set Advantages
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Organization and Assembly Language (COAL)
Instructions - Type and Format
The University of Adelaide, School of Computer Science
MIPS assembly.
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Introduction to Micro Controllers & Embedded System Design
Computer Instructions
3.
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS Assembly.
Control Flow and Arrays
Presentation transcript:

Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6

Motivation u Real programs use abstractions like lists, trees, stacks, and queues. u The data associated with these abstractions must be ordered within memory. u Assembly language does not provide convenient ways to access data in memory like high-level languages do. u It therefore necessary to calculate explicitly the locations of data within the structure.

Memory u A memory cell is a unit of memory with a unique address. u The entire memory is a collection of memory cells. u Each memory cell holds eight bits, or 1 byte. u A word designates the amount of memory used to store an integer, e.g., 1 word = 4 bytes

Storing an integer u Assume a 32-bit word. The number of bits used to store an integer is 32 or 4 bytes. It can also be thought of as an array of 4 bytes. u By convention, the smallest of the four byte addresses is used to indicate the address of the word. u The smallest of the byte addresses in a word must be a multiple of four  words are aligned

RISC: load/store architecture u Most RISC designs don't allow arithmetic and logic instructions to access memory  Source, target of operation must be registers u A few special load/store instructions are used to move data from memory to registers  This means RISC architecture require more registers than CISC architectures

Specifying an address u In a load/store architecture, only two types of instructions specify addresses:  store and load instructions  control instructions u Control instructions specify the target address of the next instruction if the control of the program execution is to be transferred there  branch  jump

PC-relative addressing u A machine language instruction can specify the target of a branch as an offset to the address of the instruction. u The offset is added to the value of the PC to find the effective address of the next instruction. An addressing mode that implies the use of a PC is PC-relative. offset beqvar1var2 program counter (PC) address + effective address

Load and store instructions lw R, address u R is the target register. In its most general form the address can include both a constant (which can be a label) and a base register. For example, lw $22, 12($25)  The effective address is computed by adding 12 to the contents of the base register $25. Note that ($25) means the contents of register 25. The word at the effective address is loaded into register 22. Make sure that the effective address is a multiple of 4.

Store to memory  Data can be copied from the register R to the memory location specified by address sw R, address Similar to the load instruction the address can include both a constant and a base register specification. sw, $13, 4($9) The effective address is computed by adding 4 to the contents of register 9.

 The sb is equivalent to the store word instruction, sw, only that it stores 1 byte instead of 4 bytes to the effective address. Only the least significant byte of the register is used.  The lb and lbu instructions load the byte into the least significant byte of the register.  lbu loads the byte as unsigned, i.e. the other three bytes in the register are set to 0  lb sign-extends the byte -- the other three bytes are set to whatever the sign of the byte is. Byte access

Valid memory reference formats u lw $s0, label u sw $s0, label($s1) u sb $s2, 16($t0) u lw $s0, ($s3)

Array u The array is the most important and most general data structure. u All other data structures can be implemented using an array. u The computer memory itself is organized as a large, one- dimensional array. u All uses of the memory are simply allocations of part of this gigantic array. 0x xffffffff

Allocating Space for Arrays u To allocate space for an array of ASCII characters {label}:.ascii “abcdef” {label}:.asciiz“abcdef” #null terminated u An array of integers can be allocated space and initialized using the word directive {label}:.word2, 4, 8, 0x10, 32 u An array of un-initialized bytes can be allocated using the space directive {label}:.space 80 #space for 20 integers #or 80 characters

Accessing Array Elements  To access element i of the array, we must add an offset to the array’s starting address, also called the base address. This is the address associated with the label of the array.  We must make sure that the value of i is the correct displacement between the i th element and the base address. u For ease of calculation, we assume the array is indexed starting with 0, as in C or C++

Accessing Array Elements ar:.space 20 #20-element array of char... la $s0, ar #get the base address lb $s1,5($s0) #access the target element target element base address address of target element

Finding the Element Address The formula for finding the address of an element in an array can be generalized to b = base address s = size of each element i = number of positions between the target and the base address char = 1 byte integer = 4 bytes can be viewed as an offset from the base address a = b + s*i

Two-dimensional Arrays u The number of bytes needed for the array is found by multiplying the size of each element times the number of elements 2 x 7 array

Example 15.4 To declare a 2 x 7 array of integers, we can use the following: ar:.space 56 7 x 2 x (4 bytes)

Storage Order Row-major order: the array is stored as a sequence of arrays consisting of rows (0,0) (0,1) (0,2)

Storage Order Column-major order: The array is stored as a sequence of arrays consisting of columns instead of rows (0,0) (1,0) (0,1)

Accessing elements in 2D arrays We know that the formula for finding the address of an element (x, y) in an array of size L x W is a = b + s*I I = e*j + k e = range of the minor dimension (L or W) j = index of the major dimension (y or x) k = index of the minor dimension (x or y)

Example: 2-D array Row-major order: e = 4, j = 1, k = 2 a = b + s*6 Column-major order: e = 3, j = 2, k = 1 a = b + s* x