Operands and Instructions - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Operands and Instructions

Description:

BIG Endian. LITTLE Endian. MIPS Assembly Language. register to memory. sh $s0,4($s1) ... Put 'typical constants' in memory and load them when needed. ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 16
Provided by: egBuc
Category:

less

Transcript and Presenter's Notes

Title: Operands and Instructions


1
  • Operands and Instructions

2
MIPS Different Views of Memory
array of bytes
array of words
array of half-words
0
0
0
2
1
4
4
2
8
6
3
12
8
4
...
10
5
lw s1, 4(s2)
6
...
sw s1,12(s2)
lh s1,6(s2)
...
sh s1,2(s2)
lb s1,3(s2)
sb s1,5(s2)
Question Given an address, how do you know
whether it addresses a byte, a half-word, or a
word?
3
Endian Conventions
word address
BIG Endian
0x00000c
MSB
LSB
0x00000c
LSB
MSB
LITTLE Endian
byte address
0x00000c
0x00000d
0x00000e
0x00000f
Example Store 0x00010203 according to little
endian and to a big endian conventions,
BIG Endian
0x00
0x01
0x02
0x03
LITTLE Endian
0x03
0x02
0x01
0x00
0x00000c
0x00000d
0x00000e
0x00000f
4
MIPS Assembly Language
5
Compile this code
  • f (gh) (ij)

Scenario 1
Scenario 2
Assume that the variables f, g, h, i, and j are
in registers s0, s1, s2, s3, and s4,
respectively.
Assume that the variables f, g, h, i, and j are
in memory positions 0, 4, 8, 12, and 16,
respectively.
6
Compiling code with arrays
  • A1 h A3

Assume that variable h is in register s3, that
A is an array of word starting at a memory
position indicated by register s0.
7
Assembly Language vs. Machine Language
  • Assembly provides convenient symbolic
    representation it is easier to read/write
    programs using mnemonics than using numbers.
  • Machine language is the underlying reality in all
    its gory details.
  • Assembly can provide pseudo-instructions
  • Pseudos add a level of abstraction over the
    processors ISA called virtual machine.
  • Example move t0,t1 exists only in Assembly.
  • It would be implemented using add t0,t1,zero.
  • When considering performance, however, you may
    want to rely on real instructions only.

8
Machine Language
  • Registers are identified by numbers.
  • Instructions are associated with codes and
    represented in binary. MIPS instructions, like
    registers, are 32-bits long.
  • Example R-format MIPS instructions.

6 bits
6 bits
5 bits
5 bits
5 bits
5 bits
op Basic operation of the instructions
opcode. rs First register source operand. rt
Second register source operand. rd Destination
register operand. shamt Shift amount. funct
Selects a variant of the operation indicated in
op function code.
9
From Assembly to Machine Language
Assembly
add s0, s3, s7
Machine Language
op
rs
rt
rd
shamt
funct
Look up the codes in your sheet and fill in the
fields above in binary. Now, look at the machine
code you created wouldnt it be easier to work
with in hexadecimal?
10
I-Format MIPS Instructions
  • Small constants are used quite frequently (50 of
    operands).How do we work with them in Assembly?
    Are these good solutions?
  • Put typical constants in memory and load them
    when needed.
  • Create hard-wired registers (like zero) for
    constants like one.

I-format
6 bits
16 bits
5 bits
5 bits
Assembly
addi s0, s3, 40
Machine Language
op
rs
rt
constant or address
11
Logical Instructions
12
Example sll
  • sll s1, s0, 8

op
rs
rt
rd
shamt
funct
Question Can you explain why shifting a binary
number left by one position corresponds to
multiplying it by 2?
13
Making Decisions
  • These instructions follow the I-format and allow
    your assembly program to make branches based on
    the result of a computation.
  • Examples
  • beq register1, register2, L1
  • bne register1, register2, L1

14
J-Format MIPS Instructions
Similarly to instructions for making decisions,
these are allow the flow of your assembly
programs to be non-sequential, that is, they
allow you to make jumps.
J-format
6 bits
26 bits
  • Examples
  • j START
  • jal MY_FUNCTION

15
Compile This Code
Java or C code
MIPS assembly code
  • if (i j)
  • f gh
  • else
  • f g-h
Write a Comment
User Comments (0)
About PowerShow.com