SlideShare una empresa de Scribd logo
1 de 49
MIPS Assembly Language I
MIPS Instruction Set Architecture

• What is an instruction set architecture (ISA)?
• Interplay of C and MIPS ISA
• Components of MIPS ISA
  – Register operands
  – Memory operands
  – Arithmetic operations
  – Control flow operations
5 components of any Computer

Personal Computer



               Computer                                Keyboard,
             Processor
                                                       Mouse
                              Memory         Devices
                                                       Disk
               Control                       Input
                              (where                   (where
               (“brain”)                               programs,
                              programs,
                              data                     data
              Datapath        live when                live when
              (“brawn”)                      Output    not running)
                              running)
                                                        Display,
                                                        Printer
                           Stored-program concept
Computers (All Digital Systems)
        Are At Their Core Pretty Simple
• Computers only work with binary signals
    – Signal on a wire is either 0, or 1
         • Usually called a “bit”
    – More complex stuff (numbers, characters, strings, pictures)
         • Must be built from multiple bits
• Built out of simple logic gates that perform Boolean logic
    – AND, OR, NOT, …

• and memory cells that preserve bits over time
    – Flip-flops, registers, SRAM cells, DRAM cells, …

• To get hardware to do anything, need to break
  it down to bits
    – Strings of bits that tell the hardware what to do are called instructions
    – A sequence of instructions called machine language program (machine code)
Instruction Set Architecture (ISA)
                            Application (Firefox)
                                            Operating
                              Compiler       System
      Software                Assembler      (Linux)
                                                         Instruction Set
      Hardware             Processor Memory I/O system    Architecture

                               Datapath & Control



• The Instruction Set Architecture (ISA) defines what instructions do
• MIPS, Intel IA32 (x86), Sun SPARC, PowerPC, IBM 390, Intel IA64
    – These are all ISAs
Instruction Set Architecture (ISA)
                           Application (Firefox)
                                                Operating
                              Compiler           System
      Software                Assembler          (Linux)
                                                                       Instruction Set
      Hardware           Processor Memory I/O system                    Architecture

                                Datapath & Control


• Many different implementations can implement same ISA (family)
    – 8086, 386, 486, Pentium, Pentium II, Pentium4 implement IA32
    – Of course they continue to extend it, while maintaining binary compatibility
• ISAs last a long time
    – x86 has been in use since the 70s

    – IBM 390 started as IBM 360 in 60s
MIPS ISA
• MIPS – semiconductor company that built one
  of the first commercial RISC architectures
   – Founded by J. Hennessy
• We will study the MIPS architecture in some
  detail in this class
• Why MIPS instead of Intel 80x86?
   –   MIPS is simple, elegant and easy to understand
   –   x86 is ugly and complicated to explain
   –   x86 is dominant on desktop
   –   MIPS is prevalent in embedded applications as
       processor core of system on chip (SOC)
MIPS Processor History
       Model - Clock   Instruction                  Transistor
Year                                 Cache (I+D)
        Rate (MHz)         Set                        Count
                                      External:
1987     R2000-16        MIPS I       4K+4K to     115 thousand
                                      32K+32K
                                      External:
1990     R3000-33                     4K+4K to     120 thousand
                                      64K+64K
1991    R4000-100       MIPS III       8K+8K       1.35 million

1993    R4400-150                     16K+16K       2.3 million

        R4600-100                     16K+16K       1.9 million

1995    Vr4300-133                     16K+8K       1.7 million

1996    R5000-200        MIPS IV      32K + 32K     3.9 million

        R10000-200                    32K + 32K     6.8 million

1999    R12000-300                    32K + 32K     7.2 million

2002    R14000-600                    32K + 32K     7.2 million
C vs MIPS
                 Programmers Interface
                                     C                            MIPS I ISA
                                                      32   32b   integer, R0 = 0
                                                      32   32b   single FP
Registers
                                                      16   64b   double FP
                                                      PC   and   special registers
                     local variables
Memory                                                232 linear array of bytes
                     global variables
                     int, short, char, unsigned,      word(32b), byte(8b),
                     float, double,                   half-word(16b),
Data types
                     aggregate data types,            single FP(32b), double
                     pointers                         FP(64b)
Arithmetic operators +, -, *, %,++, <, etc.           add, sub, mult, slt, etc.

Memory access        a, *a, a[i], a[I][j]             lw, sw, lh, sh, lb, sb
                     If-else, while, do-while, for,   branches, jumps,
Control
                     switch, procedure call, return   jump and link
Why Have Registers?
• Memory-memory ISA
                                                                        Memory
    – All HLL variables declared in memory
    – Why not operate directly on memory operands?                     232 Bytes
    – E.g. Digital Equipment Corp (DEC) VAX ISA
• Benefits of registers
    – Smaller is faster (regs. 20X–100X faster than mem.)
                                                                       Load Store
    – Multiple concurrent accesses
    – Shorter names                                                       32
                                                                       Registers
• Load-Store ISA
                                                                        27 Bytes
    – Arithmetic operations only use register operands
    – Data is loaded into registers, operated on, and stored back to
      memory                                                           Arithmetic
    – All RISC instruction sets                                            unit
Using Registers
• Registers are a finite resource that needs to be
  managed
   – Programmer
   – Compiler: register allocation
• Goals
   – Keep data in registers as much as possible
   – Always use data still in registers if possible
• Issues
   – Finite number of registers available
      • Spill registers to memory when all registers in use
   – Arrays
      • Data is too large to store in registers
• What’s the impact of fewer or more registers?
Register Naming
• Registers are identified by a $<num>
• By convention, we also give them names
  – $zero contains the hardwired value 0
  – $v0, $v1 are for results and expression
    evaluation
  – $a0–$a3 are for arguments
  – $s0, $s1, … $s7 are for save values
  – $t0, $t1, … $t9 are for temporary values
• Compilers use these conventions to simplify
  linking
Assembly Instructions
• The basic type of instruction has four
  components:
     1.   Operation name
     2.   1st source operand
     3.   2nd source operand
     4.   Destination operand

     • add dst, src1, src2      # dst = src1 + src2

• dst, src1, and src2 are register names ($)
C Example
Simple C procedure: sum_pow2 = 2b+c

1: int sum_pow2(int b, int c)
2: {
3:       int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128};
4:       int a, ret;
5:       a = b + c;
6:
7:       if (a < 8)
8:             ret = pow2[a];
         else
9:             ret = 0;
10:
11:}     return(ret);
Arithmetic Operators
• Consider line 5, C operation for addition
  a = b + c;
• Assume the variables are in registers $s1-
  $s3 respectively
• The add operator using registers
     add $s1, $s2, $s3            # a = b + c

• Use the sub operator for a=b–c in MIPS
     sub $s1, $s2, $s3            # a = b - c

• But we know that a,b, and c really refer to
  memory locations
Complex Operations
• What about more complex statements?
     a = b + c + d - e;

• Break into multiple instructions
     add $t0, $s1, $s2         # $t0 = b + c
     add $t1, $t0, $s3         # $t1 = $t0 + d
     sub $s0, $t1, $s4         # a = $t1 - e

•
Signed & Unsigned Number
• If given b[n-1:0] in a register or in memory
• Unsigned value            n 1
                  value         bi 2i
                           i 0


• Signed value (2’s complement)
                                                     n 1
                                           n 1                    i
                   value         (bn 1 2         )         bi 2
                                                     i 0
Unsigned & Signed Numbers
 X     unsigned signed   • Example values
0000      0      0
0001      1      1         – 4 bits
0010      2      2         – Unsigned: [0, 24 – 1]
0011      3      3
0100      4      4         – Signed: [- 23, 23 -1]
0101      5      5       • Equivalence
0110      6      6
0111      7      7         – Same encodings for non-
1000      8      –8          negative values
1001      9      –7
1010     10      –6      • Uniqueness
1011     11      –5        – Every bit pattern represents
1100     12      –4
1101
                             unique integer value
         13      –3
1110     14      –2        – Not true with sign magnitude
1111     15      –1
Arithmetic Overflow
When the sum of two n-bit numbers can not be
 represented in n bits

        Unsigned                             Signed
                                     True Sum
       Wraps Around
                          0 111…1   2n–1
     – If true sum ≥ 2n
                                              PosOver
     – At most once                                     Modular Sum
                          0 100…0    2n–1                   011…1
True Sum
  2n+1
           Overflow
                          0 000…0    0                      000…0
 2n
                          1 100…0   –2n –1                  100…0
 0
            Modular Sum   1 000…0   –2n       NegOver
Constants
• Often want to be able to specify operand in the instruction: immediate or
  literal
• Use the addi instruction

        addi dst, src1, immediate

• The immediate is a 16 bit signed value between -215 and 215-1
• Sign-extended to 32 bits
• Consider the following C code
        a++;
• The addi operator
        addi $s0, $s0, 1                            # a = a + 1
MIPS Simple Arithmetic
Instruction Example               Meaning               Comments
add                   add $s1,$s2,s$3       $s1 = $s2 + $s3        3 operands; Overflow

subtract              sub $s1,$s2,s$3       $s1 = s$2 – $s3        3 operands; Overflow

add immediate         addi $s1,s$2,100      $s1 = s$2 + 100        + constant; Overflow

add unsigned          addu $s1,$s2,$s3      $s1 = $s2 + $s3        3 operands; No overflow

subtract unsign       subu $s1,$s2,$s3      $s1 = $s2 – $s3         3 operands; No overflow

add imm unsign        addiu $s1,$s2,100     $s1 = $s2 + 100        + constant; No overflow
Memory Data Transfer
• Data transfer instructions are used to move
  data to and from memory
• A load operation moves data from a memory
  location to a register and a store operation
  moves data from a register to a memory
  location
                    address (32)

                                     Memory
            CPU       data (32)      232 Bytes
                    load     store
Data Transfer Instructions: Loads

• Data transfer instructions have three parts
  – Operator name (transfer size)
  – Destination register
  – Base register address and constant offset

     lw dst, offset(base)


  – Offset value is a signed constant
Memory Access
• All memory access happens through loads and
  stores
• Aligned words, half-words, and bytes
• Floating Point loads and stores for accessing
  FP registers
Loading Data Example
• Consider the example
      a = b + *c;


• Use the lw instruction to load
      Assume a($s0), b($s1), c($s2)


      lw $t0, 0($s2)                  # $t0 = Memory[c]
      add $s0, $s1, $t0                    # a = b + *c
Accessing Arrays
• Arrays are really pointers to the base address in memory
   – Address of element A[0]
• Use offset value to indicate which index
• Remember that addresses are in bytes, so multiply by
  the size of the element
   – Consider the integer array where pow2 is the base address
   – With this compiler on this architecture, each int requires 4
     bytes
   – The data to be accessed is at index 5: pow2[5]
   – Then the address from memory is pow2 + 5 * 4
• Unlike C, assembly does not handle pointer arithmetic
  for you!
Array Memory Diagram
        1032

        1028   pow 2[7]
        1024   pow 2[6]
        1020   pow 2[5]
        1016   pow 2[4]
        1012   pow 2[3]
        1008   pow 2[2]
        1004   pow 2[1]
        1000
               pow 2[0]   4 bytes


 pow2
Array Example
• Consider the example
     a = b + pow2[7];

• Use the lw instruction offset, assume $s3 =
  1000

     lw $t0, 28($s3) # $t0 = Memory[pow2[7]]
     add $s0, $s1, $t0    # a = b + pow2[7]
Complex Array Example
• Consider line 7 from sum_pow2()
     ret = pow2[a];


• First find the correct offset, again assume $s3
  = 1000

     sll $t0, $s0, 2 # $t0 = 4 * a : shift
      left by 2
     add $t1, $s3, $t0    # $t1 = pow2 + 4*a
     lw $v0, 0($t1) # $v0 = Memory[pow2[a]]
Storing Data
• Storing data is just the reverse and the
  instruction is nearly identical

• Use the sw instruction to copy a word from
  the source register to an address in memory
     sw src, offset(base)



• Offset value is signed
Storing Data Example
• Consider the example
     *a = b + c;

• Use the sw instruction to store

     add $t0, $s1, $s2   # $t0 = b + c
     sw $t0, 0($s0) # Memory[s0] = b + c
Storing to an Array
• Consider the example
     a[3] = b + c;


• Use the sw instruction offset
     add $t0, $s1, $s2        # $t0 = b + c
     sw $t0, 12($s0)# Memory[a[3]] = b + c
Complex Array Storage
• Consider the example
     a[i] = b + c;

• Use the sw instruction offset
     add   $t0,   $s1, $s2   # $t0 = b + c
     sll   $t1,   $s3, 2# $t1 = 4 * i
     add   $t2,   $s0, $t1   # $t2 = a + 4*i
     sw    $t0,   0($t2)# Memory[a[i]] = b + c
A “short” Array Example
• ANSI C requires a short to be at least 16 bits and no longer than an
  int, but does not define the exact size
• For our purposes, treat a short as 2 bytes
• So, with a short array c[7] is at c + 7 * 2, shift left by 1
                   1016
                                c[ 7]
                   1014
                   1012         c[ 6]

                   1010         c[ 5]

                   1008         c[ 4]

                   1006         c[ 3]

                   1004         c[ 2]
                                c[ 1]
                   1002
                   1000         c[ 0]          2 bytes



                  c
MIPS Integer Load/Store
Instruction         Example              Meaning     Comments
store word          sw $1, 8($2) Mem[8+$2]=$1       Store word
store half          sh $1, 6($2)    Mem[6+$2]=$1    Stores only lower 16 bits
store byte          sb $1, 5($2)    Mem[5+$2]=$1    Stores only lowest byte
store float         sf $f1, 4($2)   Mem[4+$2]=$f1   Store FP word


load word           lw $1, 8($2)    $1=Mem[8+$2]    Load word
load halfword       lh $1, 6($2)    $1=Mem[6+$2]    Load half; sign extend
load half unsign    lhu $1, 6($2) $1=Mem[8+$2]      Load half; zero extend
load byte           lb $1, 5($2)    $1=Mem[5+$2]    Load byte; sign extend
load byte unsign    lbu $1, 5($2) $1=Mem[5+$2]      Load byte; zero extend
Alignment Restrictions
• In MIPS, data is required to fall on addresses that are multiples of the
  data size
                            0       1   2    3

                 Aligned



                     Not
                 Aligned


• Consider word (4 byte) memory access



        0          4            8           12       16

        0          4            8           12       16
Alignment Restrictions (cont)
•   C Example                       struct foo {

      What is the size of                       char sm;
       this structure?                          short med;
                                                char sm1;
                                                int lrg;
                                    }
•   Historically Byte offset         0    1     2    3 4       5 7   8         12
                                         sm x       med sm1      x       lrg

     –   Early machines (IBM 360 in 1964) required alignment
     –   Removed in 1970s to reduce impact on programmers
     –   Reintroduced by RISC to improve performance
•   Also introduces challenges with memory organization with virtual memory, etc.
Memory Mapped I/O
• Data transfer instructions can be used to move data to and from
  I/O device registers
• A load operation moves data from an I/O device register to a CPU
  register and a store operation moves data from a CPU register to a
  I/O device register
                                address (8)

                                 address [7]
                                                         Memory
                   CPU            data (8)              27 Bytes


                                         I/O register
                                Enable

                         I/O register at address 0x80 (128)
Changing Control Flow
• One of the distinguishing characteristics of computers
  is the ability to evaluate conditions and change control
  flow
• C
   – If-then-else
   – Loops
   – Case statements
• MIPS
   – Conditional branch instructions are known as branches
   – Unconditional changes in the control flow are called jumps
   – The target of the branch/jump is a label
Conditional: Equality
• The simplest conditional test is the beq instruction for equality
        beq reg1, reg2, label
• Consider the code
                 if (a == b) goto L1;
                 // Do something
        L1:      // Continue

• Use the beq instruction
                 beq $s0, $s1, L1
                 # Do something
        L1:      # Continue
Conditional: Not Equal
• The bne instruction for not equal
     bne reg1, reg2, label

• Consider the code
           if (a != b) goto L1;
           // Do something
     L1:   // Continue

• Use the bne instruction
           bne $s0, $s1, L1
           # Do something
     L1:   # Continue
Unconditional: Jumps
• The j instruction jumps to a label
     j label
If-then-else Example

                              (true)           (false)
• Consider the code                    i == j?
                              i == j            i != j
     if (i == j) f = g + h;
     else f = g – h;           f=g+h        f=g-h


                                         Exit
If-then-else Solution

• Create labels and use equality instruction

       beq $s3, $s4, True # Branch if i == j
       sub $s0, $s1, $s2    # f = g – h
       j Exit               # Go to Exit
       True:     add $s0, $s1, $s2# f = g + h
       Exit:
Other Comparisons
• Other conditional arithmetic operators are
  useful in evaluating conditional expressions
  using <, >, <=, >=
• Register is “set” to 1 when condition is met
• Consider the following C code
      if (f < g) goto Less;


• Solution
slt $t0, $s0, $s1      # $t0 = 1 if $s0 < $s1
bne $t0, $zero, Less   # Goto Less if $t0 != 0
MIPS Comparisons
Instruction Example          Meaning                               Comments
set less than                slt $1, $2, $3      $1 = ($2 < $3)    comp less than signed

set less than imm            slti $1, $2, 100    $1 = ($2 < 100)   comp w/const signed

set less than uns            sltu $1, $2, $3     $1 = ($2 < $3)    comp < unsigned

set l.t. imm. uns            sltiu $1, $2, 100   $1 = ($2 < 100)   comp < const unsigned

•    C

      if (a < 8)

•    Assembly




            slti $v0,$a0,8               # $v0 = a < 8
            beq $v0,$zero, Exceed        # goto Exceed if $v0 == 0
C Example
Simple C procedure: sum_pow2(b,c) = 2b+c
1:    int sum_pow2(int b, int c)
2:    {
3:
4:    int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128};
5:    int a, ret;
6:    a = b + c;
7:    if (a < 8)
            ret = pow2[a];
8:    else
9:
10:       ret = 0;
11:   return(ret);
      }
sum_pow2 Assembly
sum_pow2:                           # $a0 = b, $a1 = c
        addu    $a0,$a0,$a1         # a = b + c, $a0 = a
        slti    $v0,$a0,8           # $v0 = a < 8
        beq     $v0,$zero, Exceed   # goto Exceed if $v0 == 0
        addiu   $v1,$sp,8           # $v1 = pow2 address
        sll     $v0,$a0,2           # $v0 = a*4
        addu    $v0,$v0,$v1         # $v0 = pow2 + a*4
        lw      $v0,0($v0)          # $v0 = pow2[a]
        j       Return              # goto Return
Exceed: addu    $v0,$zero,$zero     # $v0 = 0
Return: jr      ra                  # return sum_pow2
Running An Application
                                   temp = v[k];
High Level Language                v[k] = v[k+1];
      Program
                                   v[k+1] = temp;
          Compiler                 lw   $15,   0($2)
Assembly Language                  lw   $16,   4($2)
     Program                       sw   $16,   0($2)
          Assembler                sw   $15,   4($2)
                                   0000 1001 1100 0110 1010 1111 0101 1000
 Machine Language                  1010 1111 0101 1000 0000 1001 1100 0110
     Program                       1100 0110 1010 1111 0101 1000 0000 1001
                                   0101 1000 0000 1001 1100 0110 1010 1111
          Machine Interpretation
   Control Signal                  High/Low on control lines
   Specification

Más contenido relacionado

La actualidad más candente

BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC  COMPUTER  ORGANIZATION  AND  DESIGNBASIC  COMPUTER  ORGANIZATION  AND  DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGNDr. Ajay Kumar Singh
 
Basic Processing Unit
Basic Processing UnitBasic Processing Unit
Basic Processing UnitSlideshare
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stackAsif Iqbal
 
11 instruction sets addressing modes
11  instruction sets addressing modes 11  instruction sets addressing modes
11 instruction sets addressing modes Sher Shah Merkhel
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
Chapter 4 The Processor
Chapter 4 The ProcessorChapter 4 The Processor
Chapter 4 The Processorguest4f73554
 
Multithreaded processors ppt
Multithreaded processors pptMultithreaded processors ppt
Multithreaded processors pptSiddhartha Anand
 
02 Computer Evolution And Performance
02  Computer  Evolution And  Performance02  Computer  Evolution And  Performance
02 Computer Evolution And PerformanceJeanie Delos Arcos
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Gaditek
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and ArchitectureVinit Raut
 
Chapter 2 - Computer Evolution and Performance
Chapter 2 - Computer Evolution and PerformanceChapter 2 - Computer Evolution and Performance
Chapter 2 - Computer Evolution and PerformanceCésar de Souza
 
Process' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxProcess' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxVarun Mahajan
 
top level view of computer function and interconnection
top level view of computer function and interconnectiontop level view of computer function and interconnection
top level view of computer function and interconnectionSajid Marwat
 
Chapter 03 arithmetic for computers
Chapter 03   arithmetic for computersChapter 03   arithmetic for computers
Chapter 03 arithmetic for computersBảo Hoang
 

La actualidad más candente (20)

BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC  COMPUTER  ORGANIZATION  AND  DESIGNBASIC  COMPUTER  ORGANIZATION  AND  DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGN
 
Basic Processing Unit
Basic Processing UnitBasic Processing Unit
Basic Processing Unit
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
11 instruction sets addressing modes
11  instruction sets addressing modes 11  instruction sets addressing modes
11 instruction sets addressing modes
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Chapter 4 The Processor
Chapter 4 The ProcessorChapter 4 The Processor
Chapter 4 The Processor
 
Mips1
Mips1Mips1
Mips1
 
Multithreaded processors ppt
Multithreaded processors pptMultithreaded processors ppt
Multithreaded processors ppt
 
Unit 1
Unit 1Unit 1
Unit 1
 
02 Computer Evolution And Performance
02  Computer  Evolution And  Performance02  Computer  Evolution And  Performance
02 Computer Evolution And Performance
 
ADDRESSING MODES
ADDRESSING MODESADDRESSING MODES
ADDRESSING MODES
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Intel Pentium Pro
Intel Pentium ProIntel Pentium Pro
Intel Pentium Pro
 
Input & Output
Input & OutputInput & Output
Input & Output
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
 
Chapter 2 - Computer Evolution and Performance
Chapter 2 - Computer Evolution and PerformanceChapter 2 - Computer Evolution and Performance
Chapter 2 - Computer Evolution and Performance
 
Process' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxProcess' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/Linux
 
top level view of computer function and interconnection
top level view of computer function and interconnectiontop level view of computer function and interconnection
top level view of computer function and interconnection
 
15 ia64
15 ia6415 ia64
15 ia64
 
Chapter 03 arithmetic for computers
Chapter 03   arithmetic for computersChapter 03   arithmetic for computers
Chapter 03 arithmetic for computers
 

Destacado

03 mips assembly language
03 mips assembly language03 mips assembly language
03 mips assembly languageMuberra Duman
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGFrankie Jones
 
MARS MIPS (Assembly language)
MARS MIPS (Assembly language)MARS MIPS (Assembly language)
MARS MIPS (Assembly language)Bat Suuri
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computerBATMUNHMUNHZAYA
 
Interfacing ics for microprocessor
Interfacing ics for microprocessorInterfacing ics for microprocessor
Interfacing ics for microprocessorTHANDAIAH PRABU
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Block diagram of computer 02
Block diagram of computer 02Block diagram of computer 02
Block diagram of computer 02ZTE Nepal
 
Conjunto de instruções mips - introdução
Conjunto de instruções mips - introduçãoConjunto de instruções mips - introdução
Conjunto de instruções mips - introduçãoElaine Cecília Gatto
 
Computer organiztion5
Computer organiztion5Computer organiztion5
Computer organiztion5Umang Gupta
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly languageAhmed M. Abed
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Designmekind
 
Arquitetura de Computadores: Assembly
Arquitetura de Computadores: AssemblyArquitetura de Computadores: Assembly
Arquitetura de Computadores: AssemblyElaine Cecília Gatto
 

Destacado (20)

03 mips assembly language
03 mips assembly language03 mips assembly language
03 mips assembly language
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
 
SQL
SQLSQL
SQL
 
MARS MIPS (Assembly language)
MARS MIPS (Assembly language)MARS MIPS (Assembly language)
MARS MIPS (Assembly language)
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computer
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Interfacing ics for microprocessor
Interfacing ics for microprocessorInterfacing ics for microprocessor
Interfacing ics for microprocessor
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Block diagram of computer 02
Block diagram of computer 02Block diagram of computer 02
Block diagram of computer 02
 
Conjunto de instruções mips - introdução
Conjunto de instruções mips - introduçãoConjunto de instruções mips - introdução
Conjunto de instruções mips - introdução
 
8086 microprocessor lab manual
8086 microprocessor lab manual8086 microprocessor lab manual
8086 microprocessor lab manual
 
Computer organiztion5
Computer organiztion5Computer organiztion5
Computer organiztion5
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Design
 
MIPS 32 BITS
MIPS 32 BITSMIPS 32 BITS
MIPS 32 BITS
 
Arquitetura de Computadores: Assembly
Arquitetura de Computadores: AssemblyArquitetura de Computadores: Assembly
Arquitetura de Computadores: Assembly
 

Similar a MIPS Assembly Language I

RISC processors: MIPS, ARM and SPARC
RISC processors: MIPS, ARM and SPARCRISC processors: MIPS, ARM and SPARC
RISC processors: MIPS, ARM and SPARCJaydeepDesai10
 
11-risc-cisc-and-isa-w.pptx
11-risc-cisc-and-isa-w.pptx11-risc-cisc-and-isa-w.pptx
11-risc-cisc-and-isa-w.pptxSuma Prakash
 
Embedded System basic and classifications
Embedded System basic and classificationsEmbedded System basic and classifications
Embedded System basic and classificationsrajkciitr
 
isa architecture
isa architectureisa architecture
isa architectureAJAL A J
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorDarling Jemima
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptjeronimored
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesAhmedMahjoub15
 
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...DefconRussia
 
A New Golden Age for Computer Architecture
A New Golden Age for Computer ArchitectureA New Golden Age for Computer Architecture
A New Golden Age for Computer ArchitectureYanbin Kong
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Futurekarl.barnes
 
MCI-Unit_1.PPTX electronics communication Engineering
MCI-Unit_1.PPTX electronics communication EngineeringMCI-Unit_1.PPTX electronics communication Engineering
MCI-Unit_1.PPTX electronics communication EngineeringKongaMadhukar
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scopeArshit Rai
 

Similar a MIPS Assembly Language I (20)

Processors selection
Processors selectionProcessors selection
Processors selection
 
RISC processors: MIPS, ARM and SPARC
RISC processors: MIPS, ARM and SPARCRISC processors: MIPS, ARM and SPARC
RISC processors: MIPS, ARM and SPARC
 
11-risc-cisc-and-isa-w.pptx
11-risc-cisc-and-isa-w.pptx11-risc-cisc-and-isa-w.pptx
11-risc-cisc-and-isa-w.pptx
 
Embedded System basic and classifications
Embedded System basic and classificationsEmbedded System basic and classifications
Embedded System basic and classifications
 
Current Trends in HPC
Current Trends in HPCCurrent Trends in HPC
Current Trends in HPC
 
isa architecture
isa architectureisa architecture
isa architecture
 
Dsp ajal
Dsp  ajalDsp  ajal
Dsp ajal
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM Processor
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.ppt
 
Risc processors
Risc processorsRisc processors
Risc processors
 
Processor types
Processor typesProcessor types
Processor types
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphes
 
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
 
A New Golden Age for Computer Architecture
A New Golden Age for Computer ArchitectureA New Golden Age for Computer Architecture
A New Golden Age for Computer Architecture
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Future
 
Arm Lecture
Arm LectureArm Lecture
Arm Lecture
 
MCI-Unit_1.PPTX electronics communication Engineering
MCI-Unit_1.PPTX electronics communication EngineeringMCI-Unit_1.PPTX electronics communication Engineering
MCI-Unit_1.PPTX electronics communication Engineering
 
Arm
ArmArm
Arm
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scope
 
FPGA @ UPB-BGA
FPGA @ UPB-BGAFPGA @ UPB-BGA
FPGA @ UPB-BGA
 

Último

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Último (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

MIPS Assembly Language I

  • 2. MIPS Instruction Set Architecture • What is an instruction set architecture (ISA)? • Interplay of C and MIPS ISA • Components of MIPS ISA – Register operands – Memory operands – Arithmetic operations – Control flow operations
  • 3. 5 components of any Computer Personal Computer Computer Keyboard, Processor Mouse Memory Devices Disk Control Input (where (where (“brain”) programs, programs, data data Datapath live when live when (“brawn”) Output not running) running) Display, Printer Stored-program concept
  • 4. Computers (All Digital Systems) Are At Their Core Pretty Simple • Computers only work with binary signals – Signal on a wire is either 0, or 1 • Usually called a “bit” – More complex stuff (numbers, characters, strings, pictures) • Must be built from multiple bits • Built out of simple logic gates that perform Boolean logic – AND, OR, NOT, … • and memory cells that preserve bits over time – Flip-flops, registers, SRAM cells, DRAM cells, … • To get hardware to do anything, need to break it down to bits – Strings of bits that tell the hardware what to do are called instructions – A sequence of instructions called machine language program (machine code)
  • 5. Instruction Set Architecture (ISA) Application (Firefox) Operating Compiler System Software Assembler (Linux) Instruction Set Hardware Processor Memory I/O system Architecture Datapath & Control • The Instruction Set Architecture (ISA) defines what instructions do • MIPS, Intel IA32 (x86), Sun SPARC, PowerPC, IBM 390, Intel IA64 – These are all ISAs
  • 6. Instruction Set Architecture (ISA) Application (Firefox) Operating Compiler System Software Assembler (Linux) Instruction Set Hardware Processor Memory I/O system Architecture Datapath & Control • Many different implementations can implement same ISA (family) – 8086, 386, 486, Pentium, Pentium II, Pentium4 implement IA32 – Of course they continue to extend it, while maintaining binary compatibility • ISAs last a long time – x86 has been in use since the 70s – IBM 390 started as IBM 360 in 60s
  • 7. MIPS ISA • MIPS – semiconductor company that built one of the first commercial RISC architectures – Founded by J. Hennessy • We will study the MIPS architecture in some detail in this class • Why MIPS instead of Intel 80x86? – MIPS is simple, elegant and easy to understand – x86 is ugly and complicated to explain – x86 is dominant on desktop – MIPS is prevalent in embedded applications as processor core of system on chip (SOC)
  • 8. MIPS Processor History Model - Clock Instruction Transistor Year Cache (I+D) Rate (MHz) Set Count External: 1987 R2000-16 MIPS I 4K+4K to 115 thousand 32K+32K External: 1990 R3000-33 4K+4K to 120 thousand 64K+64K 1991 R4000-100 MIPS III 8K+8K 1.35 million 1993 R4400-150 16K+16K 2.3 million R4600-100 16K+16K 1.9 million 1995 Vr4300-133 16K+8K 1.7 million 1996 R5000-200 MIPS IV 32K + 32K 3.9 million R10000-200 32K + 32K 6.8 million 1999 R12000-300 32K + 32K 7.2 million 2002 R14000-600 32K + 32K 7.2 million
  • 9. C vs MIPS Programmers Interface C MIPS I ISA 32 32b integer, R0 = 0 32 32b single FP Registers 16 64b double FP PC and special registers local variables Memory 232 linear array of bytes global variables int, short, char, unsigned, word(32b), byte(8b), float, double, half-word(16b), Data types aggregate data types, single FP(32b), double pointers FP(64b) Arithmetic operators +, -, *, %,++, <, etc. add, sub, mult, slt, etc. Memory access a, *a, a[i], a[I][j] lw, sw, lh, sh, lb, sb If-else, while, do-while, for, branches, jumps, Control switch, procedure call, return jump and link
  • 10. Why Have Registers? • Memory-memory ISA Memory – All HLL variables declared in memory – Why not operate directly on memory operands? 232 Bytes – E.g. Digital Equipment Corp (DEC) VAX ISA • Benefits of registers – Smaller is faster (regs. 20X–100X faster than mem.) Load Store – Multiple concurrent accesses – Shorter names 32 Registers • Load-Store ISA 27 Bytes – Arithmetic operations only use register operands – Data is loaded into registers, operated on, and stored back to memory Arithmetic – All RISC instruction sets unit
  • 11. Using Registers • Registers are a finite resource that needs to be managed – Programmer – Compiler: register allocation • Goals – Keep data in registers as much as possible – Always use data still in registers if possible • Issues – Finite number of registers available • Spill registers to memory when all registers in use – Arrays • Data is too large to store in registers • What’s the impact of fewer or more registers?
  • 12. Register Naming • Registers are identified by a $<num> • By convention, we also give them names – $zero contains the hardwired value 0 – $v0, $v1 are for results and expression evaluation – $a0–$a3 are for arguments – $s0, $s1, … $s7 are for save values – $t0, $t1, … $t9 are for temporary values • Compilers use these conventions to simplify linking
  • 13. Assembly Instructions • The basic type of instruction has four components: 1. Operation name 2. 1st source operand 3. 2nd source operand 4. Destination operand • add dst, src1, src2 # dst = src1 + src2 • dst, src1, and src2 are register names ($)
  • 14. C Example Simple C procedure: sum_pow2 = 2b+c 1: int sum_pow2(int b, int c) 2: { 3: int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128}; 4: int a, ret; 5: a = b + c; 6: 7: if (a < 8) 8: ret = pow2[a]; else 9: ret = 0; 10: 11:} return(ret);
  • 15. Arithmetic Operators • Consider line 5, C operation for addition a = b + c; • Assume the variables are in registers $s1- $s3 respectively • The add operator using registers add $s1, $s2, $s3 # a = b + c • Use the sub operator for a=b–c in MIPS sub $s1, $s2, $s3 # a = b - c • But we know that a,b, and c really refer to memory locations
  • 16. Complex Operations • What about more complex statements? a = b + c + d - e; • Break into multiple instructions add $t0, $s1, $s2 # $t0 = b + c add $t1, $t0, $s3 # $t1 = $t0 + d sub $s0, $t1, $s4 # a = $t1 - e •
  • 17. Signed & Unsigned Number • If given b[n-1:0] in a register or in memory • Unsigned value n 1 value bi 2i i 0 • Signed value (2’s complement) n 1 n 1 i value (bn 1 2 ) bi 2 i 0
  • 18. Unsigned & Signed Numbers X unsigned signed • Example values 0000 0 0 0001 1 1 – 4 bits 0010 2 2 – Unsigned: [0, 24 – 1] 0011 3 3 0100 4 4 – Signed: [- 23, 23 -1] 0101 5 5 • Equivalence 0110 6 6 0111 7 7 – Same encodings for non- 1000 8 –8 negative values 1001 9 –7 1010 10 –6 • Uniqueness 1011 11 –5 – Every bit pattern represents 1100 12 –4 1101 unique integer value 13 –3 1110 14 –2 – Not true with sign magnitude 1111 15 –1
  • 19. Arithmetic Overflow When the sum of two n-bit numbers can not be represented in n bits Unsigned Signed True Sum Wraps Around 0 111…1 2n–1 – If true sum ≥ 2n PosOver – At most once Modular Sum 0 100…0 2n–1 011…1 True Sum 2n+1 Overflow 0 000…0 0 000…0 2n 1 100…0 –2n –1 100…0 0 Modular Sum 1 000…0 –2n NegOver
  • 20. Constants • Often want to be able to specify operand in the instruction: immediate or literal • Use the addi instruction addi dst, src1, immediate • The immediate is a 16 bit signed value between -215 and 215-1 • Sign-extended to 32 bits • Consider the following C code a++; • The addi operator addi $s0, $s0, 1 # a = a + 1
  • 21. MIPS Simple Arithmetic Instruction Example Meaning Comments add add $s1,$s2,s$3 $s1 = $s2 + $s3 3 operands; Overflow subtract sub $s1,$s2,s$3 $s1 = s$2 – $s3 3 operands; Overflow add immediate addi $s1,s$2,100 $s1 = s$2 + 100 + constant; Overflow add unsigned addu $s1,$s2,$s3 $s1 = $s2 + $s3 3 operands; No overflow subtract unsign subu $s1,$s2,$s3 $s1 = $s2 – $s3 3 operands; No overflow add imm unsign addiu $s1,$s2,100 $s1 = $s2 + 100 + constant; No overflow
  • 22. Memory Data Transfer • Data transfer instructions are used to move data to and from memory • A load operation moves data from a memory location to a register and a store operation moves data from a register to a memory location address (32) Memory CPU data (32) 232 Bytes load store
  • 23. Data Transfer Instructions: Loads • Data transfer instructions have three parts – Operator name (transfer size) – Destination register – Base register address and constant offset lw dst, offset(base) – Offset value is a signed constant
  • 24. Memory Access • All memory access happens through loads and stores • Aligned words, half-words, and bytes • Floating Point loads and stores for accessing FP registers
  • 25. Loading Data Example • Consider the example a = b + *c; • Use the lw instruction to load Assume a($s0), b($s1), c($s2) lw $t0, 0($s2) # $t0 = Memory[c] add $s0, $s1, $t0 # a = b + *c
  • 26. Accessing Arrays • Arrays are really pointers to the base address in memory – Address of element A[0] • Use offset value to indicate which index • Remember that addresses are in bytes, so multiply by the size of the element – Consider the integer array where pow2 is the base address – With this compiler on this architecture, each int requires 4 bytes – The data to be accessed is at index 5: pow2[5] – Then the address from memory is pow2 + 5 * 4 • Unlike C, assembly does not handle pointer arithmetic for you!
  • 27. Array Memory Diagram 1032 1028 pow 2[7] 1024 pow 2[6] 1020 pow 2[5] 1016 pow 2[4] 1012 pow 2[3] 1008 pow 2[2] 1004 pow 2[1] 1000 pow 2[0] 4 bytes pow2
  • 28. Array Example • Consider the example a = b + pow2[7]; • Use the lw instruction offset, assume $s3 = 1000 lw $t0, 28($s3) # $t0 = Memory[pow2[7]] add $s0, $s1, $t0 # a = b + pow2[7]
  • 29. Complex Array Example • Consider line 7 from sum_pow2() ret = pow2[a]; • First find the correct offset, again assume $s3 = 1000 sll $t0, $s0, 2 # $t0 = 4 * a : shift left by 2 add $t1, $s3, $t0 # $t1 = pow2 + 4*a lw $v0, 0($t1) # $v0 = Memory[pow2[a]]
  • 30. Storing Data • Storing data is just the reverse and the instruction is nearly identical • Use the sw instruction to copy a word from the source register to an address in memory sw src, offset(base) • Offset value is signed
  • 31. Storing Data Example • Consider the example *a = b + c; • Use the sw instruction to store add $t0, $s1, $s2 # $t0 = b + c sw $t0, 0($s0) # Memory[s0] = b + c
  • 32. Storing to an Array • Consider the example a[3] = b + c; • Use the sw instruction offset add $t0, $s1, $s2 # $t0 = b + c sw $t0, 12($s0)# Memory[a[3]] = b + c
  • 33. Complex Array Storage • Consider the example a[i] = b + c; • Use the sw instruction offset add $t0, $s1, $s2 # $t0 = b + c sll $t1, $s3, 2# $t1 = 4 * i add $t2, $s0, $t1 # $t2 = a + 4*i sw $t0, 0($t2)# Memory[a[i]] = b + c
  • 34. A “short” Array Example • ANSI C requires a short to be at least 16 bits and no longer than an int, but does not define the exact size • For our purposes, treat a short as 2 bytes • So, with a short array c[7] is at c + 7 * 2, shift left by 1 1016 c[ 7] 1014 1012 c[ 6] 1010 c[ 5] 1008 c[ 4] 1006 c[ 3] 1004 c[ 2] c[ 1] 1002 1000 c[ 0] 2 bytes c
  • 35. MIPS Integer Load/Store Instruction Example Meaning Comments store word sw $1, 8($2) Mem[8+$2]=$1 Store word store half sh $1, 6($2) Mem[6+$2]=$1 Stores only lower 16 bits store byte sb $1, 5($2) Mem[5+$2]=$1 Stores only lowest byte store float sf $f1, 4($2) Mem[4+$2]=$f1 Store FP word load word lw $1, 8($2) $1=Mem[8+$2] Load word load halfword lh $1, 6($2) $1=Mem[6+$2] Load half; sign extend load half unsign lhu $1, 6($2) $1=Mem[8+$2] Load half; zero extend load byte lb $1, 5($2) $1=Mem[5+$2] Load byte; sign extend load byte unsign lbu $1, 5($2) $1=Mem[5+$2] Load byte; zero extend
  • 36. Alignment Restrictions • In MIPS, data is required to fall on addresses that are multiples of the data size 0 1 2 3 Aligned Not Aligned • Consider word (4 byte) memory access 0 4 8 12 16 0 4 8 12 16
  • 37. Alignment Restrictions (cont) • C Example struct foo { What is the size of char sm; this structure? short med; char sm1; int lrg; } • Historically Byte offset 0 1 2 3 4 5 7 8 12 sm x med sm1 x lrg – Early machines (IBM 360 in 1964) required alignment – Removed in 1970s to reduce impact on programmers – Reintroduced by RISC to improve performance • Also introduces challenges with memory organization with virtual memory, etc.
  • 38. Memory Mapped I/O • Data transfer instructions can be used to move data to and from I/O device registers • A load operation moves data from an I/O device register to a CPU register and a store operation moves data from a CPU register to a I/O device register address (8) address [7] Memory CPU data (8) 27 Bytes I/O register Enable I/O register at address 0x80 (128)
  • 39. Changing Control Flow • One of the distinguishing characteristics of computers is the ability to evaluate conditions and change control flow • C – If-then-else – Loops – Case statements • MIPS – Conditional branch instructions are known as branches – Unconditional changes in the control flow are called jumps – The target of the branch/jump is a label
  • 40. Conditional: Equality • The simplest conditional test is the beq instruction for equality beq reg1, reg2, label • Consider the code if (a == b) goto L1; // Do something L1: // Continue • Use the beq instruction beq $s0, $s1, L1 # Do something L1: # Continue
  • 41. Conditional: Not Equal • The bne instruction for not equal bne reg1, reg2, label • Consider the code if (a != b) goto L1; // Do something L1: // Continue • Use the bne instruction bne $s0, $s1, L1 # Do something L1: # Continue
  • 42. Unconditional: Jumps • The j instruction jumps to a label j label
  • 43. If-then-else Example (true) (false) • Consider the code i == j? i == j i != j if (i == j) f = g + h; else f = g – h; f=g+h f=g-h Exit
  • 44. If-then-else Solution • Create labels and use equality instruction beq $s3, $s4, True # Branch if i == j sub $s0, $s1, $s2 # f = g – h j Exit # Go to Exit True: add $s0, $s1, $s2# f = g + h Exit:
  • 45. Other Comparisons • Other conditional arithmetic operators are useful in evaluating conditional expressions using <, >, <=, >= • Register is “set” to 1 when condition is met • Consider the following C code if (f < g) goto Less; • Solution slt $t0, $s0, $s1 # $t0 = 1 if $s0 < $s1 bne $t0, $zero, Less # Goto Less if $t0 != 0
  • 46. MIPS Comparisons Instruction Example Meaning Comments set less than slt $1, $2, $3 $1 = ($2 < $3) comp less than signed set less than imm slti $1, $2, 100 $1 = ($2 < 100) comp w/const signed set less than uns sltu $1, $2, $3 $1 = ($2 < $3) comp < unsigned set l.t. imm. uns sltiu $1, $2, 100 $1 = ($2 < 100) comp < const unsigned • C if (a < 8) • Assembly slti $v0,$a0,8 # $v0 = a < 8 beq $v0,$zero, Exceed # goto Exceed if $v0 == 0
  • 47. C Example Simple C procedure: sum_pow2(b,c) = 2b+c 1: int sum_pow2(int b, int c) 2: { 3: 4: int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128}; 5: int a, ret; 6: a = b + c; 7: if (a < 8) ret = pow2[a]; 8: else 9: 10: ret = 0; 11: return(ret); }
  • 48. sum_pow2 Assembly sum_pow2: # $a0 = b, $a1 = c addu $a0,$a0,$a1 # a = b + c, $a0 = a slti $v0,$a0,8 # $v0 = a < 8 beq $v0,$zero, Exceed # goto Exceed if $v0 == 0 addiu $v1,$sp,8 # $v1 = pow2 address sll $v0,$a0,2 # $v0 = a*4 addu $v0,$v0,$v1 # $v0 = pow2 + a*4 lw $v0,0($v0) # $v0 = pow2[a] j Return # goto Return Exceed: addu $v0,$zero,$zero # $v0 = 0 Return: jr ra # return sum_pow2
  • 49. Running An Application temp = v[k]; High Level Language v[k] = v[k+1]; Program v[k+1] = temp; Compiler lw $15, 0($2) Assembly Language lw $16, 4($2) Program sw $16, 0($2) Assembler sw $15, 4($2) 0000 1001 1100 0110 1010 1111 0101 1000 Machine Language 1010 1111 0101 1000 0000 1001 1100 0110 Program 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Machine Interpretation Control Signal High/Low on control lines Specification