IC_
IC_

Reputation: 1789

Can't understand how to decode M68K binary code

I want to make a disassembly of the m68k compiled binary myself and make an emulator. I've disassembled the binary file into a text file with a thirdparty tool m68k-linux-gnu-objdump -b binary -m m68k:68000 ... to have a better vision of what is going on in the binary

Here I have an instruction:

0604 0320       addib #32,%d4

From this table I see that addi function has the next binary scheme:

0000 011 0 <S> <M> <Xn>

and my instruction has representation of:

0000 011 0 00 000 100

Which means I have addi operation with size (8 bits), addressing mode "data register" and the register is encoded to be D4. Ok, addib with destination %d4 but what does this data column on the right side mean?

I see that the second word (2 bytes of data) in the disassembly is 0x0320 where the last 4 bits 0x20 actually my #32 literal in decimal. But what is this 0x03 in the middle? I've seen some other addi instructions in the disassembly and everywhere there was a 4 bits of something in the middle and the last 4 bits were my number in hex.

I'm probably not taking the last column of the table into account "data" but I failed to understand how to interpret it.

For the example above the table says, data type - "any type" + immediate mode but what is this "any type".
The size of addi instruction said to be any b/w/l in the second (green) column of the table. Are these three things like blue data's first sub-column(B,W,/), green size column (B/W/L), and pink sector of the scheme (00 - B, 01 - W, 10 - L) related? I'm completely confused
And the problem I don't understand the boundaries of the instructions. I've seen some instructions that were maximum 16 bits long (as shown in general schema for each operation) but there are "brief extension words" and "full extension words", what the book says about them I can't get completely. The only thing I probably understood is that the first 16 bits of the opcode is "Single Effective Address Operation Word" and that is.
This is my first approach in trying to understand such a low level of programming

Upvotes: 2

Views: 383

Answers (1)

tofro
tofro

Reputation: 6063

Do what the CPU does with the first byte of the immediate data word of a byte size instruction: Ignore it.

By encoding the two size bits as "00", you told the CPU that you want to add an 8-bit immediate value to the byte-size part of d4 - That means, the upper byte of the immediate data word is not used, but still the 68000 will only read instructions word-wise. Thus, the upper part of this data word is simply "don't care" - You can put anything in there without changing the effect of the instruction, because the CPU won't use it. (Thus, the actual value "3" you see there in your case is irrelevant and probably just some random value left over from the assembler)

If you encode the instruction as ".w" (that is, you want to do a 16-bit add), the upper byte of the data word becomes relevant. If you encode the very same instruction as .l (32-bit add), the assembler will add yet another word to the instruction and put the 32-bit immediate in those 2 words.

Upvotes: 3

Related Questions