Data Transfer Instructions

Similar documents
COMP3221: Microprocessors and. and Embedded Systems. Overview. Variable Types and Memory Sections. Types of Variables in C

Assembly Programming (III)

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu

Addressing Modes Part II AVR Addressing Indirect READING

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

CSC 2400: Computer Systems. Using the Stack for Function Calls

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

COMP2121: Microprocessors and Interfacing

Run-time Environments

Run-time Environments

Run Time Environment

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Lecture 5. Announcements: Today: Finish up functions in MIPS

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

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

Procedures and Stacks

Implementing Subroutines. Outline [1]

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Functions in MIPS. Functions in MIPS 1

AVR and MeggyJr Simple

In Java we have the keyword null, which is the value of an uninitialized reference type

AVR ISA & AVR Programming (I)

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Today. Putting it all together

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

Run-time Environment

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

Menu. >Debugging/Simulating in Atmel Studio >Downloading and Debugging/Emulating with the UF-board. Machine Codes 6811: $86 $0A GCPU: $02 $0A

Chapter 9 :: Subroutines and Control Abstraction

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Function Calls and Stack Allocation

Function Calls and Stack Allocation

Stack. Stack. Function Calls and Stack Allocation. Stack Popping Popping. Stack Pushing Pushing. Page 1

Lecture V Toy Hardware and Operating System

Central Processing Unit

CN310 Microprocessor Systems Design

Topic 7: Activation Records

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming

Plan. Regression testing: Demo of how to use the regress.sh script.

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

COMP3221: Microprocessors and Embedded Systems. Lecture 11: Assembly Lecturer: Hui Wu Session 2, 2005

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Some Basic Concepts EL6483. Spring EL6483 Some Basic Concepts Spring / 22

EE 308: Microcontrollers

Course Administration

Stacks and Function Calls

Overview COMP Microprocessors and Embedded Systems. Lectures 18 : Pointers & Arrays in C/ Assembly

COMP2121: Microprocessors and Interfacing

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Using SRAM in AVR assembler language

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e Feb 11, 13, 15, and 25. Winter Session 2018, Term 2

231 Spring Final Exam Name:

Logic Instructions and Programs READING

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CS61C : Machine Structures

Anne Bracy CS 3410 Computer Science Cornell University

Procedure Call. Procedure Call CS 217. Involves following actions

Ch. 11: References & the Copy-Constructor. - continued -

Lecture 7: Procedures and Program Execution Preview

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Control Abstraction. Hwansoo Han

Data Structure Layout. In HERA/Assembly

AVR Subroutine Basics

Chapter 10 Memory Model for Program Execution. Problem

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

ENEE 457: Computer Systems Security. Lecture 16 Buffer Overflow Attacks

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Systems Architecture The Stack and Subroutines

Anne Bracy CS 3410 Computer Science Cornell University

Lecture XXIV: Review Xuan Guo CSC 3210 Computer Organization and Programming Georgia State University April 23, 2015 Xuan Guo Lecture XXIV: Review

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

Lecture 4 CIS 341: COMPILERS

Fundamentals of Programming

Assembly Programming (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science & Engineering Indian Institute of Technology, Kanpur

Computer Architecture and System Software Lecture 07: Assembly Language Programming

COMP2121: Microprocessors and Interfacing. Instruction Formats and Addressing Modes

Module 27 Switch-case statements and Run-time storage management

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Programming Languages

CSC 2400: Computer Systems. Using the Stack for Function Calls

CSE Lecture In Class Example Handout

High Performance Computing Lecture 7. Matthew Jacob Indian Institute of Science

Xuan Guo. Lecture XIX: Subroutines (2) CSC 3210 Computer Organization and Programming Georgia State University. March 31, 2015.

Assignment 11: functions, calling conventions, and the stack

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

Digital Forensics Lecture 3 - Reverse Engineering

Informatica e Sistemi in Tempo Reale

CIT Week13 Lecture

Compilers and computer architecture: A realistic compiler to MIPS

6.004 Computation Structures Spring 2009

CSC 8400: Computer Systems. Using the Stack for Function Calls

3/7/2018. Sometimes, Knowing Which Thing is Enough. ECE 220: Computer Systems & Programming. Often Want to Group Data Together Conceptually

Transcription:

Data Transfer Instructions (Credit: Hui Wu/COMP2121 Lecture Notes) Load Direct (ld): ld Rd, v Rd {r0, r1,..., r31} and v {x, x+, -x, y, y+, -y, z, z+, -z} (remember the X, Y, Z pointers) Load Program Memory (lpm): Can take on three forms, Syntax Operation lpm R0 (Z) lpm Rd, Z R0 (Z)

lpm Rd, Z+ Rd (Z) Z Z+1 Z contains the byte address while the program flash memory uses word addressing. Therefore the word address must be converted into a byte address before having access to the data on the program flash memory. Example usage, (Table_1<<1 converts the word address into a byte address) ldi zh, high(table_1<<1) ; Initialise Z pointer ldi zl, low(table_1<<1) lpm r16, z+ ; r16=0x76 lpm r17, z ; r17=0x58... Table_1:.dw 0x5876.. IN/OUT: AVR has 64 IO registers. Example, in Rd, A out A, Rd where 0 A 63. Push/Pop: The stack pointer (implemented as two 8-bit registers in the I/O space) points to the next free space in RAM above/below (depends how you look at it) the stack. The stack in AVR is part of the SRAM space, and the stack (in AVR) grows from higher memory locations to lower memory locations. I m talking about the actual value of the address, so 0xFFFF is a higher address than 0xDDDD. This got me a little confused at one stage because if you draw a picture of memory with 0 0000 at the top of the diagram, and 0 0001 below it and so on then in reference to the diagram a stack that is getting larger with PUSH operations is growing upwards (you usually associate higher to lower with down, this is why I got confused). So the first thing you must do is initialise the stack pointer (RAMEND is a good starting location). So a push operation, push Rr will push Rr onto the stack (ie. put the contents of Rr into the location that the SP points to), and then decrement the SP by 1. Pop has a similar opposite effect.

Shift Instructions Logical shift left lsl Rd Rotate Left Through Carry rol Rd Both operation change some status register flags. Functions We dabbed into this in first year but just to revise and extend a little I ll try to reiterate this here. The heap is used for dynamic memory applications (eg. malloc()). The stack is used to store return addresses, parameters, conflict registers and local variables and other things. In passing parameters in WINAVR (C compiler for AVR) for say a function call they are passedby value for scalar variables (eg. char, int, float) and passed by reference for non-scalar variables (eg. array, struct). Rules are needed between the caller and the callee to resolve issues such as, how to pass values and references to a function? where to get the return value? how to handle register conflicts? (if a function wants to use a register that was previously in use) how to allocate and deallocate stack memory to and from local variables? If a register is used in both caller and callee and the caller needs its old value after the return from the callee, then a register conflict occurs. Either the compiler or the assembly programmer needs to check for this. The work around is to save the conflict registers on the stack. The return value of a function needs to be stored in designated registers. WINAVR uses r25:r24 for this.

A stack consists of stack frames. A stack frame is created whenever a function is called, and it is freed whenever the function returns. Macros (Credit: Hui Wu/COMP2121 Lecture Notes) The AVR assembler offers macros. A macro is just a segment of code that you define and can then use by just calling the macro. Basically the macro name is just a place holder for the macro code. When the program is assembled the macro name will be replaced by the code that macro defines. This defines a macro named mymacro,.macro mymacro lds r2, @0 lds r3, @1 sts @1, r2 sts @0, r3.endmacro We can then invoke this macro with, mymacro p, q The p, q are used like arguments. So @0 will be replaced with p and @1 will be replaced by q. In AVR you can used @0 up to @9 in the macro body. Assembly Process The AVR assembler uses a two pass process.

Pass One: Lexical and syntax analysis: checking for syntax errors. Record all symbols (labels ) in a symbol table. Expand macro calls. Pass Two: Use symbol table to substitute the values for the symbols and evaluate functions (eg. low(-13167)). Assemble each instruction (ie. generate machine code). For example add Rd, Rr is encoded as machine code as 0000 11rd dddd rrrr. References Wu, Hui. COMP2121 09s1 Lecture Notes. Source: http://andrewharvey4.wordpress.com/2009/04/17/comp2121-wk0304- data-transferfunctions/