计算偏移量(摩托罗拉 68k)
Calculating Offset (Motorola 68k)
有人问我如何找到偏移量:
假设指令 BNE HERE 位于内存位置 $FF1234,标签 HERE 代表地址为 $FF12C0 的指令。计算此指令的偏移量(位移)。典型的汇编程序会将偏移量存储为 8 位还是 16 位值?为什么?
我试着这样做来找到位移:
FF1234 + offset = HERE = FF12C0
I tried solving for Offset which is:
FF1234
-FF12C0
等于:33432820?
这是计算偏移量的正确方法吗?
首先:检查 BNE 指令如何使用偏移量以及如果采用跳转,PC 值将用于计算下一个 PC 值。
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.
因此,如果 BNE
指令位于 $FF1234
,用作要添加的偏移量的基数的 PC 的值是 $FF1236
。
OTOH,PC 目标值为 $FF12C0
,因此 $FF1236 + offset = $FF12C0
。 offset
将是一个正值。你应该没问题。
关于另一个问题:
Will the offset be stored as an 8-bit or 16-bit value by a typical
assembler? Why?
不知道是什么意思"a typical assembler"。我不知道它是指任何体系结构的典型汇编程序,还是 m68k 体系结构的典型汇编程序。我只能猜测这是指 "typical assembler generating m68k object code",在这种情况下,您应该能够通过查看偏移值所需的位大小和 BNE 指令的编码选项来回答问题,可用在提到的网页中:
Instruction Format: \i3-++-4Condition,88-bit Displacement,
016-bit Displacement if 8-bit Displacement = [=18=],
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 [=18=]. 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 [=18=] (zero offset).
有人问我如何找到偏移量:
假设指令 BNE HERE 位于内存位置 $FF1234,标签 HERE 代表地址为 $FF12C0 的指令。计算此指令的偏移量(位移)。典型的汇编程序会将偏移量存储为 8 位还是 16 位值?为什么?
我试着这样做来找到位移:
FF1234 + offset = HERE = FF12C0
I tried solving for Offset which is:
FF1234
-FF12C0
等于:33432820?
这是计算偏移量的正确方法吗?
首先:检查 BNE 指令如何使用偏移量以及如果采用跳转,PC 值将用于计算下一个 PC 值。
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.
因此,如果 BNE
指令位于 $FF1234
,用作要添加的偏移量的基数的 PC 的值是 $FF1236
。
OTOH,PC 目标值为 $FF12C0
,因此 $FF1236 + offset = $FF12C0
。 offset
将是一个正值。你应该没问题。
关于另一个问题:
Will the offset be stored as an 8-bit or 16-bit value by a typical assembler? Why?
不知道是什么意思"a typical assembler"。我不知道它是指任何体系结构的典型汇编程序,还是 m68k 体系结构的典型汇编程序。我只能猜测这是指 "typical assembler generating m68k object code",在这种情况下,您应该能够通过查看偏移值所需的位大小和 BNE 指令的编码选项来回答问题,可用在提到的网页中:
Instruction Format: \i3-++-4Condition,88-bit Displacement,
016-bit Displacement if 8-bit Displacement = [=18=],
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 [=18=]. 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 [=18=] (zero offset).