Author Topic: string and asm  (Read 5916 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
string and asm
« on: March 29, 2013, 10:35:28 AM »

Hi all,

i have a function that return a string variable type and i call it by call asm instruction , then i want to save the returned string in file so i used putfile. but it did not wrok as expected , any help please.
Code: [Select]

function name() as string
     string s = "i am string variable"
     return s
end function


sub Main

     call  name
     mov eax,[eax]
     putfile "t.txt",eax

 

Peter

  • Guest
Re: string and asm
« Reply #1 on: March 29, 2013, 10:54:48 AM »
Hi Emil,

Code: [Select]
function name() as string
     string s = "i am string variable"
     return s
end function


sub Main

     call  name
     mov eax,[eax]
     putfile "t.txt",eax
     
End Sub     

Main

Emil_halim

  • Guest
Re: string and asm
« Reply #2 on: March 29, 2013, 11:05:18 AM »

thanks Peter ,

but open the t.txt file it contains not the "i am string variable" string and that is wrong.

Peter

  • Guest
Re: string and asm
« Reply #3 on: March 29, 2013, 11:19:11 AM »
I wonder me, how can the eax register store  a string ?
you just store the address of the string !

Emil_halim

  • Guest
Re: string and asm
« Reply #4 on: March 29, 2013, 11:22:25 AM »

Peter this line should get the address of string.
Code: [Select]
    call  name
    mov eax,[eax]  ' this line should get the address of string

Emil_halim

  • Guest
Re: string and asm
« Reply #5 on: March 29, 2013, 11:28:19 AM »

Charles , does string variable has a string descriptor , and if  so how is it work ?   

Peter

  • Guest
Re: string and asm
« Reply #6 on: March 29, 2013, 11:59:57 AM »
Hi Emil,

Code: [Select]
indexbase 0

function name() as string
     string s = "i am string variable"
     return s
end function


sub Main
     char s[22], dword x
     name
     lea esi,s
     mov edx,x 
     .m1 mov cl,[eax+edx]
mov [esi+edx],cl
         inc edx
         cmp edx,20
         jnz m1     
putfile "t.txt",s
End Sub     

Main

Emil_halim

  • Guest
Re: string and asm
« Reply #7 on: March 29, 2013, 12:15:31 PM »

Ok thanks Peter ,

but why you copy the returned string in char array then pass this copy to Putfile?

BTW name is a dummy function here , in real code you did not know the length of returned string?

Peter

  • Guest
Re: string and asm
« Reply #8 on: March 29, 2013, 01:15:59 PM »
Hi Emil
Code: [Select]
indexbase 0
sys length

function name() as string
     string s = "i am string variable"
     length = Len(s)
     return s
end function


sub Main
     char s[22], dword x
     name
     lea esi,s
     xor edx,edx 
     .m1 mov cl,[eax+edx]
mov [esi+edx],cl
         inc edx
         cmp edx,length
         jnz m1     
putfile "t.txt",s
End Sub     

Main

Charles Pegge

  • Guest
Re: string and asm
« Reply #9 on: March 29, 2013, 01:21:13 PM »
A string function returns a bstring, which points to an array of characters.

With low level handling you must free the string after.

function name() as string
     string s = "i am string variable"
     return s
end function

'low level handling
sys a
call  name
mov a,eax
putfile "t.txt", cast bstring a
freememory a


But basic will do it all for you :)

putfile "t.txt",name




Peter

  • Guest
Re: string and asm
« Reply #10 on: March 29, 2013, 01:37:06 PM »
Why do I love Assembler and not Basic.

Charles Pegge

  • Guest
Re: string and asm
« Reply #11 on: March 29, 2013, 02:10:38 PM »
I felt the same about Basic too, which is why I started this project. Would you like to create your own language Peter?

Emil_halim

  • Guest
Re: string and asm
« Reply #12 on: March 30, 2013, 07:27:52 AM »

Hi Charles ,

thanks for demonstration ,

Quote
'low level handling
sys a
call  name
mov a,eax
putfile "t.txt", cast bstring a
freememory a


using a variable for moving the address of string into it then casting it so that it works with putfile ,
is not good.
can Oxygen allow casting directly from register , something like this ?
Code: [Select]
call  name
putfile "t.txt", cast bstring  Eax

Emil_halim

  • Guest
Re: string and asm
« Reply #13 on: March 30, 2013, 07:40:39 AM »

hi Peter
Quote
Why do I love Assembler and not Basic.

the best thing in Oxygen basic is that you have a variety of ways to achieve a certain things.

for example see the example of iteration. the for statement can be in pure basic and can be in mix between
basic & C and can be in pure C.

this make Oxygen a very good tool for programming.

I do like to mix my coding in basic , C , asm to get the best thing that i need , so the point here is not to love asm and not basic.       

Charles Pegge

  • Guest
Re: string and asm
« Reply #14 on: March 30, 2013, 08:50:53 AM »
Yes, I agree about the variable. I forgot all about the stack :)

function name() as string
     string s = "i am string variable"
     return s
end function

'low level handling
name
push eax
putfile "t.txt",cast bstring eax
pop eax
freememory eax