Page 1 of 1
How add value to a address ???
Posted: Tue Sep 26, 2017 11:10 am
by Wolfram
How can I add a value to the address of A$
Code: Select all
A$ ="ABCDEFGH"
*p.string
v.i =4
! lea rcx,[v_A$]
! add rcx, [v_v] ;???
! mov [p_p], rcx
Debug *p\s ;should be "EFGH"
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 11:22 am
by Mijikai
This should work:
Code: Select all
A$ ="ABCDEFGH"
*p.string
v.i = 8;Unicode!
!lea rcx,[v_A$]
!mov rax,[v_v]
!add [rcx],rax
!mov [p_p],rcx
Debug *p\s
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 12:44 pm
by Wolfram
Thanks, it works.
But if I put this code inside a Procedure I get an error.
purebasic.asm:167: error: undefined symbol `v_A' (first use)
purebasic.asm:167: error: (Each undefined symbol is reported only once.)
purebasic.asm:168: error: undefined symbol `v_v' (first use)
purebasic.asm:170: error: undefined symbol `p_p' (first use)
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 12:48 pm
by wilbert
Variables inside a procedure are proceded by p.
Like [p.v_A]
Any reason you are using assembly for this and not simple PB code ?
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 1:10 pm
by Mijikai
What exactly are you trying to do?
Code: Select all
Procedure.i WreckStr(Input.i,Value.i)
!lea rax,[p.v_Input]
!mov rcx,[p.v_Value]
!add [rax],rcx
ProcedureReturn
EndProcedure
TestString.s = "Hello! :)"
*Str.String = WreckStr(@TestString,14)
Debug *Str\s
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 1:16 pm
by Wolfram
wilbert wrote:Variables inside a procedure are proceded by p.
Like [p.v_A]
Any reason you are using assembly for this and not simple PB code ?
I don't want to use Peeks() and also I want to learn.
Inside of the Procedure it crashes now.
Code: Select all
Procedure test()
A.s ="ABCDEFGH"
*p.string
; v.i = 8;Unicode!
v.i = 4;Asci!
!lea rcx,[p.v_A]
!mov rax,[p.v_v]
!add [rcx],rax ;crashes not if I remove this
!mov [p.p_p],rcx
Debug *p\s
EndProcedure
test()
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 2:13 pm
by cas
Wolfram wrote:*p.string
This is not a pointer to string data, it is a pointer to structure called "string". You can see its definition in Tools>Structure Viewer.
Code: Select all
Procedure test()
A.s ="ABCDEFGH"
*p.string=AllocateMemory(SizeOf(string))
PokeI(*p,@A+SizeOf(Character)*4)
Debug *p\s
PokeI(*p,@A+SizeOf(Character)*5)
Debug *p\s
PokeI(*p,@A+SizeOf(Character)*6)
Debug *p\s
FreeMemory(*p)
EndProcedure
test()
Code: Select all
Procedure test()
A.s ="ABCDEFGH"
*p.string=AllocateMemory(SizeOf(string))
*p_i.Integer=*p
*p_i\i=@A+SizeOf(Character)*4
Debug *p\s
*p_i\i=@A+SizeOf(Character)*5
Debug *p\s
*p_i\i=@A+SizeOf(Character)*6
Debug *p\s
FreeMemory(*p)
EndProcedure
test()
Re: How add value to a address ???
Posted: Tue Sep 26, 2017 2:36 pm
by Mijikai
The desired string/stringpart should/needs to be copied otherwise the original string might get corrupted.