-1

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'?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
AvinashK
  • 3,309
  • 8
  • 43
  • 94
  • 1
    Sorry, I can't follow your question. Can you clarify? (It looks like a is indeed not PC relative, but I don't know this particular architecture.) – David Given Aug 02 '11 at 11:18
  • @david i read(i am referring to leland l beck's book on system software) that in sic/xe structure addresses are pc relative and if that goes out of range then base relative....so i was pretty convinced that this would be the case but then i saw that for 'b' only immediate mode is used(pc mode though feasible is not used)...and then in the next paragraph book stated the case of 'a' without giving any reason – AvinashK Aug 03 '11 at 16:17

2 Answers2

0

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.

ceving
  • 21,900
  • 13
  • 104
  • 178
  • Are you talking about compacting / garbage-collecting chunks of JITed code + "static" data? This code is written in asm source, so it's being ahead-of-time compiled and can actually be static, not needing to ever more. The other major reason for PC-relative addressing is that it's more compact than absolute when the data is close to the code relative to the size of the address space. (e.g. x86-64 with 32-bit PC-relative in a 64-bit address space.) – Peter Cordes Jul 11 '19 at 07:50
-1

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.

Community
  • 1
  • 1
Johan Bezem
  • 2,582
  • 1
  • 20
  • 47