The ARC (A Risc Computer) Instruction Set Computer Architecture and Organization: An Integrated Approach M. Murdocca & V. Heuriong

Similar documents
Instruction Set Architecture

THUMB Instruction Set

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

CPU Organization and Assembly Language

Instruction Set Architecture (ISA)

Chapter 7D The Java Virtual Machine

Introduction to MIPS Assembly Programming

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

MICROPROCESSOR AND MICROCOMPUTER BASICS

Reduced Instruction Set Computer (RISC)

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

MACHINE ARCHITECTURE & LANGUAGE

Instruction Set Reference

MACHINE INSTRUCTIONS AND PROGRAMS

CHAPTER 7: The CPU and Memory

8085 INSTRUCTION SET

EECS 427 RISC PROCESSOR

PROBLEMS (Cap. 4 - Istruzioni macchina)

Typy danych. Data types: Literals:

Computer Organization and Architecture

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Review: MIPS Addressing Modes/Instruction Formats

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

Graded ARM assembly language Examples

LC-3 Assembly Language

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Z80 Instruction Set. Z80 Assembly Language

What to do when I have a load/store instruction?

Computer organization

Microprocessor & Assembly Language

Instruction Set Design

Administrative Issues

Machine Programming II: Instruc8ons

Traditional IBM Mainframe Operating Principles

An Introduction to the ARM 7 Architecture

M6800. Assembly Language Programming

PART B QUESTIONS AND ANSWERS UNIT I

Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

1 Classical Universal Computer 3

IBCM: The Itty Bitty Computing Machine

Chapter 7 Assembly Language

Levels of Programming Languages. Gerald Penn CSC 324

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

An Overview of Stack Architecture and the PSC 1000 Microprocessor

Faculty of Engineering Student Number:

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Programmer s Model = model of µc useful to view hardware during execution of software instructions

Central Processing Unit (CPU)

(Refer Slide Time: 00:01:16 min)

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

X86-64 Architecture Guide

1 Description of The Simpletron

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

612 CHAPTER 11 PROCESSOR FAMILIES (Corrisponde al cap Famiglie di processori) PROBLEMS

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Notes on Assembly Language

Computer Science 281 Binary and Hexadecimal Review

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Instruction Set Architecture

Systems I: Computer Organization and Architecture

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

Keil C51 Cross Compiler

Summary of the MARIE Assembly Language

Developer Suite ARM. Assembler Guide. Version 1.2. Copyright 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B

1 The Java Virtual Machine

The stack and the stack pointer

Chapter 2 Assemblers

RISC Processor Simulator (SRC) INEL 4215: Computer Architecture and Organization September 22, 2004

2) Write in detail the issues in the design of code generator.

BASIC COMPUTER ORGANIZATION AND DESIGN

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine

Appendix C: Keyboard Scan Codes

Instruction Set Architecture (ISA) Design. Classification Categories

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

The 104 Duke_ACC Machine

A SystemC Transaction Level Model for the MIPS R3000 Processor

Z80 Microprocessors Z80 CPU. User Manual UM Copyright 2014 Zilog, Inc. All rights reserved.

Efficient Low-Level Software Development for the i.mx Platform

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

2.2: Bitwise Logical Operations

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

ARM Instruction Set. ARM7TDMI-S Data Sheet. Final - Open Access

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Chapter One Introduction to Programming

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

Let s put together a Manual Processor

MIPS Assembler and Simulator

Transcription:

The ARC (A Risc Computer) Instruction Set Computer Architecture and Organization: An Integrated Approach M. Murdocca & V. Heuriong Spring 2010-1 -

The ARC (A Risc Computer) Instruction Set Computer Architecture and Organization: An Integrated Approach; 2007 by M. Murdocca & V. Heuring Example: A simple ARC programming example!! A simple ARC program to add two numbers!.begin.org 2048 main: ld [x], %r1! load x into %r1 ld [y], %r2! load y into %r2 addcc %r1, %r2, %r3! %r3 <- %r1 + %r2 st %r3, [z]! store %r3 into z halt! halt simulator x: 15 y: 9 z: 0.end jmpl %r15+4, %r0 Observe the following! standard return 1..begin and.end directives must enclose the program 2. By convention code begins at address 2048; hence the.org 2048 directive 3. The ARC is a load and store architecture; all arithmetic and logical operations are register to register; the only memory reference operations are load (ld) and store (st). 4. Arithmetic and logical operations have two source operands and one destination operand. The two source operands are both registers (denoted rs1 and sr2) or a register (rs1) and a 13 bit signed integer (imm13); the destination operand is always a register (rd). 5. The 32 32-bit registers are denoted %r0 through %r31. %r0 is fixed at zero; it cannot be changed. Registers %r14 and %r15 are the stack pointer and link register respectively. The latter is used to store the return address during a subroutine call. 6. Data flow is left to right (i.e. src -> dest) ; that is ld [x],%r1 loads x into %r1 while st %r3, [z] stores %r3 into z. The same is true for arithmetic operations: addcc %r1, %r2, %r3 which adds %r1 plus %r2 into destination register %r3 (and sets the condition code registers accordingly - see below) 7. Only those arithmetic and logic operations with cc suffixes set/clear the four condition flags: N (negative), Z (zero), C (carry) and/or V (signed over flow); 8. Comments begin with! 9. There are a limited number of memory addressing modes; ld [x], %r1 is an example of direct addressing. Other addressing modes are register indirect: ld %r2, %r1 where %r2 contains the effective address of the source operand - 2 -

base plus offset: ld [%r2+x], %r2 where the effective address of the source operand is found by adding x to the contents of register %r2 In addition arithmetic operations have an immediate mode; for example jmpl %r15+4,%r0 adds 4 to register %r15 10. Since %r0 is always zero, any time it is used as a destination register, the results are thrown away (see jmpl %r15+4,%r0 above). 11. The data area (where x, y, and z are located) can go anywhere; here the data area immediately follows the code. Optionally a.org directive could have been used to locate the data area in memory (see below). 12. The instruction jmpl %r15+4,%r0 is technically a return to the operating system (assuming that %r15 contains the address of the call statement that invoked the program from the operating system). Since the ARC simulator does not support an operating system, %r15 is probably empty which means execution of this instruction would cause a branch to address 4. Hence the halt command before the jmpl instruction. A Subset of ARC Assembly Language Instructions (ARC-Lite) type menmonic ccversion semantics example memory ld load register from memory ld [x], %r1 st store register to memory st %r2, [y] arith. add addcc add: rs1 + rs2 -> rd add %r1,%r2,%r3 sub subcc subtract: rs1 rs2 -> rd sub %r1,%r2,%r3 logic and andcc and: rs1 & rs2 -> rd and %r1,%r2,%r3 or orcc or: rs1 rs2 -> rd orn orncc or not: rs1 rd2 -> rd to complement use: orn %r0, rs2, rd xor xorcc exclusive or sll shift left logical sll %r1,1,%r1 sra shift right arithmetic sra %r1,1,%r1 control be branch on equal (Z==0) be L1 bne branch on not equal (Z==1) bne L1 bneg branch on negative (N==1) bneg L1 bpos branch on positive (N==0) bpos L1 ba branch always ba L1 subroutine call call subroutine return call subr address stored in %r15 jmpl jump and link return: jmpl %r15+4,%r0 halt halt (non-standard) - 3 -

Opcode 00: SETHI/Branch Format SETHI 0 0 rd op2 imm22 rd = imm22 << 10 (left shift 10) The purpose of the SETHI instruction is to set the high-order bits of a register to a 22 bit quantity. Branch 0 0 0 cond op2 disp22 Eaddr = sign_extend(disp22) << 2 (note word alignment) %pr = %pc + EAddr The N,V, Z, and C bits set by a previous cc -type operation are tested and if the condition is met a relative jump is taken by adding the distance (in word) between the branch instruction and the target address to the program counter. ba Branch Always bn Branch Never Branch on Flags bpos Branch on Positive (i.e. N == 0) bneg Branch on Negative (i.e. N == 1) be Branch on Equal (i.e. Z == 1) bne Branch in No Equal (i.e. Z == 0) bvc Branch on Overflow Clear (i.e. V == 0) bvs Branch on Oversflow Set (i.e. V == 1) bcc Branch on Carry Clear (i.e. C == 0) bcs Branch on Carry Set (i.e. C == 1) Unsigned Comparison Branching bgu Branch on Greater than unsigned (i.e. C Z == 0) bleu Branch on Less than or Equal to Unsigned (i.e. C Z == 1) Note: Unlike the ARC, the SPARC supports bgeu (branch on greater than or equal unsigned) and blu (branch on less than unsigned) instructions which are synonyms for the bcs and bcc instructions respectively. Note that a 22 bit displacement gives you a restricted range of from -2 21 to +2 21-1 words between the branch instruction and the target. - 4 -

Signed Comparison Branching bg Branch on Greater than bl Branch on Less than ble Branch on Less than or equal bge Branch on Greater than or Equal Example of signed comparison subcc %r1, %r2, %r0! if %r1 > %r2 bg L1! goto L1 Example of count-down loop from 10 to 0 Loop: add %r0, 10, %r10! %r10 initialized to 10! loop begins here subcc %r10, 1, %r10! decrement %r10 bg Loop! loop if > 0 Opcode 01: Call Format (1 instruction in this class) 0 1 disp30 %r15 = %pc %pc = %pc + sign_extend(disp) << 2 Store the program counter in register %r15 (for eventual return) and branch to the subroutine. Like the branch instruction this is relative jump taken by adding the sign-extended displacement to the program counter but with a 30 bit displacement left shifted by 2 to enforce word-alignment, this given you a range covering the entire ARC memory. Note: A return is performed by the jmpl %15+4, %r0 instruction (below) Opcode 02: Arithmetic/Logic Operations 1 0 rd op3 rs1 0 rs2 The two operands are the contents of the two source registers rs1 and rs2. 1 0 rd op3 rs1 1 simm13 The two operands are source register rs1 and the simm13 field sign extended to a 32 bit quantity. op2 (below) refers to the second operand either rs2 or sign-extend(simm13) - 5 -

Arithmetic Operations add addcc examples add r1%, r2%, r%r3! %r3 = %r1 + r%2 sum contents of two registers add r4%, 1, %r4! increment %r4 sub subcc examples sub %r5, %r6, %r7! %r7 = %r5 - %r6 - order is important sub %r8, 1, %r8! decrement %r8 Logical Operations and andcc used to mask and test bits andn ( a and not b) andncc or orcc used to set bits orn (a or not b) orncc Note: this is NOT equivalent to nor %r0 orn %r1 complements %r1 xor xorcc exclusive OR xnor xnorcc exclusive NOR - Note: a xnor b = a xor b Shift Operations sll (shift left logical) shr (shift right logical) sra (shift right arithmetic) rd = left-shift(rs1, op2) where op2 is number of bits to shift rd = right-shift(rs1, op2) rd = arithmetic-right-shift(rs2, op2) Special Return Operation/Halt Instruction jmpl jump and link This instruction is used as a return from subroutine call. Essentially the following operations are executed Example %rd = %pc %pc = %rs1 + op2! save %pc in destination register %rd! jump to address %rs1 + op2 jmpl %r15,4,%r0! return from subroutine Note: Since %r15 contains the address of call instruction itself, you must add 4 to branch to the instruction following the Call instruction. halt this (non-standard) instruction will halt the simulator; programs should end with this. - 6 -

Opcode 03: Memory Format Instructions Load and Store 1 1 rd op3 rs1 0 rs2 EAddr = %rs1 + %rs2 The effective address is obtained by adding the contents of %r1 and %r2 1 1 rd op3 rs1 1 simm13 EAddr = %rs1 + sign_extend(simm13) The effective address is obtained by adding the sign-extended simm3 field to register %rs1 ld load word (address must be word-aligned i.e. end in 00) examples ld [x], %r3! load x to %r3 ld %r1, %r4! %r1 contains address of word to load ld %r1, 4, %r5! load next word ld [%r1 + 4], %r5! alternate notation ldub load unsigned byte ldsb load sign-extended byte lduh load unsigned half-word (address must be half-word aligned address ends in 0) ldsh load sign-extended halfword (address must be half word aligned) st store word (note rd field used for source!) examples st %r3, [y]! store %r3 at y st %r4, %r1! store %r4 at address contained in %r1 st %r5,4,%r1! store %r5 at next location st %r5, [%r1 + 4]! alternate notation? stb store byte sth store halfword - 7 -

Doing I/O using ARC Memory Mapped I/O There are no explicit I/O instructions for the ARC; instead I/O is done by reading from (loading) and writing to (storing) fixed memory locations in upper memory which are assigned to I/O devices. This is referred to as memorymapped I/O. For each device there is a data port and a status port both of which are memory addresses; the later used to test the status of the I/O device to insure it is ready. The ARC simulator has a console output port to display characters and a keyboard input port to read characters. Output: Address 0xffff0000 is the console (output) data port; address 0xffff0004 is the console (output) status port where bit 7 is the ready flag (0 not ready / 1 ready). Printing a character is done by storing the character to the output data port after first checking that bit 7 (ready flag) of the output status port is set to 1 (ready). Example: A Hello World! program! Prints "Hello World!\n" in the message area.begin BASE.equ 0x3fffc0 COUT.equ 0x0 CONSTAT.equ 0x4! starting point of memory mapped area! 0xffff0000 Console Data Port! 0xffff0004 Console Status Port.org 2048 Main: add %r0, %r0, %r2! clear %r2 add %r0, %r0, %r4! clear %r4 sethi BASE, %r4 Loop: ld [%r2 + String], %r3! load next character addcc %r3, %r0, %r3! test for null be End Wait: ldub [%r4+constat],%r1! test console andcc %r1, 0x80, %r1! status be Wait! if busy loop stb %r3, [%r4+cout]! otherwise print add %r2, 4, %r2 ba Loop End: halt ba Main! increment string offset.org 3000 String:0x48, 0x65, 0x6c, 0x6c, 0x6f! Hello 0x20, 0x77, 0x6f, 0x72, 0x6c! Worl 0x64, 0x21, 0x0a, 0x00! d!\n.end - 8 -

Input: Address 0xffff0008 is keyboard (input) data port; address 0xffff000C is the keyboard (input) status port where bit 7 is the ready flag (0 not ready / 1 ready). To read a character first check that the keyboard status bit 7 is set (ready) then load the character from the keyboard data port Example: A program to read and echo a character! Typewriter.asm.begin BASE.equ 0x3fffc0 COUT.equ 0x0 CONSTAT.equ 0x4 CIN.equ 0x8 CICTL.equ 0xc! Starting point of memory mapped area! 0xffff0000 Console Data Port! 0xffff0004 Console Status Port! 0xffff0008 Keyboard Data Port! 0xffff000c Keyboard Control Port.org 2048 Main: add %r0, %r0, %r4! clear %r4 sethi BASE, %r4 InWait: ldub [%r4+cictl], %r1! check kbd status andcc %r1, 0x80, %r1 be InWait ldub [%r4 + CIN], %r3! get character subcc %r3, 27, %r0! check for (esc) be End Wait: ldub [%r4 + CONSTAT],%r1! check console status andcc %r1, 0x80, %r1 be Wait stb %r3, [%r4 + COUT]! echo character ba InWait End: halt ba Main.end Note: You must click (activate) the Message Window at the bottom of the simulator first in order for the program to respond to keystrokes. - 9 -