CISC 260 Machine Organization and Assembly Language (Spring, 2018) Assignment #
ID: 3724233 • Letter: C
Question
CISC 260 Machine Organization and Assembly Language (Spring, 2018) Assignment # 3 (Due: March 13. 2018 The following instruction set is supported by a simple processor, which is similar to what we discussed in the class, with a few new instructions added. The format of most instructions is defined as follows. 9 8:6 5:32:0 ode wsrc1src2 dst field unused where the fields are defined as follows. opcode operation to be performed by the processor write back ALU output to register file (1 = yes, 0 = no) address of the first ALU operand in the register file address of the second ALU operand in the register file address in the register file where the output is writtein SIc SIc dst: For opcodes BEQ, BLEZ and JUMP, the 6 least significant bits (5:0) give an address in the instruction memory, which is byte-addressed. The opcode HALT has all operand bits (9:0) being 0. When an instruction has only two operands, the field for the unused operand is filled with 0-bits. For example, bits (5:3) for SLL are all zero because src2 is not used. The opcode and meaning of these instructions are listed in the following table encoding ation ADD SUB SLL SRL INV XOR OR AND INCR BRZ BLEZ 0x0 0x1 src 11-RIsrc2]-> Rldst src1] Rldst Src1 If RIsrc 1] = 0, branch to BAddr If R[srcl] 0, branch to BAddi JUMP HALT 0xE 0xF Jump to JAddr Stop execution In this part you are asked to recognize what a given segment of machine code does, by translating it into assembly code, and annotating it with expressions in a high level language like C. This process, 1.Explanation / Answer
1) Convert the given machine instruction from hex to binary.
2) Break it down into unused, opcode, w, src1, src2 and dst as specified in the table.
3) Substitute the codes for opcode, registers etc.
So, the first instruction 0x00 : 07 FF
is equivalent to 0000 0111 1111 1111 in binary. Note: 0x00 is the address, and will not be converted to binary. Only the machine code is converted to binary.
Now, moving from left to right and comparing with the given format, we get the following:
unused - 00
opcode - 0001 (for SUB)
write - 1
src1 - 111
src2 - 111
dst - 111
This becomes SUB R7, R7, R7. [Subtract R7 from R7 and store the difference in R7. This is usually used to clear the contents of a register.]
Similarly,
0x02: 06 08 becomes 00 0001 1 000 001 000 in binary (the contents of unused bits, opcode, write, src1, src2 and dst are separated by spaces.)
This translates to SUB R0, R1, R0, [Subtract R0 from R1, store in R0]
0x04: 28 08 becomes 00 1010 0 000 001000 in binary and translates to BLEZ R0, [0x08]. [Branch to memory address 0x08 if R0 is less than 0]
0x06: 38 02 becomes 00 1110 0 000 000010 in binary and translates to JUMP [0x02]. [Jump to memory address 0x02]
0x08: 02 47 becomes 00 0000 1 001 000 111 in binary and translates to ADD R1, R0, R7. [Add R1 to R0 and store in R7]
0x0A: 3C 00 becomes 00 1111 0 000 000 000 in binary and translates to HALT. [Stop executing the program]