Arrays and Pointers Variables are just names of memory locations An array is a variable (just with many memory locations – all contiguous) Address = pointer.

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Catch up on previous topics Summary and putting together first four classes.
OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify.
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
Branches Two branch instructions:
Programming and Data Structure
SPIM and MIPS programming
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
MIPS Assembly Language Programming
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Addressing modes – 1 The way in which an operand is specified is called the Address Mode.
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
L5 – Addressing Modes 1 Comp 411 – Spring /29/08 Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
MIPS coding. SPIM Some links can be found such as:
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
Computer Architecture and the Fetch-Execute Cycle
Working With Main Memory. Why Main Memory Register space limited Used for communication.
Computers and programming The 4 th lecture Jiří Šebesta.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Computer Organization – Memory Access David Monismith Jan. 30, 2015 Based upon notes by Dr. Bill Siever and the Patterson and Hennessy Text.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Computer Organization and Design Addressing Modes Montek Singh Sep 30, 2015 Lecture 7.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems.
Accessing Memory Chapter 5 Lecture notes for SPARC Architecture, Assembly Language Programming and C, Richard P. Paul by Anu G. Bourgeois.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Winter 2016CISC101 - Prof. McLeod1 Today Numeric representation (or “How does binary and hexadecimal work?”). How can a CPU understand instructions written.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
June 14, 2016Machine Language and Pointers1 What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; }
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Computer Organization Exam Review CS345 David Monismith.
Addressing Modes in Microprocessors
Data Transfers, Addressing, and Arithmetic
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
L7 – Assembler Directives
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Lecture 4: MIPS Instruction Set
These are slides from Comp411
(Array and Addressing Modes)
MIPS Instructions.
(Array and Addressing Modes)
MIPS Coding.
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
Generalities for Assembly Language
Addressing Modes Don Porter.
(Array and Addressing Modes)
Presentation transcript:

Arrays and Pointers Variables are just names of memory locations An array is a variable (just with many memory locations – all contiguous) Address = pointer (in function, not C++ syntax) Address = pointer in assembler (no data typing)

Allocating an Array You have to know the size in bytes of each element of the array –Int = 4 bytes –Float = 4 bytes –Char = 1 byte Determine the number of bytes needed –Size*quantity Allocate space (in bytes) arr:.space100

Memory Access Remember, the REAL assembly language can only access memory via number($R) –Or disp(base) where disp is a number and base is a register –The address is the value in the base register added to the displacement

The la command The la (load address) macro command is very helpful (especially with arrays) We will load the address of the data section. The data section always starts at memory location x –Look at the first 4 hex char (x1001). –This is 4097 in decimal

The lui command Used by the assembler a lot –Some instructions only have a 16 bit operand –To get a 32 bit value into a register, we need two instruction lui – load upper immediate –Loads the upper 2 bytes (16 bits) of the register with the specified value and places 0’s in the last 16 bits –ori – or immediate – logically or’s the last 16 bits of a register with the immediate operand.

Back to the la So, to load the 32 bit address of a variable into $t1, the assembler uses: –lui $t1,4097 #now t1 has the addr of the data section –ori $t1,offset #the distance the var is from the beginning of the.data This replaces the la $t1,var instruction

Working with Arrays First, get the address of the array into a register –la $t1,arr To get to element i of an array, you multiply i by the size of an element and add that to the base address of the array. –This gives the address of arr[i]

Processing an entire array If you are looping through an array, rather than multiply, you could just add the size of an element to the “current” address to get the address of the next element Example: for (i=0; i<25; i++) arr[i]=i;

In assembler In the.data section arr:.space100 In the.text section la$t1,arr li$t2,0 #i li$t3,25 #limit loop: beq$t2,$t3,done sw$t2,0($t1) addi$t1,4#address increases by 4 addi$t2,1#counter increases by 1 jloop done:

Other examples Look at the reverse string example Look at the binary search example Look at the sorting example