立即数和程序计数器相对寻址
我遇到了 sic/xe 机器的代码....下面是对我来说是问题根源的行...
0003 LDB #LENGTH ;a
0020 LDA #3 ;b
0033 LENGTH RESW 1 ;c
103C +LDT #4096 ;d
现在给出了“a”将有一个目标代码,其中 pc 相对和立即模式将被使用....但 b 将只有立即模式....现在长度为 0033,那么为什么要使用 pc 相对模式....如果按照惯例,也必须使用 pc 相对模式那么为什么不同时使用 pc 相对和立即'b'?
i came across a code for an sic/xe machine....below are the lines which were a source of problem for me...
0003 LDB #LENGTH ;a
0020 LDA #3 ;b
0033 LENGTH RESW 1 ;c
103C +LDT #4096 ;d
now it was given that 'a' will have an object code in which pc relative and immediate mode will be used....but b will have just immediate mode....now as length is at 0033, so why use pc relative mode....and if it is imperative by convention that pc relative mode is too be used so why not use both pc relative and immediate in 'b'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当需要改变机器代码在存储器中的位置时,使用相对于程序计数器的地址。这通常是垃圾收集所必需的。参见 Andrew W. Appel 的第 13.3 章; 使用Continuations进行编译;剑桥大学出版社,2007。
Addresses relative to the program counter are used, when it is necessary to change the position of the machine code in the memory. This is typically necessary for garbage collection. See chapter 13.3 in Andrew W. Appel; Compiling with Continuations; Cambridge University Press, 2007.
抱歉,但这并不是我所期望的问题。
首先,您的“代码行”完全脱离了上下文,因为第一列表示位置,所以我们丢失了中间的所有位置。对此减一分。
其次,请使用适当的标签将此标记为作业。对此减一分。
第三,请附上对原始来源的引用,例如 您的大学给您的 PPT 文件。减二十。
你觉得自己很幸运,我只能减去一。
现在我不是坏人,综合来看,所以这是我的答案 FWIW:
LENGTH 是属于地址 0033 的标签,保留了 3 字节字,位于当前 PC 位置附近。由于汇编程序在其决策中是自主的,因为相对于 PC 优先,并且由于最大 2047 的偏移量已经足够,所以汇编程序将采用相对于 PC 的方式。如果您查看我链接的 PPT 中的操作码,您将看到 2D(十六进制)的 PC 相对(p=1)偏移量,LDB 指令之后的位置是 6,并且 2D+6=33(所有十六进制),QED。
'b' 的含义相同:由于 b=0 和 p=0,我们使用立即寻址,并且操作码的“地址”为 3,因此 A 被加载常量 3。
只有操作码中的加号表示format4 使用具有 20 位地址字段的 4 字节指令。
Sorry, but this is not quite what I expect of a question.
First, your "lines of code" are completely taken out of context, since the first column indicates location, so we are missing all locations in-between. One minus for that.
Secondly, please indicate this as homework using the appropriate tag. One minus for that.
Third, please include a reference to the original source, like the PPT file your university gave you. Twenty minus for that.
Consider yourself lucky that I can only subtract one.
Now I'm not a bad guy, all taken together, so here are my answers FWIW:
LENGTH is the label belonging to an address 0033 reserving a 3-byte word, located in the vicinity of the current PC location. Since assembler is autonomous in its decision, since PC-relative is to take priority, and since an offset of 2047 max is more than sufficient, PC-ralative is taken by the assembler. If you look at the opcode in the PPT I linked, you'll see a PC-relative (p=1) offset of 2D (hex), and the location after the LDB instruction is 6, and 2D+6=33 (all hex), QED.
In the same sense is 'b': Since b=0 and p=0 we use immediate addressing, and the opcode has an "address" of 3, so A is loaded with the constant 3.
Only the plus signs in the opcodes indicate format4 using 4 byte instructions with 20-bit address fields.