Download presentation
Presentation is loading. Please wait.
1
Compiling examples in MIPS
Relocatable programs Compiling of 2 modules Linking 2 modules
2
Programs are compiled based on address
When we compile the program we suppose that it will work starting from the predefined memory address. Usually in SPIM by default the address is defined as 0x This is done assuming that the program will be loaded in the real memory starting from that address. .text .globl main . . . .data x: word 4 value: .word 1 For one program this assumption doesn’t create any problems.
3
Many modules or programs in memory
What if we have two programs and want to load them into the memory and to keep both of them there at the same time ? For sure one of the programs should reside not in the 0x address. We can compile it starting from the other address. Program1 Program2 . . . if we know the size of the first program
4
Compile programs with different addresses
The address of compiling could be chosen in .text and .data directives as shown in the textbook (with some limitation of the range). Then the second program could reside after the first program in different addresses. Program2 Program1 Program1 What if for some reason the first program becomes larger overlapping the second program ? text 0x .globl main . . . .data 0x x: word 4 value: .word 1 .text 0x .globl main . . . .data 0x x: word 4 value: .word 1
5
Recompile to Relocate the program ?
Then we have to move the second program further up to the memory for example to 0x addresses. This could be done by recompiling the program with new .text .data directives. But this is not the best way to relocate the program Program1 Program2
6
Relocatable program Will be well if the program could be relocated smoothely without recompiling. This achieves compiling the program only once but with the relocatable code. In this code there should exist only relative addresses which are relative to the modules initial address or current running instructions. Absolute addresses make the module non relocatable. Program1 Program2 With the relocatable code your module can travel in the memory wherever is allowed by the OS.
7
How the binary code could be relocatable ?
8
Binary code is different (non relocatable)
If the instructions contain the absolute addresses then that code is not relocatable. To make the code relocatable the compiler should use only relative addresses based on some base register(s) value.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.