This answer is within the context of Operating System design as might be taught from the book Modern Operating System Design Edition 4 . In chapter 3 one learns about different architectural designs and how an operating system may deal with issues like running multiple programs without a memory abstraction. One such mechanism is to partition memory and each program runs within that partition. An example may be that each program is loaded on a 4kb boundary (0x0000, 0x1000, 0x2000).
I believe this question is in that context.
This program works fine when it is loaded at address 0x0, but not when it is loaded at address 0x1000. Why not?`
The reason would be that the instructions provided attempt to load and store from memory addresses (0x100 and 0x104). If these instructions are loaded starting at 0x1000 and then executed they would likely interfere with the program loaded from 0x0000 to 0x1000. To get around this a simple OS design could have a program loader that statically relocates all absolute memory references to make them relative to the base address of the memory partition they are being loaded in. The base would be 0x1000 in this case so that would be added to 0x0100 and 0x0104. The resulting program would look like:
movl ($0x1100), %eax
movl ($0x1104), %ebx
movl %eax, ($0x1104)
movl %ebx, ($0x1100)
The syntax above seems to be for a fictional (or educational) assembly language (based on x86 AT&T syntax) where ($0x####)
does loads/stores from an absolute physical memory address.
My answer above was made based on observations that this was tagged operating system and in particular the location 0x1000 and the idea of absolute memory references. This in itself made me assume (right or wrong) that likely this was a memory partitioning question in the context of a machine that was using no memory abstractions (like paging and segmentation).
I discovered that the OPs question appears to be part of a course. I noticed that this question has been posed more fully as:
The earliest memory systems managed physical memory directly, and typically
the operating system could do very little to make programming easier.
In this studio, you will:
Consider statically partitioned physical memory
Consider dynamically partitioned memory with base and limit registers
Explore the limitations of physical memory based methods
[snip]
2. Consider a program that uses absolute physical memory references meaning that each
reference refers to a specific physical memory location. One part of such a program
is below:
movl ($0x100), %eax
movl ($0x104), %ebx
movl %eax, ($0x104)
movl %ebx, ($0x100)
This program works fine when it is loaded at address 0x0, but not when it is
loaded at address 0x1000. Why not?
3. Re-write the above code so the program works when it is loaded at memory
address 0x1000.
4. Suppose you have a machine with four static parititons, each capable of holding a
program with a length of 4096 bytes (0x1000 bytes). The first partition starts
at address 0x0. Give the first and last address of each of the four partitions.
5. Suppose the first of the four programs executes the following line of code,
with the operand located at byte 0x25, and the destination address located
at bytes 0x26-0x2A:
0x25: jmp ($0x50)
Suppose also another program executes the following line first.
movl $0x1234, ($0x26)
What happens to the first progam upon executing the instruction at address 0x25?
The course syllabus says that Modern Operating System (Edition 4 being the latest) is being used for the course and that there is an assignment was due recently. The syllabus also suggests this studio (exercise) is associated with Chapter 3 of the book.
Oct 16 Memory management MOS 3.1 Studio 15-a
Oct 18 Address spaces and swapping MOS 3.2 Studio 15-b
With this in mind I believe the answer I gave above is probably a reasonable answer given Chapter 3 of the book and what is being asked in the exercise.