PureBasic Forum
https://www.purebasic.fr/english/

How add value to a address ???
https://www.purebasic.fr/english/viewtopic.php?f=35&t=69258
Page 1 of 1

Author:  Wolfram [ Tue Sep 26, 2017 11:10 am ]
Post subject:  How add value to a address ???

How can I add a value to the address of A$
Code:
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"

Author:  Mijikai [ Tue Sep 26, 2017 11:22 am ]
Post subject:  Re: How add value to a address ???

This should work:
Code:
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

Author:  Wolfram [ Tue Sep 26, 2017 12:44 pm ]
Post subject:  Re: How add value to a address ???

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)

Author:  wilbert [ Tue Sep 26, 2017 12:48 pm ]
Post subject:  Re: How add value to a address ???

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 ?

Author:  Mijikai [ Tue Sep 26, 2017 1:10 pm ]
Post subject:  Re: How add value to a address ???

What exactly are you trying to do?

Code:
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

Author:  Wolfram [ Tue Sep 26, 2017 1:16 pm ]
Post subject:  Re: How add value to a address ???

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:
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()

Author:  cas [ Tue Sep 26, 2017 2:13 pm ]
Post subject:  Re: How add value to a address ???

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:
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:
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()

Author:  Mijikai [ Tue Sep 26, 2017 2:36 pm ]
Post subject:  Re: How add value to a address ???

The desired string/stringpart should/needs to be copied otherwise the original string might get corrupted.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/