Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim 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.
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
-
Hi Emil,
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
-
thanks Peter ,
but open the t.txt file it contains not the "i am string variable" string and that is wrong.
-
I wonder me, how can the eax register store a string ?
you just store the address of the string !
-
Peter this line should get the address of string.
call name
mov eax,[eax] ' this line should get the address of string
-
Charles , does string variable has a string descriptor , and if so how is it work ?
-
Hi Emil,
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
-
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?
-
Hi Emil
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
-
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
-
Why do I love Assembler and not Basic.
-
I felt the same about Basic too, which is why I started this project. Would you like to create your own language Peter?
-
Hi Charles ,
thanks for demonstration ,
'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 ?
call name
putfile "t.txt", cast bstring Eax
-
hi Peter
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.
-
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
-
Charles , what do you think about this
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
call @freememory ' we already pushed the argument
how to call freememory from asm ?
-
Would you like to create your own language Peter?
No, I have got one.
-
Peter is switching to SB from what I was told. :o
-
how to call freememory from asm ?
FreeMemory eax
-
Charles , what do you think about this
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
call @freememory ' we already pushed the argument
how to call freememory from asm ?
No Emil, stdcall, will remove parameter from the stack on return from functions. but you can push eax onto the stack twice.
One warning, this asm stuff, you will have to rewrite for 64 bit compiling. The 64 bit calling conventions are not very friendly to programmers. Hence my interest in exposing the abstract assembly layer.
-
Quote
how to call freememory from asm ?
Code:
FreeMemory eax
this is not what i asked for , my be i asked wrongly. any way i was asking for that is this legal
call freememory
or this
call @freememory
No Emil, stdcall, will remove parameter from the stack on return from functions. but you can push eax onto the stack twice.
why , i was thinking that this is good enough
putfile "t.txt",cast bstring eax
so oxygen will cast eax then push it as an argument ,so stdcall will remove the pushed eax in putfil line
and the upper push will work with freememory.
-
Charles , i used this to know how things works.
#show putfile file, cast bstring eax
then i get this list which i did not undersatnd any thing.
$op 1 C1 eax
$op 60 C1
$go 0 [ebx+0x8B0]
$op 4 C1
$pa 1 0 4 [ebp+0x8]
$ch 1
$go 0[ebx+344]
$go 0 [ebx+0x838]
so what is this list?
-
Hi Emil,
You are seeing the machine-friendly / User-unfriendly OIL code for one line of basic. This gets converted to x86 assembly code. Should I turn this demon into an angel? :)
-
okay , what about the above previous post?
-
Should I turn this demon into an angel?
Yes, but 64bit. :D
-
Should I turn this demon into an angel?
(http://files.allbasic.info/O2/O2_Charles.jpg)
Based on everything I've seen to date, that should be a walk in the park. You are truly amazing Charles!