March 2006 Saeid Nooshabadi

Slides:



Advertisements
Similar presentations
4.
Advertisements

COMP3221 lec10-logical-II&mul.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 10: C/Assembler Logical and Shift – II & Multiplication.
Chapter 2.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Fall 2011 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
CS 61C L06 MIPS Intro (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
CIS 314: Introduction to MIPS Assembly Language: Arithmetic Fall 2005 I´ve been getting this a lot lately So, what are you teaching this term? Computer.
CS61C L08 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS1104 Assembly Language: Part 1
CS 61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
From C to Assembly Language Jen-Chang Liu, Spring 2006 Adapted from
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
Reformatting a Machine 125 Million Miles Away! Mars rover “Opportunity” got its flash drive reformatted 9/8/14, reason: rover keeps rebooting. Happy news:
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Chapter 2 Instructions: Language of the Computer Part I.
CS2100 Computer Organisation MIPS Part I: Introduction (AY2015/6) Semester 1.
MIPS assembly. Computer  What’s in a computer?  Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
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.
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2014 © UCB TA/Guest Lecturer: Shreyas Chand inst.eecs.berkeley.edu/~cs61c.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 4, EE 334.
CS2100 Computer Organisation
Computers’ Basic Organization
IT 251 Computer Organization and Architecture
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN
Assembly language.
Lecturer PSOE Dan Garcia
MIPS Instruction Set Advantages
Control Unit Lecture 6.
IT 251 Computer Organization and Architecture
Microprocessor Systems Design I
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Microprocessor Systems Design I
IT 251 Computer Organization and Architecture
Number Systems Give qualifications of instructors:
March 2006 Saeid Nooshabadi
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
A Closer Look at Instruction Set Architectures
Give qualifications of instructors: DAP
March 2006 Saeid Nooshabadi
IT 251 Computer Organization and Architecture
The University of Adelaide, School of Computer Science
Chapter 1 C for Embedded Systems.
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Chapter 1 C for Embedded Systems.
MIPS assembly.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Topic 6: Bitwise Instructions
Hello to Jessy VanDivner listening from Ohio!
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Lecture 06 Programming language.
3.
COMS 361 Computer Organization
Instructions in Machine Language
March 2006 Saeid Nooshabadi
Some of the slides are adopted from David Patterson (UCB)
8051 ASSEMBLY LANGUAGE PROGRAMMING
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
CPU Structure CPU must:
Circuit Analysis Procedure by Dr. M
Presentation transcript:

March 2006 Saeid Nooshabadi saeid@unsw.edu.au ELEC2041 Microprocessors and Interfacing Lecture 8: C/Assembler Data Processing http://webct.edtec.unsw.edu.au/ March 2006 Saeid Nooshabadi saeid@unsw.edu.au

Overview C operators, operands Variables in Assembly: Registers Comments in Assembly Data Processing Instructions Addition and Subtraction in Assembly credential: bring a computer die photo wafer : This can be an hidden slide. I just want to use this to do my own planning. I have rearranged Culler’s lecture slides slightly and add more slides. This covers everything he covers in his first lecture (and more) but may We will save the fun part, “ Levels of Organization,” at the end (so student can stay awake): I will show the internal stricture of the SS10/20. Notes to Patterson: You may want to edit the slides in your section or add extra slides to taylor your needs.

Review C Operators/Operands (#1/2) Operators: +, -, *, /, % (mod); 7/4==1, 7%4==3 Operands: Variables: lower, upper, fahr, celsius Constants: 0, 1000, -17, 15.4 Assignment Statement: Variable = expression Examples: celsius = 5*(fahr-32)/9; a = b+c+d-e;

C Operators/Operands (#2/2) In C (and most High Level Languages) variables declared first and given a type Example: int fahr, celsius; char a, b, c, d, e; Each variable can ONLY represent a value of the type it was declared as (cannot mix and match int and char variables).

Assembly Design: Key Concepts Keep it simple! Limit what can be a variable and what can’t Limit types of operations that can be done to absolute minimum if an operation can be decomposed into a simpler operation, don’t include it. For example 7%4 operation is complex. We break it into simpler operations in Assembly

Assembly Variables: Registers (#1/4) Unlike HLL, assembly cannot use variables Why not? Keep Hardware Simple Assembly Operands are registers limited number of special locations built directly into the hardware operations can only be performed on these! Benefit: Since registers are directly in hardware, they are very fast

Assembly Variables: Registers (#2/4) Drawback: Since registers are in hardware, there are a predetermined number of them Solution: ARM code must be very carefully put together to efficiently use registers 16 registers in ARM Why 16? Smaller is faster Each ARM register is 32 bits wide Groups of 32 bits called a word in ARM

Assembly Variables: Registers (#3/4) Registers are numbered from 0 to 15 Each register can be referred to by number or name Number references: r0, r1, r2, … r15 r15 = pc has special significant: r15 is program counter pointing to instructions being fetched from memory

Assembly Variables: Registers (#4/4) By convention, each register also has a name to make it easier to code For now: r0 – r3  a1 – a4 (correspond to C functions arguments. Used for scratch pad too!) r4 – r10  v1 – v7 (correspond to function variables) In general, use names to make your code more readable

Comments in Assembly Another way to make your code more readable: comments! Hash (;) is used for ARMS comments anything from (;) mark to end of line is a comment and will be ignored GNU ARM assembler accepts (@) instead of (;) as well Note: Different from C. C comments have format /* comment */ , so they can span many lines GNU ARM assembler accepts /* comments*/ as well.

Assembly Instructions In assembly language, each statement (called an Instruction), executes exactly one of a short list of simple commands Unlike in C (and most other High Level Languages), each line of assembly code contains at most 1 instruction

Data processing Instructions Largest category of ARM instructions, all sharing the same instruction format. Contains: Arithmetic operations Comparisons (no results saved - just set condition code flags NZCV) Logical operations Data movement between registers This is a load / store architecture These instruction only work on registers, NOT memory. They each perform a specific operation on operands. 4 field Format: 1 2, 3, 4 where: 1) operation by name 2) operand getting result (“destination”) 3) 1st operand for operation (“source1”) 4) second operand: register or shifted register or immediate (numerical constant)

Using the Barrel Shifter: The Second Operand Result ALU Barrel Shifter Operand 2 Register, optionally with shift operation applied. Shift value can be either be: 5 bit unsigned integer add a1, v1, v3, lsl #8 ;a1  v1 +(v3 << 8 bits) Specified in bottom byte of another register. add a1, v1, v3, lsl v4 ;a1  v1 +(v3 << v4 bits) Immediate value. 8 bit number Can be rotated right through an even number of positions. Assembler will calculate rotate for you from constant. add a1, v1, #10 ;a1  v1 + 10

Addition and Subtraction (#1/3) Addition in Assembly Example: add v1,v2,v3 (in ARM) Equivalent to: a = b + c (in C) where registers v1,v2,v3 are associated with variables a, b, c Example: add v1,v2,v3, lsl #1 (in ARM) Equivalent to: a = b + 2 * c (in C) Subtraction in Assembly Example: sub v4,v5,v6 (in ARM) Equivalent to: d = e - f (in C) where registers v4,v5,v6 are associated with variables d, e, f

Addition and Subtraction (#2/3) How do we do this? f = (g + h) - (i + j); Use intermediate register add v1,v2,v3 ; f = g + h add a1,v4,v5 ; a1 = i + j ; need to save i+j, but can’t use f, so use a1 sub v1,v1,a1 ; f=(g+h)-(i+j)

Addition and Subtraction (#3/3) How do the following C statement? a = b + c + d - e; Break into multiple instructions add v1, v2, v3 ; a = b + c add v1, v1, v4 ; a = a + d sub v1, v1, v5 ; a = a - e Notice: A single line of C may break up into several lines of ARM instructions. Notice: Everything after the (;) mark on each line is ignored (comments)

Computers in the News Seagate Technology will begin shipping a higher capacity version of its hard-disk drive for cell phones in the third quarter of this year. The new drive will have a capacity of 12GB, which is a 50 percent increase on its current highest capacity 1- inch drive. Such drives are typically used in cell phones and digital music players. In addition to increased capacity there are three other main improvements offered by the new drive: it consumes almost a third less power than current models, has higher operational shock resistance and is physically smaller.

Addition/Subtraction with Immediates (#1/2) Immediates are numerical constants. They appear often in code, so there are special instructions for them. Add Immediate: add v1,v2,#10 (in ARM) f = g + 10 (in C) where registers v1,v2 are associated with variables f, g Syntax similar to add instruction with register, except that last argument is a number instead of a register. This number should be preceded by (#) symbol

Addition/Subtraction with Immediates (#2/2) Similarly add v1,v2,#-10 f = g - 10 (in C) where registers v1,v2 are associated with variables f, g OR sub v1,v2,#10

Data Movement Instruction Addition with zero is conveniently used to move content of one register to another register, so: add v1,v2,#0 (in ARM) f = g (in C) where registers v1,v2 are associated with variables f, g This is so often used in code that ARM has an specific instruction for it: mov v1, v2 Another useful instruction often used to provide delay in a loop is mov v1, v1 ;this also called nop (No Operation) This does nothing useful

Reverse Subtraction Instruction Normal Subtraction: Example: sub v4,v5,v6 (in ARM); v4  v5 – v6 Equivalent to: d = e - f (in C) where registers v4,v5,v6 are associated with variables d, e, f Reverse Subtraction: Example: rsb v4,v5,v6 (in ARM) ; v4  v6 – v5 Equivalent to: d = - (e) + f (in C) rsb is useful in many situations

ELEC2041 Reading Materials (Week #3) Week #3: Steve Furber: ARM System On-Chip; 2nd Ed, Addison-Wesley, 2000, ISBN: 0-201-67519-6. We use chapters 3 and 5 ARM Architecture Reference Manual –On CD ROM

“And in Conclusion…” New Instructions: New Registers: add sub mov C Function Variables: v1 – v7 Scratch Variables: a1 – a4