3

Can anyone explain me what does high vs low addresses mean in the context of the following question?:

By definition, “high” addresses are those that are large unsigned numbers and “low” addresses are those that are small unsigned numbers.

What is the highest address to which control can be transferred using a beq (branch on equal) instruction that resides at the physical memory address 0x320ACB48?

Matt
  • 22,721
  • 17
  • 71
  • 112
KJP
  • 531
  • 2
  • 9
  • 19
  • 1
    You may want to check this: http://stackoverflow.com/questions/6950230/how-to-calculate-jump-target-address-and-branch-target-address/6954138#6954138 – nrz Mar 06 '13 at 01:16

1 Answers1

2

The answer depends on the particular MIPS chip and on its MMU (if any).

The valid addresses for 32-bit instructions are from 0 to 4GB-4. However, if the memory isn't present in the entire range or if there are memory-mapped devices or if you have virtual to physical address translation enabled, you will not be able to execute code at an arbitrary location at all or in a meaningful way.

If you transfer control to a location not backed up by memory, you execute garbage. The same applies to transferring control to a location that represents some memory mapped device's registers or data buffers.

If the page translation is set up in such a way that it restricts accesses to specific regions of addresses or disallows execution there, you cannot execute anything in those regions at all.

Now, there's also a limitation in beq in terms of how far in can transfer control from where it (beq) is located itself. beq can only transfer control to its location +/- approximately 217 bytes (=128KB).

So, in theory, beq located at 0x320ACB48 could transfer control to any location (that's a multiple of 4) from 0x320ACB48 + 4 - 32768*4 to 0x320ACB48 + 4 + 32767*4.

If beq is located near address 0, it may be able to transfer control to near 4GB, unless the CPU prohibits wrapping of addresses. Likewise, if beq is near the 4GB point, it may be able to transfer control to near address 0, unless, again, address wrapping is prohibited by the CPU.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
  • could you explain this sentence again: "in theory beq located at 0x320acb48 could transfer control to any location that is a multiple of 4". beq leaves us 16bits of offset so why isn't the highest memory address to which this instruction can transfer control to not 0x7fff or 32,767? I am having trouble understanding your logic. – curiousX Feb 24 '19 at 20:45
  • @curiousX MIPS instructions (unless we're talking about extensions like microMIPS and MIPS16e) are 4 bytes long and always being on addresses that are a multiple of 4. There's no point in using the 16-bit offset as a byte offset, it would be a waste. So, the 16-bit offset in the branch instruction is multiplied by 4. – Alexey Frunze Feb 25 '19 at 07:44