CSE 127: SPARC -- Calling a lower address

To see how the call instruction is used to call a lower address, let us examine the following transcript:
ieng9.ucsd.edu% cat > lower.c
void lower(char *s) 
int main(void)   
        lower("Hello world");    
ieng9.ucsd.edu% gcc -g lower.c -o lower
ieng9.ucsd.edu% gdb lower
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.6"...
(gdb) break main
Breakpoint 1 at 0x10588: file lower.c, line 9.
(gdb) run
Starting program: /home/solaris/ieng9/cs127w/cs127w/lower 

Breakpoint 1, main () at lower.c:9
9               lower("Hello world");
(gdb) x/i main
0x10584 <main>: save  %sp, -112, %sp
0x10588 <main+4>:       sethi  %hi(0x10400), %o1
0x1058c <main+8>:       or  %o1, 0x228, %o0     ! 0x10628 <_lib_version+16>
0x10590 <main+12>:      call  0x10560 <lower>
0x10594 <main+16>:      nop 
(gdb) x/i lower
0x10560 <lower>:        save  %sp, -112, %sp
(gdb) x/x 0x10590
0x10590 <main+12>:      0x7ffffff4
Note that the address of the call lower instruction is 0x10590. The instruction is, in hex,
7fff fff4
0111 1111 1111 1111  1111 1111 1111 0100
The high two bits specifies that this is the call instruction, and the rest of the bits is the offset:
offset: 11 1111 1111 1111  1111 1111 1111 0100
this is a signed quantity, equal to a word offset of -0xC. We must multiply this by 4 to get the byte offset, which is -0x30.

If you subtract 0x30 from 0x10590, you get 0x10560 -- which is the address of the function lower!

[ search CSE | CSE | bsy's home page | links | webster | MRQE | google | yahoo | citeseer | certserver ]
picture of bsy

bsy+cse127w02@cs.ucsd.edu, last updated Mon Mar 25 15:22:08 PST 2002. Copyright 2002 Bennet Yee.
email bsy.

Don't make me hand over my privacy keys!