-3
long long int i=57745158985; #the C code
    
0000000000100004: li r7,13
0000000000100008: lis r8,29153 
000000000010000c: ori r8,r8,0x3349
0000000000100010: stw r7,24(rsp)
0000000000100014: stw r8,28(rsp)
0000000000100018: lfd fp0,24(rsp)
000000000010001c: stfd fp0,8(rsp)

Hello, when I disassemble the CodeWarrior c code, this code comes up. In the code, offset is given to the registers. I don't understand why the given offsets are 24, 28, and 8. How does it determine this? Would it work if it assigned any other value?

umt
  • 7
  • 2
  • 1
    Are you sure it's `=5` in there, and not some other expression which evaluates to 5? Seems pretty unlikely that a compiler would generate 7 operations for a single constant assignment. –  Aug 10 '22 at 06:18
  • The value was entered incorrectly while entering the question. I edited. – umt Aug 10 '22 at 06:56
  • 2
    You should give the complete C function, and complete disassembly of the function. – hyde Aug 10 '22 at 07:09
  • To understand this, get hex dump of the stack, and locate these values in the dump, together with parameters and return address and saved registers. This is not full code, so it is kinda hard for us to do. – hyde Aug 10 '22 at 07:11
  • 1
    Also, convert the 57745158985 to hex. – hyde Aug 10 '22 at 07:12
  • Answer for this is already in https://stackoverflow.com/questions/73291354/the-usage-of-offset-for-storing-stw-in-powerpc-assembly – Mikey Aug 10 '22 at 22:39

1 Answers1

1

This depends on the ABI for your platform and architecture.

Assuming your platform is the PowerPC e500 Application Binary Interface. The register in question (rsp) is the stack pointer. Those offsets are references to within the functions stack frame. To understand the stack frame of a function you need to consult the ABI.

If you look at Section 2.3 The Stack Frame of 1 you will see the layout for a functions stack frame. That is what the compiler is targeting when those offsets like 24 and 28 are being determined.

jpn
  • 81
  • 2