flat assembler
Message board for the users of flat assembler.
Index
> MenuetOS > macroinstructions library |
Author |
|
JohnFound 28 Dec 2003, 19:10
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. |
|||
28 Dec 2003, 19:10 |
|
Ivan Poddubny 29 Dec 2003, 08:01
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 |
|||
29 Dec 2003, 08:01 |
|
Bitdog 19 Jan 2004, 13:50
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. |
|||
19 Jan 2004, 13:50 |
|
aaro 20 Jan 2004, 08:43
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 |
|||
20 Jan 2004, 08:43 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.