Author Topic: High Level Asm translator  (Read 4233 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
High Level Asm translator
« on: April 04, 2013, 09:34:23 AM »
Hi all

here is the first release of my tool HighLevelAsm , containing the source code written with BCX.

also contains a test example that showing you many good information of Oxygen and heihlevelasm.

here is the example
Code: [Select]

//*********************************
//*  test program by Emil Halim   *
//*       4 / 4 / 2013            *
//*********************************

indexbase 0
$ filename "test4.exe"
#include "..\..\inc\RTL32.inc"

zstring a[]="ABCDE"
zstring b[]="12345"

'string copy functio
====================
Sub H_strcpy(zstring dst,src)  // pass by address of '&' or '@'
 #HLAsm {
     uses edx ebx
     Eax = dst
     Edx = src
     .repeat
          CL = char[Edx]
          char[Eax] = CL
          Eax++
          Edx++
          CL = char[Edx]     
     .until  CL != 0
  }                     // here will automaticaly pop the rigesters that in uses statment and puting ret instruction
End Sub

'string length function like c
==============================
int H_strlen(zstring _str)
{   
  #HLAsm {
      eax = _str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    }
    return 



'string length function like c
==============================
int H_strlen1(zstring* _str) //pass by just variable name
{   
  #HLAsm {
      addr eax,_str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    }
    return 


'string length function like basic
==================================
Sub H_strlen2(zstring _str)
  #HLAsm {
      eax = _str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    } 
End Sub

'string length function like Oxygen Macro
=========================================
macro H_strlen3(z,le)
{
 addr eax,z
 mov ecx,eax
 {
  cmp byte [eax],0
  jz exit
  inc eax
  repeat
 }
 sub eax,ecx
 mov le,eax
}

'string length function
=======================
function H_strlen4(zstring _str) as sys
    #HLAsm {
      eax = _str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    } 
   return     // return value is in Eax
end function

'string length function
=======================
function H_strlen6(zstring _str) as sys
    #HLAsm {
      eax = _str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    } 
   function = Eax     // return value is in _return local variable i.g ' mov _return,Eax
end function

'string length function
=======================
function H_strlen7(zstring _str) as sys
    #HLAsm {
      eax = _str
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    } 
   return  Eax     // return value is in EAX ,it skips over the _return assignment.
end function



' Testing
==========

H_strcpy(&a,&b)
print a

print H_strlen1(a)
 
print H_strlen(&a)

print H_strlen2(&a)

sys i
H_strlen3(a,i)
print i

print H_strlen4(&a)

addr eax,a : gosub H_strlen5
print eax

print H_strlen6(&a)
print H_strlen7(&a)

end

'string length subroutin
========================
.H_strlen5:
   #HLAsm {
      Edx = Eax
      .while byte [Eax] != 0 
          Eax++
      .endw
      Eax -= Edx 
    } 
   ret
   

X

Charles Pegge

  • Guest
Re: High Level Asm translator
« Reply #1 on: April 04, 2013, 11:15:06 PM »
Thanks Emil

Emil_halim

  • Guest
Re: High Level Asm translator
« Reply #2 on: April 05, 2013, 07:17:57 AM »
okay , second release of OxyHLasm , fixing inline high asm bugs.

here is example shoing you how to use inline high level asm by symbol '^'

Code: [Select]

//*********************************
//*  test program by Emil Halim   *
//*       5 / 4 / 2013            *
//*********************************

indexbase 0
$ filename "AscToDword.exe"
#include "..\..\inc\RTL32.inc"

zstring a[]="12345"

   addr edx,a : gosub AscToDwor_proc : add eax , 10
   print eax   //12355
end

==========================
AscToDwor_proc:

          xor eax, eax               ; clear eax
 ^  @@:   movzx byte ecx, [edx]      ; move 1 byte into ecx
 ^        lea eax, [eax+eax*4]       ; eax = 5 * eax
 ^        lea eax, [eax*2+ecx-30h]   ; eax = 2 * eax + (ecx-30h)
 ^        edx++                      ; inc edx
 ^        cmp byte[edx], 0           ; if end of string then return
 ^        jne @b
 ^        ret

Edited:

this asm example i fount it in masm forum , it is fast and simple ascii to dword converter 


X
« Last Edit: April 05, 2013, 07:35:15 AM by Emil_halim »

Emil_halim

  • Guest
Re: High Level Asm translator
« Reply #3 on: April 09, 2013, 11:26:09 AM »

Hi all ,

this time i have improved and added HighLevelAsm with FPU.

here is a snippet code taken from opnegl2.o2bas example in asm folder
Code: [Select]

''========================================================================
'' DrawScene() - Draw the scene (a rotating torus)
''========================================================================

  ;---------
  DrawScene:
  ;---------
    glPushMatrix
    ; Rotate the object
    push edi
    ^ esp -= 12
    ^ edi = esp   
    ^ st = dword rot_x
    ^ st *= double half
    ^ float [edi  ] = st
    ^ st = dword rot_y
    ^ st *= double half
    ^ float [edi+4] = st
    ^ st = dword rot_z
    ^ st *= double half
    ^ float [edi+8] = st
    ; user rotation
    glRotatef  [edi  ], 1.0, 0.0, 0.0
    glRotatef  [edi+4], 0.0, 1.0, 0.0
    glRotatef  [edi+8], 0.0, 0.0, 1.0
    ^  esp += 12
    pop edi
    ; Set model color (used for orthogonal views, lighting disabled)
    glColor4fv &model_diffuse

    '' Set model material (used for perspective view, lighting enabled)
    (
    def GL_AMBIENT   0x1200
    def GL_DIFFUSE   0x1201
    def GL_SPECULAR  0x1202
    def GL_SHININESS 0x1601
    def GL_FRONT     0x0404
    glMaterialfv  GL_FRONT, GL_DIFFUSE,   &model_diffuse
    glMaterialfv  GL_FRONT, GL_SPECULAR,  &model_specular
    glMaterialf   GL_FRONT, GL_SHININESS, model_shininess
    )

    call DrawTorus
    glPopMatrix
    ret ; end of drawscene


  o2 !4

Emil_halim

  • Guest
Re: High Level Asm translator
« Reply #4 on: April 12, 2013, 04:52:13 AM »

Hi all ,

i have add some more instructions. see below
Quote
edx:eax = #TimeStamp   -----converted to ------->  rdtsc
 edx:eax = eax               -----converted to ------->  cdq
 edx:eax /= max             -----converted to ------->  idiv max
 eax = ecx * 100            -----converted to ------->  imul eax,ecx,100

here is the rnd function in full highlevelasm

Code: [Select]
int H_Rnd(int max)
{
   ^ edx:eax = #TimeStamp
   ^ edx:eax = eax
   ^ edx:eax /= max
   ^ .if eax<0
   ^    ~edx
   ^ .endif
   ^ eax><edx
   return eax
}