It is currently Thu Nov 23, 2017 11:55 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How add value to a address ???
PostPosted: Tue Sep 26, 2017 11:10 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 342
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"


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 11:22 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 134
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 12:44 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 342
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 12:48 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3003
Location: Netherlands
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 ?

_________________
MacOS 10.13.1 High Sierra, PB 5.60 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 1:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 134
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 1:16 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 342
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()


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 2:13 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 03, 2008 9:56 pm
Posts: 503
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()


Top
 Profile  
Reply with quote  
 Post subject: Re: How add value to a address ???
PostPosted: Tue Sep 26, 2017 2:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 134
The desired string/stringpart should/needs to be copied otherwise the original string might get corrupted.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye