Chapter 15: Higher Level Constructs

Slides:



Advertisements
Similar presentations
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Advertisements

ARM versions ARM architecture has been extended over several versions.
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
CS/COE0447 Computer Organization & Assembly Language
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
ARM Microprocessor “MIPS for the Masses”.
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
Chapter 15: Higher Level Constructs CEG Microcomputer Systems CEg2400 Ch15 Higher Level Constructs V4b 1 Reference Steven Furber, ARM system-on-chip.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Lecture 4. ARM Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
F28HS2 Hardware-Software Interfaces Lecture 7: ARM Assembly Language 1.
EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – ARM Addressing Endianness, Loading, and Storing Data – Data Layout Struct Packing.
Lecture 8: Loading and Storing to Memory CS 2011 Fall 2014, Dr. Rozier.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
ARM Shifts, Multiplies & Divide??. MVN Pseudo Instructions Pseudo Intruction: Supported by assembler, not be hardware.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value),
Computer Architecture & Operations I
Deeper Assembly: Addressing, Conditions, Branching, and Loops
Smruti Ranjan Sarangi, IIT Delhi Chapter 4 ARM Assembly Language
Chapter 15: Higher Level Constructs
Instruction sets : Addressing modes and Formats
MIPS Instruction Set Advantages
Introduction to the ARM Instruction Set
ECE 3430 – Intro to Microcomputer Systems
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
Making Decisions and Writing Loops
Chapter 4 Addressing modes
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
William Stallings Computer Organization and Architecture 8th Edition
The University of Adelaide, School of Computer Science
CS170 Computer Organization and Architecture I
SCHOOL OF ELECTRONICS ENGINEERING Electronics and Communication
Instructions - Type and Format
Chapter 15: Higher Level Constructs (C and assembly relation)
Lecture 4: MIPS Instruction Set
ARM Control Structures
CSC 3210 Computer Organization and Programming
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Multiplication by small constants (pp. 139 – 140)
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
ARM Control Structures
March 2006 Saeid Nooshabadi
Branching instructions
Overheads for Computers as Components 2nd ed.
MIPS Assembly.
MIPS assembly.
Multiply Instructions
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
Branch & Call Chapter 4 Sepehr Naimi
An Introduction to the ARM CORTEX M0+ Instructions
Arithmetic and Logic Chapter 3
Presentation transcript:

Chapter 15: Higher Level Constructs Reference Steven Furber, ARM system-on-chip architecture Pearson

Introduction Part 1: ARM instructions Part 2 : using assembly to implement C statements. Reference http://www.heyrick.co.uk/assembler/qfinder.html

Part 1 Instructions

Instructions CEG2400 ARM Instruction quick reference.doc Arithmetic ADD{condition}{S} Rd, Rn, <Operand> ADC{condition}{S} Rd, Rn, <Operand> SUB{condition}{S} Rd, Rn, <Operand> SBC{condition}{S} Rd, Rn, <Operand> RSB{condition}{S} Rd, Rn, <Operand> RSC{condition}{S} Rd, Rn, <Operand> MUL{condition}{S} Rd, Rm, Rs MLA{condition}{S} Rd, Rm, Rs, Rn UMULL{condition}{S} RdLo, RdHi, Rm, Rs UMLAL{condition}{S} RdLo, RdHi, Rm, Rs SMULL{condition}{S} RdLo, RdHi, Rm, Rs SMLAL{condition}{S} RdLo, RdHi, Rm, Rs Move MOV{condition}{S} Rd, <Operand> MVN{condition}{S} Rd, <Operand> Logical TST{condition} Rn, <Operand> TEQ{condition} Rn, <Operand> AND{condition}{S} Rd, Rn, <Operand> EOR{condition}{S} Rd, Rn, <Operand> ORR{condition}{S} Rd, Rn, <Operand> BIC{condition}{S} Rd, Rn, <Operand> Compare CMP{condition} Rn, <Operand> CMN{condition} Rn, <Operand> Branch B{condition} label BL{condition} label Load / Store LDR{condition} Rd, <Addressing_mode1> STR{condition} Rd, <Addressing_mode1> Stack LDM{condition}<Addressing_mode2> Rn{!}, <register_list> STM{condition}<Addressing_mode2> Rn{!}, <register_list>

Required fields Required fields <Operand> Immediate value #<immediate_value> Register Rm Logical shift left Rm, LSL #<shift> Logical shift right Rm, LSR #<shift> Arithmetic shift right Rm, ASR #<shift> Rotate right Rm, ROR #<shift> E.g. ADD R0, R2, R3,LSL#1 ; R0 = R2 + (R3 << 1)

Addressing_modes <Addressing_mode1> Zero offset [Rn] Immediate offset [Rn, #+/-< immediate_value>] Register offset [Rn, +/-Rm] Post-indexed Immediate offset [Rn], #+/-< immediate_value> Post-indexed Register offset [Rn], +/-Rm Pre-indexed Immediate offset [Rn, #+/-< immediate_value>]! Pre-indexed Register offset [Rn, +/-Rm]! <Addressing_mode2> Full Descending FD Empty Descending ED Full Ascending FA Empty Ascending EA

Optional fields CEG2400 ARM Instruction quick reference.doc {condition} EQ Equal NE Not equal MI Negative PL Positive or zero VS Overflow VC No overflow HI Unsigned higher LS Unsigned lower or same GE Signed greater than or equal LT Signed less than GT Signed greater than LE Signed less than or equal

Using assembly to implement C statements Part 2 Using assembly to implement C statements

Why? All higher languages (C, C++, Java) must be translated into assembly language/machine code for execution Assemble by an assembler Compilation By a compiler Machine Code in memory Higher level Language C, C++, java Object code In assembly

C statements Pointers Arrays Conditional statements : If-then-else; Switch For loop Do while loop While loop

1) Pointers in C int *p; //integer is 32-bit p = p + 1; p = p + t; Each memory address is 8-bit So each 32-bit has 4 locations int *p; //integer is 32-bit p = p + 1; Since p points to a 4-byte value, p must be incremented by 4 Increment the pointer once , increment address 4 times If p is in register r0 “add r0,r0,#4” p = p + t; p must be incremented by 4 * t, so if t is in r1 add r0,r0,r1,lsl #2; t in r1, old p in r0, lsl #2 = times 4 8-bit

Recall : ADD http://www.heyrick.co.uk/assembler/mov.html#add ADD : Addition ADD<suffix> <dest>, <op 1>, <op 2> dest = op_1 + op_2 ADD will add the two operands, placing the result in the destination register. Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value: ADD R0, R1, R2 ; R0 = R1 + R2 ADD R0, R1, #256 ; R0 = R1 + 256 ADD R0, R2, R3,LSL#1 ; R0 = R2 + (R3 << 1) The addition may be performed on signed or unsigned numbers.

2) Arrays Same as pointers since a[i] is the same as *(a + i)

3) Conditionals in C if (a > b) c = a; else c = b; a, b and c are in r0, r1, r2 resp. cmp r0,r1 ; if a>b ble l1 ; branch to l1“if less or equal” mov r2,r0 ; c=a b end ;done l1 mov r2,r1 ; c=b end yes a>b? (r0>r1)? no c=a (r2=r0) c=b (r2=r1)

exercise1 Conditionals in C if (a <= b) c = a; else c = b; a, b and c are in r0, r1, r2 resp. Write the assembly code

Recall: CMP http://www.heyrick.co.uk/assembler/cmp.html#cmp CMP : Compare CMP<suffix> <op 1>, <op 2> status = op_1 - op_2 CMP allows you to compare the contents of a register with another register or an immediate value, updating the status flags to allow conditional execution to take place. It performs a subtraction, but does not store the result anywhere. Instead, the flags are updated as appropriate.

Recall: MOV http://www.heyrick.co.uk/assembler/cmp.html#cmp MOV : Move MOV<suffix> <dest>, <op 1> dest = op_1 MOV loads a value into the destination register, from another register, a shifted register, or an immediate value. You can specify the same register for the effect of a NOP instruction, or you can shift the same register if you choose: MOV R0, R0 ; R0 = R0... NOP instruction MOV R0, R0, LSL#3 ; R0 = R0 * 8 If R15 is the destination, the program counter or flags can be modified. This is used to return to calling code, by moving the contents of the link register into R15: MOV PC, R14 ; Exit to caller MOVS PC, R14 ; Exit to caller preserving flags (not 32-bit compliant)

Conditionals The method in the previous slide is the most general case, can have many statements in the “if” and “else” parts of the condition For simple cases such as the example, may be more efficient to use conditional execution, e.g. “conditional execution gt” cmp r0,r1 ; compare movgt r2,r0 ;mov=move, ;gt=signed greater than (optional field) movle r2,r1 ;le=signed less than or equal

Switches in C (application of if-then-else) Can be handled using “if” statements; use previous methods tmp = e; if (tmp == 0) { point0; } else if (tmp == 1) { point1; … else { pointx; }… switch (e) { case 0: point0; case 1: point1; … default: pointx; }

For loop in C for (i = 0; i < 10; i++) { a[i]=i-1;} Write the assembly code.

5) Do while one branch is enough do {..do_something.. body; } while (conditional expr); LOOP …do_something.. ; body … ; conditional expr bne LOOP EXIT

6) While loop requires 2 branch instructions while (conditional_expr) {do_something …body;} LOOP … ; not conditional_expr beq exit ;branch exit if condition met …do_something…; body b LOOP EXIT The main loop has 2 branch instructions: slower

Alterative method ‘while’, it is more efficient advantage: The main loop has only one branch instruction: faster while (conditional expr){…do_something...} b TEST ;need this because it is a while _do loop LOOP … do_something ..; loop body TEST…; exit test conditional expression bne LOOP ;loop back if exit condition not met EXIT “Goto exit if test exit condition is met”

Summary Studied the relation between assembly and higher level languages