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



Similar documents
Instruction Set Reference

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

Typy danych. Data types: Literals:

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

Instruction Set Architecture (ISA)

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

HC12 Assembly Language Programming

THUMB Instruction Set

Instruction Set Design

Computer Organization and Architecture

Reduced Instruction Set Computer (RISC)

Instruction Set Architecture

Introduction to the Altera Nios II Soft Processor. 1 Introduction. For Quartus II 11.1

Translating C code to MIPS

1 Classical Universal Computer 3

Instruction Set Architecture (ISA) Design. Classification Categories

EC 362 Problem Set #2

Chapter 7D The Java Virtual Machine

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Notes on Assembly Language

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

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

X86-64 Architecture Guide

Sources: On the Web: Slides will be available on:

1 Description of The Simpletron

Adding and Subtracting Positive and Negative Numbers

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

MACHINE ARCHITECTURE & LANGUAGE

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

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

Intel 8086 architecture

MIPS Assembly Code Layout

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

CPU Organization and Assembly Language

Systems I: Computer Organization and Architecture

6. Control Structures

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

We will use the accumulator machine architecture to demonstrate pass1 and pass2.

The stack and the stack pointer

MIPS Assembler and Simulator

Review: MIPS Addressing Modes/Instruction Formats

Number Representation

5 MIPS Assembly Language

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

EECS 427 RISC PROCESSOR

1 The Java Virtual Machine

The Little Man Computer

MACHINE INSTRUCTIONS AND PROGRAMS

LC-3 Assembly Language

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

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Where we are CS 4120 Introduction to Compilers Abstract Assembly Instruction selection mov e1 , e2 jmp e cmp e1 , e2 [jne je jgt ] l push e1 call e

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

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

Computer Systems Architecture

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

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

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

Instruction Set Architecture

BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

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

Summary of the MARIE Assembly Language

MIPS Assembly Language Programming CS50 Discussion and Project Book. Daniel J. Ellard

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

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

CSI 333 Lecture 1 Number Systems

Computer Science 281 Binary and Hexadecimal Review

PART B QUESTIONS AND ANSWERS UNIT I

CS:APP Chapter 4 Computer Architecture. Wrap-Up. William J. Taffe Plymouth State University. using the slides of

Notes on x86-64 programming

Inequalities - Absolute Value Inequalities

Chapter 14: Boolean Expressions Bradley Kjell (Revised 10/08/08)

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

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

5.1 Radical Notation and Rational Exponents

An Introduction to the ARM 7 Architecture

In this Chapter you ll learn:

Compilers I - Chapter 4: Generating Better Code

Lecture 2. Binary and Hexadecimal Numbers

Binomial Probability Distribution

1 One Dimensional Horizontal Motion Position vs. time Velocity vs. time

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Microprocessor & Assembly Language

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

Regression Verification: Status Report

Numbering Systems. InThisAppendix...

CHAPTER 18 Programming Your App to Make Decisions: Conditional Blocks

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Lecture 27 C and Assembly

Chapter 9 Computer Design Basics!

Computer organization

A-level COMPUTER SCIENCE

Solving Rational Equations

CSE 141 Introduction to Computer Architecture Summer Session I, Lecture 1 Introduction. Pramod V. Argade June 27, 2005

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

Transcription:

76 What to do when I have a load/store instruction? Is there a label involved or a virtual address to compute? 1 A label (such as ldiq $T1, a; ldq $T0, ($T1);): a Find the address the label is pointing at (previously defined in a data declaration structure such as data{ }) b Is the address fulfilling the alignment requirement? i Yes 1 Perform the instruction while respecting: a The little Indian rule (first byte store or load is the least significant one) b Are signed loading instructions involved? i Yes: Check the sign of the byte, word, longword, quadword loaded and signextend it to quadword size ii No: If unsigned loading instruction involved, extent the byte, word, longword, quadword, to quadword size by filling the remaining bytes with 0 s ii No 1 Do nothing 2 A virtual address to compute (stq $T0, 5($T1)): a Add the content of the register to the sign-extended 16 bits displacement to obtain the 64 bits address where to load and/or store b Go to 1b to proceed through the instruction

77 Loading/Storing and label To load a quadword from memory (at an address specified by label a) and drop it in register $t0 You need 2 instructions: 1 You need to transfer the address hold by label a (like a move instructions) in a register o ldiq $t1, a; 2 Now you can load, in $t0, a quadword at starting memory address hold by the register used in the previous ldiq command (here $t1) o ldq $t0, ($t1); or ldq $t0, 0($t1); To summarize: Don t try to do ldq $t0, a; it won't compile ldiq $t1, a; ldq $t0, ($t1); will compile Warning: To "store, a quadword holds in register $T0, at memory address specified by label a)" you need to do: ldiq $T1, a; stq $T0, ($T1);

78 Branch Instructions Branch instructions change the control flow of a program Two types of branch instructions exist: Unconditional branch Conditional branch Conditional branch instructions test register Ra and specify a signed 21-bit PC-relative longword target displacement Subroutine calls put the return address in register Ra Conditional branch instructions can test a register for positive/negative or for zero/nonzero, and they can test integer registers for even/odd Unconditional branch instructions can write a return address into a register There is also a calculated jump instruction that branches to an arbitrary 64-bit address in a register Unconditional branch br is an unconditional branch instruction The instruction is as below: br label It corresponds to: pc = label; Label normally consists of one or several letters or digits (always try to use mnemotecnics) Labels are used to identify instructions

79 The instructions are not executed in the order as they appear in the program start: br next_instruction; ldiq $T0, 0x12; // some more instructions next_instruction: ldiq $T0, a br start ; jmp is the unconditional jump instruction It has the form: jmp ($reg); It is, used to jump to an address when the destination has to be computed at run time It is often used to implement switch statements Essentially it corresponds to: pc = intreg[ reg ]; bsr is the branch to subroutine instruction It has the form: bsr destination; It is used to branch to code for a function (subroutine, function, procedure and method are words that mean essentially the same thing) It stores in a register, called the return address register $RA, the address corresponding to the next instruction, just after the bsr instruction so that it is possible to return to the right instruction when the subroutine call is over (which is when all the operations included in the subroutine have been performed) It corresponds to: intreg[ ra ] = pc; pc = destination; There is a matching instruction to return from a function, the ret instruction It has no operands: ret; It restores the pc to its previous value It corresponds to pc = intreg[ ra ]; We will see details about function invocations later

80 Conditional branch With conditional branch instructions, the machine only jumps to execute the labeled instruction if the condition specified by the instructions is satisfied Conditional branch instructions have two operands The first operand is a register The second operand is a label If the value in the register satisfies the condition specified by the instruction (eg equal to zero, etc), then the machine jumps to execute the instruction whose label is the second operand Otherwise, the machine executes the instruction, which follows the branch instruction The format of the conditional branch instruction is as below: bxy s_reg, label beq $T0, label If $T0 == 0 then jump to label instruction bne $T0, label If $T0!= 0 then jump to label instruction blt $T0, label If $T0 < 0 then jump to label instruction ble $T0, label If $T0 <= 0 then jump to label instruction bgt $T0, label If $T0 > 0 then jump to label instruction bge $T0, label If $T0 >= 0 then jump to label instruction blbs $T0, label If the low bit is set (bit is 1), then jump to label instruction blbc $T0, label If the low bit is clear (bit is 0), then jump to label instruction

81 Relational Instructions A special class of integer operates instruction cmpx instructions are used to test the relation between two values The instructions have either two or three operands The operands can be either registers or a value but the first operand must be a register CmpX S_reg1, S_reg2, D_reg CmpX S_reg1/D_reg, S_reg2 If the test result is true, then 1 is stored in the operand, which holds the result; otherwise, 0 is stored in the operand cmpeq compares the equality of two values cmpeq $T0, $T1, $T3 (cmpeq s_reg1,s_reg2,d_reg) If $T0 == $T1 then $T3 = 1 else $T3 = 0 cmpeq $T0, $T1 (cmpeq d_reg/s_reg1,s_reg2) If $T0 == $T1 then $T0 = 1 else $T0 = 0 cmpeq $T0, 0x2, $T1 (cmpeq s_reg, val, d_reg) If $T0 == 0x2 then $T1 = 1 else $T1 = 0 cmpeq $T0, 0x2 (cmpeq s_reg/d_reg, val) If $T0 == 0x2 then $T0 = 1 else $T0 = 0 cmplt and cmple compare two signed quadwords cmplt $T0, $T1, $T3 (cmplt s_reg1, s_reg2, d_reg) If $T0 < $T1 then $T3 = 1 else $T3 = 0 cmplt $T0, $T1 (cmplt d_reg/s_reg1, s_reg2) If $T0 < $T1 then $T0 = 1 else $T0 = 0 cmplt $T0, 0x2, $T1 (cmplt s_reg, val, d_reg) If $T0 < 0x2 then $T1 = 1 else $T1 = 0 cmplt $T0, 0x2 (cmplt s_reg/d_reg, val)

82 If $T0 < 0x2 then $T0 = 1 else $T0 = 0 cmple $T0, $T1, $T3 (cmple s_reg1, s_reg2, d_reg) If $T0 <= $T1 then $T3 = 1 else $T3 = 0 cmple $T0, $T1 (cmple d_reg/s_reg1, s_reg2) If $T0 <= $T1 then $T0 = 1 else $T0 = 0 cmple $T0, 0x2, $T1 (cmple s_reg, val, d_reg) If $T0 <= 0x2 then $T1 = 1 else $T1 = 0 cmple $T0, 0x2 (cmple s_reg/d_reg, val) If $T0 <= 0x2 then $T0 = 1 else $T0 = 0 No >= or > since T0 >=T1 can be done as T1 <= T0 T0 > T1, it can be performed as T1 < T0 If you want to perform T0 > 0x02, you cannot do cmplt 0x02, $T0 It has to be: o ldiq $T1, 0x2; o cmplt $T1, $T0 ; cmpult and cmpule compare two unsigned quadwords The format of cmpult and cmpule are the same as cmplt and cmple They just treat the quadwords as unsigned values and compare them the same way other comparing expressions use

83 Example 2: What are the values stored in the relevant T registers when the program terminates data{ a: quad 0x123456789abcdef0; b: quad 0x9876543210fedcba; } code{ ldiq $T0, a; ldiq $T1, b; cmpeq $T0, $T1, $T2; ldq $T3, ($T0); ldq $T4, ($T1); cmplt $T3, $T4, $T5; cmpule $T3, $T4, $T6; } Results: T2=0 (labels a and b point toward different address) T5 = 0 (since quadword stored in T3 is positive and the one stored in T4 is negative) T6 = 1 (since this expression deals only with unsigned values and compare them regarding unsigned representation format) Note: Using 2 s representation, T3 holds the quadword 0x123456789abcdef0, which is a positive number and T4 holds the quadword 0x9876543210fedcba, which is a negative number equal to 0x6789abcdef012346 (2 s representation) Using unsigned representation, T3 and T4 holds positive values, lowest one being 0x00 and largest one 0xffff Therefore content of T4 is larger than content of T3