-
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
-
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.
-
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.
-
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.
-
-
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?