flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro calc dest, expr

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
Code:
include 'extend/calc32.inc'
use32
calc eax, (3+5)+eax    
will go into
Code:
:00000000 6A03                    push 00000003
:00000002 6A05                    push 00000005
:00000004 58                      pop eax
:00000005 010424                  add dword ptr [esp], eax
:00000008 50                      push eax
:00000009 58                      pop eax
:0000000A 010424                  add dword ptr [esp], eax
:0000000D 58                      pop eax    
to make more optimize Smile
Post 16 Apr 2016, 16:24
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
Code:
include 'CDStack.INC'
cnt = 0
macro calc dst, exp{
 if 1>2 ;exp eqtype 0
  mov dst, dword exp
 else
  local push_p, c1, c2
  macro push_p x& \{
    local t
    virtual at -8
      x
      db 8 dup 0
      load t qword from -8
      t = t or (1 shl ($*8))
      push_c c1, t and $ffffffff
      push_c c2, t shr 32
    end virtual
  \}

  local r, s, L, T, t1, t2, t0, lst, matched, endl
  stackinit r, 1000  ;rank
  push_c r, -3
  push_c r, -1
  stackinit s, 1000  ;symbols
  push_c s, 0
  push_c s, 0
  stackinit c1, 1000
  stackinit c2, 1000
  L = 0
  T equ 0
  lst equ []
  irps x , exp endl\{
    match =0, T \\{
      matched = 0
      match =+, x \\\{
        matched = 1          ; t1=odd  ->
        t1 = 1+L             ; t1=even <-
        match =[], lst \\\\{ matched = 11
                            t1 = 6\\\\}
        match =(, lst \\\\{ matched = 11
                            t1 = 6\\\\}
      \\\}
      match =-, x \\\{
        t1 = 1+L
        matched = 2
        match =[], lst \\\\{ matched = 12
                            t1 = 6\\\\}
        match =(, lst \\\\{ matched = 12
                            t1 = 6\\\\}
      \\\}
      match =*, x \\\{
        matched = 3
        t1 = 3+L
      \\\}
      match =/, x \\\{
        matched = 4
        t1 = 3+L
      \\\}
      match =%, x \\\{
        matched = 5
        t1 = 3+L
      \\\}
      if endl eq x
        matched = 19
        t1 = -2
      end if
      match =(, x \\\{
        matched = -1
        L = L + 100
      \\\}
      match =), x \\\{
        matched = -1
        L = L - 100
      \\\}
      match =[, x \\\{
        matched = -1
        T equ 1
        t0 equ
      \\\}
      if matched < 0
      else if matched > 0
        while 1<2
          top_cs r, t2
          if t2<t1 | (t2=t1 & t1 mod 2 = 0)
            break
          end if
          if cnt>100
            break
          end if
          cnt = cnt+1
          pop_cs r
          pop_cs s, t2
          if t2 = 1
            push_p rept 1\\\{pop eax\\\} add [esp], eax
          else if t2 = 2
            push_p rept 1\\\{pop eax\\\} sub [esp], eax
          else if t2 = 3
            push_p rept 1\\\{pop eax\\\} rept 1\\\{mul dword [esp]\\\} mov [esp], eax
          else if t2 = 4
            push_p rept 1\\\{pop ecx eax\\\} rept 1\\\{xor edx, edx\\\} rept 1\\\{div ecx\\\} push eax
          else if t2 = 5
            push_p rept 1\\\{pop ecx eax\\\} rept 1\\\{xor edx, edx\\\} rept 1\\\{div ecx\\\} push edx
          else if t2 = 11
            ;nop
          else if t2 = 12
            push_p neg dword [esp]
          end if
        end while
        push_c r, t1
        push_c s, matched
      else if x eqtype 0 | x eqtype eax
        push_p push x
      end if
    \\}
    match =1, T \\{
      t0 equ t0 x
      match ], x \\\{
        push_p push dword t0
        T equ 0
      \\\}
    \\}
    lst equ x
  \}
  load matched dword from c1:-4
  repeat matched
    load t1 dword from c1:%*4-4
    load t2 dword from c2:%*4-4
    t1 = t1 + (t2 shl 32)
    while t1>1
      db t1 and 255
      t1 = t1 shr 8
    end while
  end repeat
  pop dword dst
 end if
}    
push_c pushs a value to the stack, pop_c pops one, top_c get the top, pop_cs pop one with sign
Post 17 Apr 2016, 02:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.