how to set some value at a memory location in stack
Vaibhav Shrimali
vaibhav.shrimali@gmail.com
Thu Apr 15 08:36:00 GMT 2010
Ian,
Thanks for all your help so far. I now think I am closer to my goal.
In order to execute :
XOR [EBP+4], [EBP]
after executing :
PUSH EBP
in the prologue, I need to use : emit_insn (gen_xorsi3 (DESTREG, SRC1, SRC2));
So I checked and I can generate a register such that:
rtx ebp_reg = gen_rtx_REG(Pmode, BP_REG);
this would be a hard register.
rtx ebp_plus = gen_rtx_PLUS(Pmode, ebp_reg, 4);
so now executing :-
emit_insn (gen_xorsi3 (ebp_plus, ebp_plus, ebp_reg));
I dont know if ebp_plus would be converted to [XOR+4] or not, although
it is derived from the hard register ebp_reg.
If I am wrong in this approach, please correct me.
Thank You for all your help so far.
On Thu, Apr 15, 2010 at 10:16 AM, Ian Lance Taylor <iant@google.com> wrote:
> Vaibhav Shrimali <vaibhav.shrimali@gmail.com> writes:
>
>> now I have stored the memory location, where I need to insert my
>> value, in the EDX register. I am not using force_reg() now.
>> I have stored the value to be inserted in a rtx type register.
>> But how do I set the value of memory location in EDX with the value
>> stored in a rtx type register?
>> Is there any library function which will allow me to do so?
>>
>> Here is my code:
>>
>> if (frame_pointer_needed)
>> { rtx r, set1,m1,edx,insn,temp;
>> //Here hard frame pointer is pushed onto the stack
>> insn = emit_insn (gen_push (hard_frame_pointer_rtx));
>> RTX_FRAME_RELATED_P (insn) = 1;
>> //Here hard frame pointer is updated
>> insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
>> RTX_FRAME_RELATED_P (insn) = 1;
>>
>> //my code starts from here.
>> r = cfun->machine->force_align_arg_pointer;
>> r = gen_rtx_PLUS (Pmode, r, -8);
>> r = gen_rtx_MEM (Pmode, r);
>> edx = gen_rtx_REG (Pmode, DX_REG);
>> emit_move_insn(edx,r);
>> //EDX now contains the memory location
>>
>> //Here I have stored the return address pushed on the stack in ret_addr
>> //So the following code generates a rtx variable
>> //which has the value ret_addr XOR hard_frame_pointer
>>
>> m1 = simplify_binary_operation(XOR, Pmode, ret_addr,
>> hard_frame_pointer_rtx);
>> //now how to set memory location in edx with value m1??? Is there
>> any function
>> //to do so.If not, please suggest me some other way of doing so.
>>
>> }
>
> You need to put the result of m1 somewhere. There isn't really any
> need to call simplify_binary_operation here. To make this work, you
> should know precisely which instructions you are doing to generate.
> You can just generate them. E.g.,
> emit_insn (gen_xorsi3 (DESTREG, SRC1, SRC2));
>
> Ian
>
--
Vaibhav Shrimali
BTech(ICT), DA-IICT
Gandhinagar
More information about the Gcc-help
mailing list