sd ra, 56(sp)
I want to check my understanding of this is correct: namely store the contents of (full width of) ra (ie the return address) at the address pointed to by the stack pointer (sp) plus 56.
From the context this looks close to obvious - setting up a stack frame - but I want to check before I bet the farm on this as the manual isn't very clear (at least to me).
Adrian
On 19 Sep 2016, at 7:20 AM, Stefan O'Rear <sor...@gmail.com> wrote:On Sun, Sep 18, 2016 at 7:11 AM, Adrian Mcmenamin <acm...@york.ac.uk> wrote:Spike has given me this output:
sd ra, 56(sp)
I want to check my understanding of this is correct: namely store the
contents of (full width of) ra (ie the return address) at the address
pointed to by the stack pointer (sp) plus 56.
Close, it means store a "doubleword" (which means 64 bits when talking
about RISC-V) from the ra register into the address pointed at by
sp+56.
If (and this is by far the most likely) you are looking at RV64 code,
then a 64-bit store will indeed save the full width of ra.
If you are looking at RV128 code, then a 64-bit store will only store
half of ra; to store the whole 128 bits use "sq".
If you are looking at RV32 code, then the "sd" instruction is illegal
and you should use "sw" to save the full 32 bits.
Or were you asking about the memory reference syntax? Your
interpretation of 56(sp) as the memory location addressed by sp + 56
is correct; this is the standard notation in GNU assemblers ("AT&T
syntax"). (If you're confused by some construction in RISC-V
assembly, something else you can do is look up how to do it in MIPS,
the ABI and assembler syntax is quite similar.)
On 19 Sep 2016, at 7:20 AM, Stefan O'Rear <sor...@gmail.com> wrote:On Sun, Sep 18, 2016 at 7:11 AM, Adrian Mcmenamin <acm...@york.ac.uk> wrote:Spike has given me this output:
sd ra, 56(sp)I noticed you are storing control flow information on the stack. You might want to enable SafeStack. We don’t any want C strings overwriting return addresses do we.