Oxygen Basic

Programming => Problems & Solutions => Topic started by: Emil_halim on March 20, 2013, 07:37:08 AM

Title: asm code problem.
Post by: Emil_halim on March 20, 2013, 07:37:08 AM

this was discussion in OXYEditor under tools section , but i see it is better to put it here.

Charles ,

this did not work as expect
Quote
$ filename "test2.exe"
#include "..\..\inc\RTL32.inc"

addr ecx,xx
[ecx] = 100
print hex [ecx]
end

.xx
dd  0
   
Title: Re: asm code problem.
Post by: Peter on March 20, 2013, 07:50:00 AM
Hi Emil,

end means in OxygenBasic  "marks the end of a code block"
 
Isn't termination!
Title: Re: asm code problem.
Post by: Emil_halim on March 20, 2013, 07:54:16 AM
Hi Peter ,

yes i know that end will tell the compiler to stop at that point and don't execute the following  instruction.

but how this help in this case?   
Title: Re: asm code problem.
Post by: Emil_halim on March 20, 2013, 07:57:22 AM
i was playing with my old strcpy function in Ziron and start to compile it under Oxygen and......

it compiled ok with a Little changes , but it refused to run as the above problem.
Code: [Select]

$ filename "test3.exe"
#include "..\..\inc\RTL32.inc"

function  H_strcpy(Dword dst,src)
{
 ' uses edx ebx;
  push edx : push ebx
  Eax = dst;
  Edx = src;
  push Eax;
  BL =  char[Edx];
  while ( BL != 0)  
   {
      char[Eax] = BL;
      Eax++; Edx++;
      BL =  char[Edx];
   }  
  char[Eax] = 0;
  pop Eax;
  pop ebx : pop edx
}

dim as string * 1024 buf

H_strcpy(&buf,"Emil Halim")

print buf
Title: Re: asm code problem.
Post by: Peter on March 20, 2013, 09:39:39 AM
Code: [Select]
indexbase 0
'$ filename "test3.exe"
'#include "..\..\inc\RTL32.inc"

string buf  

Sub H_strcpy(string dst, string src)
  pushad
  mov Eax,dst
  mov Edx,src
.w  
  
      mov CL, [Edx]
      mov [Eax], CL
      inc Eax
      inc Edx
      mov CL, [Edx]
    
  cmp CL,0
  jnz w
  popad
End Sub

H_strcpy(buf,"Emil Halim ")

print buf
Title: Re: asm code problem.
Post by: Emil_halim on March 20, 2013, 10:24:30 AM

ok ,Peter thanks for converting.

but i really want to know Oxygen compiled it with no error and what could be the op-code that came out?
Title: Re: asm code problem.
Post by: Charles Pegge on March 20, 2013, 11:14:54 AM
Hi Emil, Peter,

the '=' operator usually translates to something like this

a=b

---->

mov eax,b
mov a,eax



copy is a built-in function and works on the var address or strpr for strings

'copying from b to a , n bytes:

copy @a,@b,n
or
copy &a,&b,n


Using Oxygen Asm with block feature:

zstring a[]="ABCDE"
zstring b[]="12345"
sys n=len a

mycopy:
addr esi,b
addr edi,a
mov ecx,n
(
  dec ecx
  jl exit
  mov al,[esi]
  mov [edi],al
  inc esi
  inc edi
  repeat
)
print b


NB: I noticed that addr does not handle bstrings and strings correctly, so I will add the mod to my next release.

zstrings / char is ok

Charles
Title: Re: asm code problem.
Post by: Peter on March 20, 2013, 12:13:14 PM
I use Assembler in old style, I have no problems.
Title: Re: asm code problem.
Post by: Emil_halim on March 20, 2013, 12:18:01 PM
Hi Peter ,

this is old style but still did not work

Code: [Select]
addr ecx,xx
mov [ecx] , 100
print hex [ecx]
end

.xx
dd  0
Title: Re: asm code problem.
Post by: Peter on March 20, 2013, 12:26:00 PM
Hi Emil,



X
Title: Re: asm code problem.
Post by: Emil_halim on March 20, 2013, 12:29:57 PM
this is very strange , it compiled okay but refused to run.

can Mr Charles give any hint here please!!!!!!!!!!  
Title: Re: asm code problem.
Post by: Peter on March 20, 2013, 12:37:31 PM
Quote
can Mr Charles give any hint here please!!!!!!!!!! 

LOL  :D
Title: Re: asm code problem.
Post by: Emil_halim on March 21, 2013, 07:13:06 AM

Hi Peter ,

i think Oxygen has some troubles with 32bit version of windows , to ensure that , want to test it with
other 32bit machine , do you have one ? 
Title: Re: asm code problem.
Post by: JRS on March 21, 2013, 07:20:22 AM
I run 32 bit XP in a VirtualBox under Ubuntu 64. I have Win7 64 bit in a separate bootable partition. (64 bit Windows testing only)  For me this is a great way to test both 32 & 64 bit Windows and still use a sane OS for development. For quick tests without having to fire up the XP VirtiualBox, I use Wine.

Title: Re: asm code problem.
Post by: Peter on March 21, 2013, 07:27:59 AM
No, I haven't.
But you can knock at Aurel. He drives ancient WinXP 32 Bit.
Title: Re: asm code problem.
Post by: Peter on March 21, 2013, 07:51:18 AM
Something runs wrong with last OxygenBasic versions.

I have had never problems with making of dlls. But now, 24 hour on the day.
One could think, Charles don't like aliens dlls. It makes him afraid.
Title: Re: asm code problem.
Post by: Charles Pegge on March 21, 2013, 11:39:40 AM

Hi Emil,

This will work when run directly in memory, but when compiled, it cannot work because you are writing into a code section, which is configured as read-only. To create some data space you can map to global and static variables for fixed-location storage, or local variables to stack storage or strings and bstrings for heap-allocated storage.

Interesting case :)

Code: [Select]
addr ecx,xx
mov [ecx] , 0x64
print hex [ecx]
end

.xx
dd  0

Peter,

I'm giving DLLs a thorough workout with ScriptBasic, PowerBasic and thinBasic interfacing. Since my last Oxygen posting (with the RTLs)  I have not come across any major problems, though a  few subtle ones,  mainly associated with complex C headers.

Charles
Title: Re: asm code problem.
Post by: Emil_halim on March 22, 2013, 12:01:31 AM

oh . i got it Charles , this will work okay
Code: [Select]
sub main()
addr ecx , xx
print hex [ecx]
MOV [ecx] , 100
print hex [ecx]
end sub

main
end

.xx
dd  10

but see the next one it compiled and worked okay , as you said it will resident in  read-only section!!!!!!!

Code: [Select]
addr ecx , xx
print hex [ecx]
end

.xx
dd  10

thanks ,
Emil.