How add value to a address ???

Bare metal programming in PureBasic, for experienced users
Wolfram
Enthusiast
Enthusiast
Posts: 529
Joined: Thu May 30, 2013 4:39 pm

How add value to a address ???

Post 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"
User avatar
Mijikai
Addict
Addict
Posts: 1032
Joined: Sun Sep 11, 2016 2:17 pm

Re: How add value to a address ???

Post 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
Wolfram
Enthusiast
Enthusiast
Posts: 529
Joined: Thu May 30, 2013 4:39 pm

Re: How add value to a address ???

Post 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)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3747
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How add value to a address ???

Post 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 ?
macOS 10.15 Catalina, Windows 10
User avatar
Mijikai
Addict
Addict
Posts: 1032
Joined: Sun Sep 11, 2016 2:17 pm

Re: How add value to a address ???

Post 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
Wolfram
Enthusiast
Enthusiast
Posts: 529
Joined: Thu May 30, 2013 4:39 pm

Re: How add value to a address ???

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

Re: How add value to a address ???

Post 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()
User avatar
Mijikai
Addict
Addict
Posts: 1032
Joined: Sun Sep 11, 2016 2:17 pm

Re: How add value to a address ???

Post by Mijikai »

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