简体   繁体   中英

Calculating Offset (Motorola 68k)

I'm given a question to find the offset as such:

Assume the instruction BNE HERE is in memory location $FF1234 and the label HERE represents the instruction at address $FF12C0. Compute the offset (displacement) for thisinstruction. Will the offset be stored as an 8-bit or 16-bit value by a typical assembler? Why?

I tried doing this to find the displacement:

FF1234 + offset = HERE = FF12C0
I tried solving for Offset which is:

 FF1234
-FF12C0

Which equals: 33432820?

Would this be the correct way of calulating the offset?

First: check out how the BNE instruction uses the offset and what PC value uses to calculate the next PC value if the jump is taken.

From http://68k.hax.com/Bcc

Description: If the specified condition is true, program execution continues at location (PC) + displacement. The PC contains the address of the instruction word of the Bcc instruction plus two. The displacement is a twos compliment integer that represents the relative distance in bytes from the current PC to the 16-bit displacement (the word immediately following the instruction) is used. If the 8-bit displacement field in the instruction word is all ones ($FF), the 32-bit displacement (long word immediately following the instruction) is used.

So, if the BNE instruction is located at $FF1234 , the value of PC used as base for the offset to be added to, is $FF1236 .

OTOH, the PC destination value is $FF12C0 , so $FF1236 + offset = $FF12C0 . offset will be a positive value. You should have no problem figuring it out.

Regarding this other question:

Will the offset be stored as an 8-bit or 16-bit value by a typical assembler? Why?

I don't know that it means "a typical assembler". I don't know if it refers to a typical assembler for any architecture, or a typical assembler for m68k architecture. I can only guess that this refers to a "typical assembler generating m68k object code", in which case, you should be able to answer the question just by looking at the size in bits needed by the offset value and the coding options for the BNE instruction, available in the mentioned webpage:

Instruction Format: \\i3-++-4Condition,88-bit Displacement,

016-bit Displacement if 8-bit Displacement = $00,

032-bit Displacement if 8-bit Displacement = $FF,

Instruction Fields (Register Shifts): Condition field -- The binary code for one of the conditions listed in the table. 8-bit Displacement field -- Twos complement integer specifying the number of bytes between the branch instruction and the next instruction to be executed if the condition is met. 16-bit Displacement field -- Used for the displacement when the 8-bit displacement field contains $00. 32-bit Displacement field -- Used for the displacement when the 8-bit displacement field contains $FF.

Note: A branch to the immediately following instruction auto- matically uses the 16-bit displacement format because the 8-bit displacement field contains $00 (zero offset).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM