Write C code to encode the MIPS-like instructions below to 32 bit machine code stored in an integer.

Programming: Instruction encoding:

Write C code to encode the MIPS-like (these are not strictly MIPS instructions by format)

instructions below to 32 bit machine code (binary) stored in an integer.

Hint: It is suggested that you investigate the use of bitwise operations. Also use the MIPS

 

instruction set pages at the end of the text to see bit layouts and instructions

Suggested approach: write a C function with this signature:

unsigned int instrToInt(char* inst, char* args)

which takes the instruction string (e.g. ‘add’) for argument 1, and the rest of the instruction line (e.g. ‘

$0,$1,$2’) as argument 2, then encodes the instruction as the 32 bit integer (see the examples below for

the syntax of the instruction line as it would appear in a MIPS-like input assembly file)

Instruction Meaning Example
add Add the contents of the rs and rt registers, and store the result in the rd register. opcode: 0, funct: 32 add $0,$1,$2
sub Subtract the contents of the rt register from the rs register, and store the result in the rd register. opcode: 0, funct: 34 sub $0,$1,$2
lw Add the immediate field to the contents of the rs register.The result is used as an address in data memory whose contents are written to the rt register. opcode: 35 lw $0,4($1)
sw The contents of the rt register are stored in data memory at the address computed by adding the contents of the rs register to the immediate field. opcode: 43 sw $0,4($1)
beq If the contents of the rs and rt registers are equal, then the

next instruction to be executed is indicated by the immediate field. Otherwise, continue executing instructions

beq $0,$1,4

 

sequentially. opcode: 4
mov A pseudoinstruction to mov the contents of rd to rs You may want to review the MIPS ISA in the text and see how you might implement this with existing instructions. mov $1, $2
and Set register rd with the value of the logical and of rs and rt and $3,$1,$2
not A pseudoinstruction to negate the contents of rd. The contents of rd should have all bits flipped not $1

 

 

Are you looking for a similar paper or any other quality academic essay? Then look no further. Our research paper writing service is what you require. Our team of experienced writers is on standby to deliver to you an original paper as per your specified instructions with zero plagiarism guaranteed. This is the perfect way you can prepare your own unique academic paper and score the grades you deserve.

Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.

[order_calculator]