Thread: assembly

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    30

    assembly

    I have a C assignment where, to summarise, the inputs are assembly instructions(mips) in the form of a hexadecimal number and the program must:

    1. determine if the instruction is a "load" or "store" instruction.
    2. the address of the first byte in memory, as a hexadecimal number.

    my problem is not so much of writing a C code to do this, but i can't even manually figure out how to determine these things from a single mips instruction. i know this is a C forum, but i'm just hoping someone may have previous experience in assembly programming and point me to the right direction.

    edited
    Last edited by nasser; 08-29-2011 at 04:43 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    mips instruction set encoding - Google Search

    > 1. determine if the instruction is a "load" or "store" instruction.
    For the sake of argument, lets say bit 31 determines this, then
    Code:
    if ( (opcode & 0x80000000) == 0 ) {
      // load
    } else {
      // store
    }
    and so on.

    It should be just a bunch of &, |, >> and << to bit-fiddle the various fields of an opcode.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    30
    Determining the instruction type is the easy part, as you just look at the first 6 bits(opcode). I need help with parts 2 and 3.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you know how to extract 6 bits for the opcode, then you also know how to extract x and y bits for the other two things as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    30
    ok thanks
    Last edited by nasser; 08-29-2011 at 04:37 AM.

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Look at the binary representation of the opcodes
    Code:
    100000 : load 1 byte, sign extended
    100100 : load 1 byte, zero extended
    101000 : store 1 byte
    100001 : load 2 bytes, sign extended
    100101 : load 2 bytes, zero extended
    101001 : store 2 bytes
    100011 : load 4 bytes
    101011 : store 4 bytes
    Notice a pattern here regarding the data sizes?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert assembly>machine code, machine code>assembly
    By wenxinleong in forum C Programming
    Replies: 12
    Last Post: 06-23-2011, 10:42 PM
  2. Assembly
    By samGwilliam in forum C++ Programming
    Replies: 20
    Last Post: 03-31-2005, 04:30 AM
  3. Assembly
    By Ben_Robotics in forum Tech Board
    Replies: 29
    Last Post: 06-29-2003, 09:21 AM
  4. assembly
    By krappykoder in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-25-2002, 04:57 PM
  5. Help in assembly please
    By LePlusMieux in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2002, 05:07 PM