Loading a Single Byte There are two instructions that load a byte from a memory address. The instructions differ in how the 8-bit byte is put into the.

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

Microprocessors General Features To be Examined For Each Chip Jan 24 th, 2002.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Introduction to Computing Systems (3rd Exam). 1.[5] Suppose R1 contains an integer x and R2 contains another integer y. Please write an instruction which.
EET 2261 Unit 2 HCS12 Architecture
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
MIPS coding. SPIM Some links can be found such as:
IT253: Computer Organization
Eng.Samra Essalaimeh Philadelphia University 2013/ nd Semester PIC Microcontrollers.
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
Working With Main Memory. Why Main Memory Register space limited Used for communication.
CSCI 136 Lab 1: 135 Review.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Chapter 2 CSF 2009 The MIPS Assembly Language: Introduction to Binary System.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i == j ) h = i + j;
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Memory Access Instructions Load and Store Addressing Modes Memory Addressing. Base addressing mode. Load byte and store byte: lb, lbu, sb Address alignment.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Topic: Binary Encoding – Part 2
CS2100 Computer Organisation
MIPS Arithmetic is 32 bits
Memory Access Instructions
Integer Multiplication and Division
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Microprocessor Systems Design I
Morgan Kaufmann Publishers
Microprocessor Systems Design I
MIPS Coding Continued.
Computer Organization and Design Instruction Sets - 2
Introduction to 8085 Instructions
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Conditional Control Structure
The University of Adelaide, School of Computer Science
Computer Organization and Design Instruction Sets
Lecture 4: MIPS Instruction Set
CSCI206 - Computer Organization & Programming
MPIS Instructions Functionalities of instructions Instruction format
MISP Assembly.
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Computer Architecture & Operations I
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
MIPS Assembly.
Computer Instructions
Computer Architecture
3.
Instruction encoding The ISA defines Format = Encoding
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Instruction encoding The ISA defines Format = Encoding
Number Representation & Operators
MIPS Assembly.
Instruction encoding The ISA defines Format = Encoding
MIPS Coding Continued.
The .ASCII and .END Assembler Input ;Stan Warford ;January 13, 2005
Generalities for Assembly Language
COMS 361 Computer Organization
MIPS Arithmetic and Logic Instructions
Conditional Control Structure
CS 111 – Sept. 16 Machine language examples Instruction execution
Presentation transcript:

Loading a Single Byte There are two instructions that load a byte from a memory address. The instructions differ in how the 8-bit byte is put into the 32-bit register. lb – load two’s complement byte lbu – load unsigned byte

lb Why is done the sign extension? Use this instruction when the byte is regarded as an 8-bit two’s complement integer in the range -128...+127 and you want a 32-bit version of it. Of course, the value of the integer does not change.

lbu Why is done the zero extension? The lbu instruction fills bits 8-31 of the register with zeros. Use this instruction when the byte is regarded as an ascii character or 8-bit unsigned integer.

lb, lbu examples 1. 0x77777777F 2. 0x7F0000000 3. 0xFFFFFFF7F What will be in register $8 after loading the byte 0x7F By lb ? What will be in register $8 after loading the byte 0x7F By lbu ? What will be in register $8 after loading the byte 0x8F By lb ? What will be in register $8 after loading the byte 0x8F By lbu ? 1. 0x77777777F 2. 0x7F0000000 3. 0xFFFFFFF7F 4. 0x00000007F 5. 0x0000000FF 1. 0x88888888F 2. 0x8F0000000 3. 0xFFFFFFF8F 4. 0x00000008F 5. 0x0000000FF

lb example Which type of instruction is this ?

lb examples (decimal vs hex) The assembler translates below assembly instruction pairs into exactly the same machine instructions. The second instruction in pairs uses signed decimal notation to specify numbers. That is much easier to use by human. lb $8, 0x60($10) lb $8, 96($10) lb $8, 0xFFF8($10) lb $8, -8($10)

Load delay slot There is a “one instruction delay” before the data from memory is available after load instructions. Reaching outside of the processor chip into main memory takes time. But the processor does not wait and executes one more instruction while the load is going on. This is the load delay slot. lb $11, 3($8) # after lb byte comes to Reg. # after one instruction . . . # The data is not yet available # This is “delay slot” or $13,$0,$11 # in Reg. $11 the byte is now # available

Filling Load delay slot Sometimes the instruction after the lb is a no-operation instruction. lb $11, 3($8) # after lb byte comes to Reg. # after one instruction sll $0,$0,0 # The data is not yet available # This is “delay slot” or $13,$0,$11 # in Register $11 the byte is # now available

Filling Load delay slot Sometimes the instruction after the lb is a useful instruction. Sometimes it’s a dangerous one lb $11, 3($8) # after lb byte comes # after one instruction ori $11, $0, 1 # wrong usage of the # register in delay slot or $13,$0,$11 # What is the problem here ? $11 is damaged by the byte came from the memory Always try to use simple NOP instead of complex useful instruction in delay slots.

Filling Load delay slot Sometimes the instruction after the lb is a useful instruction. Sometimes it’s a dangerous one lb $11, 3($8) # after lb byte comes # after one instruction or $12,$0,$11 # wrong usage of the # register in delay slot or $13,$0,$12 # What is the problem here ? $11 doesn’t contain yet the byte came from the memory

Storing a Single Byte

lb, lbu, sb examples ori $9,$0, 0x1234 # Prepare data sll $9,$9,16 ori $9,$9, 0xabcd ori $8,$0, 0x1000 # Prepare the address sll $8,$8,16 # in base register sb $9,0($8) # Save 0xcd at 0x10000000 srl $9,$9,8 sb $9,1($8) # Save 0xab at 0x10000001 sb $9,2($8) # Save 0x34 at 0x10000002 sb $9,3($8) # Save 0x12 at 0x10000003 $9 1 2 3 4 a b c d $8 1 0 0 0 0x10000000 c d a b 3 4 1 2

Example continues. Delay Slots ? Where are NOPs in delay slots ? Does this work properly without NOPs ? lb $11, 3($8) # Positive values lb $12, 2($8) lb $16, 1($8) # Negative Values lb $17, 0($8) lbu $18, 1($8) # Unsigned load lbu $19, 0($8) What is the difference between upper and lower pairs of instructions’ results ? 0x10000000 c d a b 3 4 1 2