flat assembler
Message board for the users of flat assembler.

Index > MenuetOS > macroinstructions library

Author
Thread Post new topic Reply to topic
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
what are you guys think about creating a VERY HUGE macroses library?
look at this and say something:

Code:
struc SystemColors {
 .frame       dd ?
 .grab        dd ?
 .grabBtnFace dd ?
 .grabBtnText dd ?
 .grabText    dd ?
 .work        dd ?
 .workBtnFace dd ?
 .workBtnText dd ?
 .workText    dd ?
 .workGraph   dd ?
}

macro mov reg,a1,a2 {
 if a2 eq
  mov reg,a1
 else
  mov reg,a1*65536+a2
 end if
}

macro add reg,a1,a2 {
 if a2 eq
  add reg,a1
 else
  add reg,a1*65536+a2
 end if
}

macro or reg,a1,a2 {
 if a2 eq
  or reg,a1
 else
  or reg,a1*65536+a2
 end if
}

macro BeginPaint {
 mov  eax,12
 mov  ebx,1
 int40
}

macro EndPaint {
 mov  eax,12
 mov  ebx,2
 int40
}

macro mov2 reg32,reg16,a1,a2 {
 if a1 eqtype 0
  if a2 eqtype 0
   if a1 <> -1
    if a2 <> -1
     mov  reg32,a1,a2
    else
     and  reg32,0x0000ffff
     or   reg32,a1,0
    end if
   else
    if a2 <> -1
     mov  reg16,a2
    end if
   end if
  else
   if a1 <> -1
    mov  reg32,a1,0
   end if
   if a2 eqtype []
    mov  reg16,word a2
   else
    mov  reg16,a2
   end if
  end if
 else
  if ~a2 eqtype 0 | a2 <> -1
   if a1 eqtype []
    mov  reg16,word a1
   else
    mov  reg16,a1
   end if
   shl  reg32,16
   if a2 eqtype []
    mov  reg16,word a2
   else
    mov  reg16,a2
   end if
  else
   push reg16
   if a1 eqtype []
    mov  reg16,word a1
   else
    mov  reg16,a1
   end if
   shl  reg32,16
   pop  reg16
  end if
 end if
}

macro DrawWindow wL,wT,wW,wH,dTP,dTL,dCB {
 xor  eax,eax
 mov2 ebx,bx,wL,wW
 mov2 ecx,cx,wT,wH
 mov  edx,[sc.work]
 or   edx,0x02000000
 mov  esi,[sc.grab]
 or   esi,0x80000000
 mov  edi,[sc.frame]
 int40
 if dTP eqtype 0 & dTP <> -1
  mov  eax,4
  mov  ebx,8,8
  mov  ecx,[sc.grabText]
  mov  edx,dTP
  mov  esi,dTL
  int40
 end if
 if ~dCB eq
  if dCB <> -1
   mov  eax,8
   mov  ebx,(wW-19),12
   mov  ecx,4,12
   mov  edx,dCB
   mov  esi,[sc.grabBtnFace]
   int40
  end if
 end if
}    


it works great for me but what can you say
Post 28 Dec 2003, 00:46
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Well, actually I don't think that inserting so big chunks of instructions and overloading instructions with macroses is a good programming style... It make the source too unclear and I try to avoid it where is possible.

Regards.
Post 28 Dec 2003, 19:10
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Ivan Poddubny



Joined: 21 Sep 2003
Posts: 32
Location: Yaroslavl, Russia
Ivan Poddubny
This is my macroses library.
Code:
; language for programs
lang equ ru ; ru en fr ge fi

; optimize the code for size
macro add arg1,arg2
{
   if arg1 in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
      if arg2 eqtype 0
         if arg2 = 1
            inc arg1
         else
            add arg1,arg2
         end if
      else
         add arg1,arg2
      end if
   else
      add arg1,arg2
   end if
}

macro sub arg1,arg2
{
   if arg2 eqtype 0
      if arg2 = 1
         dec arg1
      else
         sub arg1,arg2
      end if
   else
      sub arg1,arg2
   end if
}

macro mov arg1,arg2
{
   if arg1 in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
      if arg2 eqtype 0
         if arg2 = 0
            xor arg1,arg1
         else if arg2 = 1
            xor arg1,arg1
            inc arg1
         else if arg2 = -1
            or  arg1,-1
         else if arg2 > -128 & arg2 < 128
            push arg2
            pop  arg1
         else
            mov  arg1,arg2
         end if
      else
         mov arg1,arg2
      end if
   else
      mov arg1,arg2
   end if
}

; structures used in MeOS
struc process_information
{
  .cpu_usage               dd ?  ; +0
  .window_stack_position   dw ?  ; +4
  .window_stack_value      dw ?  ; +6
  .not_used1               dw ?  ; +8
  .process_name            rb 12 ; +10
  .memory_start            dd ?  ; +22
  .used_memory             dd ?  ; +26
  .PID                     dd ?  ; +30
  .x_start                 dd ?  ; +34
  .y_start                 dd ?  ; +38
  .x_size                  dd ?  ; +42
  .y_size                  dd ?  ; +46
  .slot_state              dw ?  ; +50
  rb (1024-52)
}

struc system_colors
{
  .frame            dd ?
  .grab             dd ?
  .grab_button      dd ?
  .grab_button_text dd ?
  .grab_text        dd ?
  .work             dd ?
  .work_button      dd ?
  .work_button_text dd ?
  .work_text        dd ?
  .work_graph       dd ?
}

macro debug_print [str]
{
   local string

   jmp @f
   string db str,0
  @@:

   pushad
   mov  edx,string
   call debug_outstr
   popad
}

if defined DEBUG
debug_outstr:
   mov  eax,63
   mov  ebx,1
 @@:
   mov  cl,[edx]
   test cl,cl
   jz   @f
   int  40h
   inc  edx
   jmp  @b
 @@:
   ret
end if
    
Post 29 Dec 2003, 08:01
View user's profile Send private message Visit poster's website Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
Macro's are great & can be used to make procedures easily
LABEL:
MACROm input1,input2
RET

macro's don't add size to an executable unless you use them.
I don't seem to have a memory problem with Fasm like Nasm gives.
I guess it's because Fasm is 70k with DMPI &
Nasm is 250k ?

Well commented code in macro's,
makes it easy to understand a month later & for others.
Post 19 Jan 2004, 13:50
View user's profile Send private message Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Here's two macros that i find kinda usefull
Code:
macro WMDispatch var, [msg] {
common       
    mov eax, var
forward
     cmp eax, msg
        je .#msg
}

macro HandleButtons var, [button] {
common
        mov     eax, var
    mov     edx, eax
    shr     edx, 16
     and     eax, 0FFFFh
 cmp edx,BN_CLICKED
  jne .skip
forward
        cmp eax, button
     je .#button
common
.skip:
}

;Example:
proc WndProc, .hWnd, .uMsg, .wParam, .lParam
enter
 WMDispatch [.uMsg], WM_PAINT, WM_COMMAND, WM_CREATE

.Default:
    invoke DefWindowProc, [.hWnd], [.uMsg], [.wParam], [.lParam]
        return
      
.WM_CREATE:
;        Initialisation code here
    jmp .Exit

.WM_PAINT:
;    Painting code here
  jmp .Exit
   
.WM_COMMAND:
        HandleButtons [.wParam], IDC_BTN1, IDC_BTN2, IDC_BTN3
       jmp .Default
        
    .IDC_BTN1:
;             Code to handle button click
         jmp .Exit
             
  .IDC_BTN2:
;             Code to handle button click
         jmp .Exit
           
    .IDC_BTN3:
;             Code to handle button click
         jmp .Exit

.Exit:
 xor eax, eax
return
    
Post 20 Jan 2004, 08:43
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 can attach files in this forum
You can download files in this forum


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

Website powered by rwasa.