Speaking the Computers Language - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Speaking the Computers Language

Description:

Promoter of concepts which have led to the development of what has become known ... is executed by sequentially fetching instructions from memory and carrying ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 23
Provided by: egBuc
Category:

less

Transcript and Presenter's Notes

Title: Speaking the Computers Language


1
  • Speaking the Computers Language

2
A Little Bit of History
  • John Louis von Neumann
  • Born 28 December 1903, Budapest, Hungary.
  • Died 8 February 1957, Washington DC.
  • Promoter of concepts which have led to the
    development of what has become known as the von
    Neumann Architecture.

3
The von Neumann Architecture
Define the computer as a collection of four main
sub-systems
bus
Memory
Processor (CPU)
Input-Output
Control Unit
ALU
program and data
GEEK
A program is consists of a stream of instructions
which are stored in memory. The program is
executed by sequentially fetching instructions
from memory and carrying them out according to
specification.
4
Microprocessor Market in 2002
5
Instructions
  • They represent the language of the machine.
  • Well be working with the MIPS instruction set
    architecture
  • Similar to other architectures developed since
    the 1980's.
  • Almost 100 million MIPS processors manufactured
    in 2002.
  • Used by NEC, Nintendo, Cisco, Silicon Graphics,
    Sony,

6
RISC and CISC
  • RISC MIPS, ARM, SPARC
  • Fixed instruction lengths, load-store instruction
    sets, limited addressing modes, and limited
    operations.
  • ARM Instruction Set
  • SPARC Instruction Set
  • CISC Intel, AMD
  • Variable instruction lengths, several addressing
    modes, plentiful and powerful operations.
  • Intel 64 and IA-32 Instruction Set
  • Read CD2.19.pdf for more details.

7
MIPS Arithmetic
  • All instructions have 3 operands.
  • Operand order is fixed (destination
    first). Example C code a b c MIPS
    code add a, b, c (well talk about
    registers in a bit)The natural number of
    operands for an operation like addition is
    threerequiring every instruction to have exactly
    three operands, no more and no less, conforms to
    the philosophy of keeping the hardware simple.

8
MIPS Arithmetic
  • Design Principle 1 Simplicity favors
    regularity.
  • Operands must be registers, only 32 registers are
    provided.
  • Each register contains 32 bits (1 word).
  • Of course this complicates some things... C
    code a b c d MIPS code add a, b,
    c add a, a, d
  • Design Principle 2 Smaller is faster. (Why?)

9
Registers
  • A register is a multiple-bit storage area that
    is, memory for data or instructions. It can be
    written into and read from.
  • It is the fastest kind of memory the computer
    system can have.
  • Registers are used to store values for
    processing.
  • The compiler associates variables with
    registers.
  • A microprocessor has several registers. Each one
    is uniquely identified.

write (input)
read (output)
10
MIPS Architecture 32 Registers
These are only use conventions that the
programmer should observe.
11
MIPS Assembly Language
12
Memory Organization
  • Viewed as a large, one-dimensional array.
  • A memory address is an index value into the
    array.
  • MIPS memory is byte addressable, meaning that the
    index of the memory array points to one specific
    byte of memory.

0
8 bits of data
1
8 bits of data
2
8 bits of data
M3
3
8 bits of data
4
8 bits of data
5
8 bits of data
6
8 bits of data
...
In Java, this would be byte M new
bytesize
13
Memory Organization
  • It may be convenient to be able to address every
    byte individually, but many times we need to use
    larger words.
  • For MIPS, a word is 32 bits long, that is, 4
    consecutive bytes aligned at an index multiple of
    4. (MIPS registers hold 32 bits words.)
  • The memory size is 232 bytes with byte addresses
    from 0 to 232-1.
  • Alternatively 230 words with byte addresses 0,
    4, 8, ... 232-4.

32 bits
0
4
8
12
...
Question What are the least 2 significant bits
of a word address?
14
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?
15
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
16
MIPS Assembly Language
17
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.
18
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.
19
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.

20
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.
21
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?
22
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
Write a Comment
User Comments (0)
About PowerShow.com