开发者

immediate and program counter relative addressing

开发者 https://www.devze.com 2023-03-25 11:11 出处:网络
i came across a code for an sic/xe machine....below are the lines which were a source of problem for me...

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 mo开发者_StackOverflowde....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'?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号