简体   繁体   English

计算偏移量(Motorola 68k)

[英]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. 假定指令BNE HERE在存储器位置$ FF1234中,标签HERE表示地址$ FF12C0中的指令。 Compute the offset (displacement) for thisinstruction. 计算该指令的偏移量(位移)。 Will the offset be stored as an 8-bit or 16-bit value by a typical assembler? 偏移量将由典型的汇编器存储为8位或16位值吗? 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? 等于: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. 首先:检查BNE指令如何使用偏移量,以及如果进行了跳转,则使用哪个PC值来计算下一个PC值。

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

Description: If the specified condition is true, program execution continues at location (PC) + displacement. 说明:如果指定的条件为true,则程序将在位置(PC)+位移处继续执行。 The PC contains the address of the instruction word of the Bcc instruction plus two. PC包含密件抄送指令的指令字地址加两个。 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. 位移是一个二进制补码整数,表示从当前PC到16位位移(紧随指令之后的字)的相对距离(以字节为单位)。 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. 如果指令字中的8位位移字段全为($ FF),则使用32位位移(紧随指令之后的长字)。

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 . 因此,如果BNE指令位于$FF1234 ,则用作要添加偏移量基础的PC的值为$FF1236

OTOH, the PC destination value is $FF12C0 , so $FF1236 + offset = $FF12C0 . OTOH,PC目标值为$FF12C0 ,因此$FF1236 + offset = $FF12C0 offset will be a positive value. offset将为正值。 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? 偏移量将由典型的汇编器存储为8位或16位值吗? 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. 我不知道它是针对任何架构的典型汇编程序,还是针对m68k架构的典型汇编程序。 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: 我只能猜测这是指“生成m68k目标代码的典型汇编程序”,在这种情况下,您应该能够仅通过查看偏移值和BNE的编码选项所需的位大小来回答问题。说明,可在上述网页中找到:

Instruction Format: \\i3-++-4Condition,88-bit Displacement, 指令格式:\\ i3-++-4条件,88位位移,

016-bit Displacement if 8-bit Displacement = $00, 如果8位位移= $ 00,则为016位位移

032-bit Displacement if 8-bit Displacement = $FF, 如果8位位移= $ FF,则为032位位移

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. 8位位移字段-二进制补码整数,指定满足条件的分支指令和要执行的下一条指令之间的字节数。 16-bit Displacement field -- Used for the displacement when the 8-bit displacement field contains $00. 16位位移字段-当8位位移字段包含$ 00时用于位移。 32-bit Displacement field -- Used for the displacement when the 8-bit displacement field contains $FF. 32位位移字段-当8位位移字段包含$ 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). 注意:紧随其后的指令的分支会自动使用16位位移格式,因为8位位移字段包含$ 00(零偏移量)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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