File sramboot. s
# Include "regdef. H"
. Text
. Globl main
Main:
. Set noreorder
. Set noat
La AT, Value
LW A0, 0 ()
LW A1, 4 ()
Jal my_add
Add A2, A0, A1
SW A2, 8 ()
File # include "regdef. H"
. Text
. Globl my_add, Value
My_add:
. Set noreorder
Add A0, A0, 3
J Ra
Add A1, A1, 4
. Data
Value:. Word 10, 20, 0
Makefile
Cc = mipsel-Linux-gcc
As = mipsel-Linux-
LD = mipsel-Linux-LD
Objdump = mipsel-Linux-objdump
Objcopy = mipsel-Linux-objcopy
Textbase =
Ldflags = $ (textbase)-t my. LD
Test. Bin: test.exe
$ (Objcopy)-O binary test.exe test. Bin
Test.exe: Call. O sramboot. o
$ (LD) Call. O sramboot. o $ (ldflags)-O test.exe
$ (Objdump)-D test.exe> test. Dump
RM *. s
Sramboot. O: sramboot. s
$ (CC)-E sramboot. S-O sramboot. s
$ (AS) sramboot. S-O sramboot. o
Call. O: Call. s
$ (CC)-E call. S-O call. s
$ (AS) Call. S-O call. o
Clean:
RM *. O *. EXE *. Bin *. Dump
My. LD File
Output_format ("elf32-tradlittlemips", "elf32-tradbigmips", "elf32-tradlittlemips ")
Output_arch (MIPs)
Sections
{
. Init:
{
Sramboot. o
}
. Text:
{
* (. Text)
}
. Data:
{
* (. Data)
}
. BSS:
{
* (. BSS)
}
}
Test. Sh File
#! /Bin/sh
Mipsel-Linux-objdump-D-m mips-B Binary-el-m no-aliases-z test. Bin> my. Dump
Production depends on the native machine code and can run test. Sh
Only test. Dump
Test 1:
No ttext. = 0 is specified
Test.exe: File Format elf32-tradlittlemips
Disassembly of section. init:
00000000 <main>:
0: 3c010000 lui at, 0x0
4: 24210050 addiu at, at, 80
8: 8c240000 LW A0, 0 ()
C: 8c250004 LW A1, 4 ()
10: 0c000008 Jal 20 <my_add>
14: 00000000 NOP
18: 00853020 add A2, A0, A1
1c: ac260008 SW A2, 8 ()
Disassembly of section. Text:
00000020 <my_add>:
20: 20840003 addi A0, A0, 3
24: 03e00008 Jr Ra
28: 20a50004 addi A1, A1, 4
2c: 00000000 NOP
Disassembly of section. reginfo:
00000030 <. reginfo>:
30: 80000030 LB zero, 48 (zero)
...
Disassembly of section. Data:
00000050 <value>:
50: 0000000a 0xa
54: 00000014 0x14
Test 2:
-Ttext = 0x50. = 0
Test.exe: File Format elf32-tradlittlemips
Disassembly of section. Text:
00000050 <my_add>:
50: 20840003 addi A0, A0, 3
54: 03e00008 Jr Ra
58: 20a50004 addi A1, A1, 4
5C: 00000000 NOP
Disassembly of section. reginfo:
00000060 <. reginfo>:
60: 80000030 LB zero, 48 (zero)
...
Disassembly of section. init:
00000000 <main>:
0: 3c010000 lui at, 0x0
4: 24210080 addiu at, at, 128
8: 8c240000 LW A0, 0 ()
C: 8c250004 LW A1, 4 ()
10: 0c000014 Jal 50 <my_add>
14: 00000000 NOP
18: 00853020 add A2, A0, A1
1c: ac260008 SW A2, 8 ()
Disassembly of section. Data:
00000080 <value>:
80: 0000000a 0xa
84: 00000014 0x14
Test 3:
-Ttext = 0x50. = 0x80000000 (added before. Text output Section)
The result indicates that ttext has a high priority and affects the virtual address of the. Data Output section.
Test.exe: File Format elf32-tradlittlemips
Disassembly of section. Text:
00000050 <my_add>:
50: 20840003 addi A0, A0, 3
54: 03e00008 Jr Ra
58: 20a50004 addi A1, A1, 4
5C: 00000000 NOP
Disassembly of section. reginfo:
00000060 <. reginfo>:
60: 80000030 LB zero, 48 (zero)
...
Disassembly of section. init:
00000000 <main>:
0: 3c010000 lui at, 0x0
4: 24210080 addiu at, at, 128
8: 8c240000 LW A0, 0 ()
C: 8c250004 LW A1, 4 ()
10: 0c000014 Jal 50 <my_add>
14: 00000000 NOP
18: 00853020 add A2, A0, A1
1c: ac260008 SW A2, 8 ()
Disassembly of section. Data:
00000080 <value>:
80: 0000000a 0xa
84: 00000014 0x14
...,
Through the above tests, we can see that-ttext (-tdata-tbss) has a higher priority than. Counter,
Because we didn't specify LMA, LMA = VMA, so when we specify-ttext, the native machine code is filled with a large amount of invalid data, occupying storage space,
By specifying LMA, we can effectively reduce the occupied storage space.