flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > building operator tables |
Author |
|
bitRAKE 07 Dec 2010, 16:01
Why not create three separate tables with macro? Tables could be sorted and log(n) searchable - both pre-parse and post-parse tables.
|
|||
07 Dec 2010, 16:01 |
|
edemko 08 Dec 2010, 00:00
bitRAKE wrote:
three? could you name those? are you talking about table of pointers? bitRAKE wrote:
method1: but we never know a keyword coming method2(seems to be yours): is that picking keywords first? log(n), what is that? sorted by name, length? ... another variant of parsed text: store operators and operands in two lines id est commands and data i found the proc must take at least these params: text, char_lower_proc_pointer, temp1, temp2_possibly it will be great to: have some .tour variable so that you load byte from text and jmp [.tour]; so we get rid of some flags/modes(if mode=xxx then jmp there else there elsewhere nowhere...); we just jump into a .tour; but that way we are to form .tour, eh |
|||
08 Dec 2010, 00:00 |
|
bitRAKE 11 Dec 2010, 09:52
Proposed idea (or simpler):
Code: ;to find in parsed source db '<' db '>' ... ;to jump on match (dword not needed) dd .shl dd .shr ... ; to parse source (better ideas exist) db 3 db 'shl' db 3 db 'shr' ... When parsing source the last list is used to create an intermediate representation. Then the first list is used while processing the intermediate data. Maybe I am not fulling understanding the task? Last edited by bitRAKE on 12 Dec 2010, 03:03; edited 1 time in total |
|||
11 Dec 2010, 09:52 |
|
edemko 11 Dec 2010, 16:48
here below is a sample, demonstrating use of 3 elements table('operator',method)
bitRAKE was right - array sorting by operator name will speed the proc any 'operator',method params to the macro will be stored as Code: db sizeof.'operator' db 'operator' dd method ... db 0 parsed flow looks like: byte $01 if an operator is next byte $02 if a value is next byte '(' as is byte ')' as is byte 0 if end of flow that's all the proc is still able for on syntax error CF=1 else CF=0 on stage1 end, ie all is fine, HLT instruction occurs as stage2 is not ready stage2 will have to solve an expression, got from stage1 finding $01 in the flow, stage2 will call that method with CF=1 to know its priority, and CF=0 to perform arithmetic over values(after $02) such methods, so that, can be standalone procs of a general use as their call params seem to be equal tested and tired EDIT BY EDEMKO: ABOUT ~15KB OF AN OLD CODE DELETED YOUR PAGES TO BE LOADED QUICKLY Last edited by edemko on 18 Dec 2010, 01:18; edited 1 time in total |
|||
11 Dec 2010, 16:48 |
|
edemko 13 Dec 2010, 20:05
.stage1 update:
keys search more easy keys search supports user definitions(type 'hello' e.q.) text can be multi line .loop more easy and supports chose-able number separators replace this topic if it's a no more macro one EDIT BY EDEMKO: ABOUT ~15KB OF AN OLD CODE DELETED YOUR PAGES TO BE LOADED QUICKLY will bring Code: CPU Dump Address Hex dump ASCII 00401093 6D|65 74 68 6F|64 20 4D 45|54 48 4F 44| method METHOD 004010A3 20 6D 65 74|68 6F 64 0D|0A 4D 65 54|68 4F 64 00| method..MeThOd. 004010B3 01 43 41 4C|4C 46 4C 41|47 01 43 41|4C 4C 46 4C| CALLFLAGCALLFL 004010C3 41 47 01 43|41 4C 4C 46|4C 41 47 01|43 41 4C 4C| AGCALLFLAGCALL 004010D3 46 4C 41 47|00 00 00 00|00 FLAG..... Last edited by edemko on 18 Dec 2010, 01:20; edited 1 time in total |
|||
13 Dec 2010, 20:05 |
|
edemko 14 Dec 2010, 06:56
to navigate easily through data brought by .stage1, every element will take 9 bytes:
methods: db 1; dd method; dd method flags numbers: db 2; dq value braces: db '(' or ')'; dq ? hence Code: ... .char:stosb jmp .stage1 .no_key_found: ... will be Code: ... .char:stosb stosd stosd jmp .stage1 .no_key_found: ... also number fetching label will become nested proc, setting CF=1 on error - this will give "universal approach" for your procs guys |
|||
14 Dec 2010, 06:56 |
|
edemko 14 Dec 2010, 07:03
should '1d1b 0x65535$1' <- those numbers be allowed with no spaces between?
|
|||
14 Dec 2010, 07:03 |
|
bitRAKE 14 Dec 2010, 08:40
That is definitely a more universal approach.
How will errors be handled? For example, those that are detected in later stages? |
|||
14 Dec 2010, 08:40 |
|
edemko 14 Dec 2010, 10:15
bitRAKE:
i hope .stage2 will be final o)= of course, brace expressions will be calculated first searching for an operator with the biggest priority(flags), number of preceding and following values will be counted and only then an operator is called it will analise left and right params count, perform some actions with them, return CF=0 or CF=1 at last qword value it gives, will substitute all left, right params and the operator processed it may happen there will be values\params in braces only: ("1 2 3") or ("1b2d3h"); braces will be removed only -what are consecutive params for? -some instructions visualization -??? -psllw 1 2 3 4 5 6 7 8 ;i do not remember whether such an instro exists :) -??? -sure :) i wish seeing smth like too: bsr $654654654 bswap 0x45654 bsl $4552123 shrd 123h $123 11b shld ... ... ... etc |
|||
14 Dec 2010, 10:15 |
|
edemko 18 Dec 2010, 04:26
This post is replacing 3 previous !stupid ones.
The macro requires checking if method=0. In the archive attached you can see that none of the macro is 0. But fasm says those are. .stage2 is tested and ready. ADD method present only still. The proc designed the way to be easily plugged. Help me to solve operator ranges please. Propose yours. Propose your own complex methods. Should i keep big posts in CODE tags? Thank you. Replace this topic whenever a non-macro one. EDEMKO DELETED ATTACHMENT - THERE IS A NEWER ONE IN POSTS BELOW Last edited by edemko on 19 Dec 2010, 22:46; edited 1 time in total |
|||
18 Dec 2010, 04:26 |
|
edemko 19 Dec 2010, 22:38
hi
previous post with an intro to the proc was deleted as everything is located in an archive below that chunk... Code: jz .accept_method mov al,[eax+8] cmp al,[edi+8] ja .switch_element ...replaced with Code: jz .accept_method ;1st method mov al,[eax+5] ;\ cmp al,[edi+5] ;-priority control jae .switch_element ;/ the fix-up makes priorities be read correctly the fix-up makes executing methods left-to-right, not vice-versa, this disallows expressions of next form: "+-+-----+value etc" lots of (tested some) methods added, understanding int64 division is out of my mind for now, thus DIV and MOD absent: + - bsf, bsl bsr mul0 mul1 mul2 and or xor sar shl shr neg not 1/, rcp, reciprocal EDEMKO DELETED ATTACHMENT - THERE IS A NEWER ONE IN POSTS BELOW Last edited by edemko on 22 Dec 2010, 04:01; edited 1 time in total |
|||
19 Dec 2010, 22:38 |
|
edemko 20 Dec 2010, 16:27
replace original chunk with this one to support string integers in text: "12345678", "string", "etc", """":
Code: .char:stosb add edi,8 jmp .stage1 .no_key_found: lodsb cmp al,0 jz .exit_stage1 cmp al,9 je .stage1 cmp al,10 je .stage1 cmp al,13 je .stage1 cmp al,' ' je .stage1 cmp al,'"' ;gether quoted string into a number je .raw cmp al,'(' je .char cmp al,')' je .char mov ah,[.fasm_numbers] call .get_number jc .fail .raw_done: mov al,2 ;means number stosb mov eax,ebx ;number.lo stosd mov eax,ecx ;number.hi stosd jmp .stage1 .raw: xor ebx,ebx ;number.lo xor ecx,ecx ;number.hi mov ah,0 ;chars stored .raw_loop: lodsb cmp al,0 jz .fail ;'"' expected cmp al,'"' jne .raw_collect ;pick char lodsb ;\ cmp al,'"' ;-merge '""' into '"' jne .raw_done ;/ .raw_collect: inc ah cmp ah,8 ja .fail ;int64 overflow shld ecx,ebx,8 shl ebx,8 mov bl,al ;fasm compatible NOT masm etc jmp .raw_loop move this thread whenever a non-macro am i wrong: Code: macro generate_equates name,[key,method,flags]{ common label name local var1 forward virtual at 0 db key var1=$ if method=0 ;err ;Error: error directive invoked in source file. display 'nothing displayed, is it possible?' end if end virtual db var1,key dd method,flags common db 0 } plans: add byte, word, dword, sbyte, sword, sdword size specifiers to return results of desired type add mmx-using methods, that will be real fun, hi DOS386 hi the board |
|||
20 Dec 2010, 16:27 |
|
edemko 20 Dec 2010, 21:35
i beg your pardon for a wrong snippet, correct one
Code: .char:stosb add edi,8 jmp .stage1 .no_key_found: lodsb cmp al,0 jz .exit_stage1 cmp al,9 je .stage1 cmp al,10 je .stage1 cmp al,13 je .stage1 cmp al,' ' je .stage1 cmp al,'"' ;\ je .raw ; \gather quoted string into a number cmp al,"'" ; / je .raw ;/ cmp al,'(' je .char cmp al,')' je .char mov ah,[.fasm_numbers] call .get_number ;string to number jc .fail mov al,2 ;means number stosb mov eax,ebx ;number.lo stosd mov eax,ecx ;number.hi stosd jmp .stage1 .raw: xor ecx,ecx ;chars + end quote mov ah,al ;quote mov al,2 ;means number .raw_loop: stosb inc ecx cmp cl,9 ja .fail ;overflow lodsb cmp al,0 jz .fail ;missing end quote cmp al,ah jne .raw_loop ;gather number lodsb cmp al,ah jz .raw_loop ;"" -> " & '' -> ' & gather number dec esi ;switch behind number neg cl add cl,9 mov al,0 rep stosb ;pad number jmp .stage1 ;continue after end quote i use fasmw's calculator to check myself after compiling it(fasmcalc) refuses to calculate |
|||
20 Dec 2010, 21:35 |
|
edemko 21 Dec 2010, 03:30
methods update
being asleep 1 mmx added only feel free putting new ones it seems i'm finished thanks Code: generate_equates equates,\ 'packuswb' ,.packuswb ,0 ,\ \ '+' ,.add ,0 ,\ '-' ,.sub ,0 ,\ 'bsf' ,.bsl ,0 ,\ 'bsl' ,.bsl ,0 ,\ 'bsr' ,.bsr ,0 ,\ 'byte' ,.byte ,0 ,\ 'sbyte' ,.sbyte ,0 ,\ 'word' ,.word ,0 ,\ 'sword' ,.sword ,0 ,\ 'dword' ,.dword ,0 ,\ 'sdword' ,.sdword ,0 ,\ \ 'mul0' ,.mul0 ,1 ,\ 'mul1' ,.mul1 ,1 ,\ 'mul2' ,.mul2 ,1 ,\ \ 'and' ,.and ,3 ,\ 'or' ,.or ,3 ,\ 'xor' ,.xor ,3 ,\ \ 'sar' ,.sar ,4 ,\ 'shl' ,.shl ,4 ,\ 'shr' ,.shr ,4 ,\ 'shld' ,.shld ,4 ,\ 'shrd' ,.shrd ,4 ,\ 'shlq' ,.shlq ,4 ,\ 'shrq' ,.shrq ,4 ,\ \ 'neg' ,.neg ,5 ,\ 'not' ,.not ,5 ,\ '1/' ,.rcp ,5 ,\ 'rcp' ,.rcp ,5 ,\ 'reciprocal' ,.rcp ,5 ;,\ EDEMKO DELETED ATTACHMENT - THERE IS A NEWER ONE IN POSTS BELOW Last edited by edemko on 22 Dec 2010, 04:03; edited 1 time in total |
|||
21 Dec 2010, 03:30 |
|
edemko 22 Dec 2010, 03:54
myself wrote:
i could not stand :) Code: macro generate_equates name,[key,method,flags]{ common label name local var1 forward virtual at 0 db key var1=$ if method=0 ;err ;Error: error directive invoked in source file. display 'nothing displayed, is it possible?' end if end virtual db var1,key dd method,flags common db 0 } generate_equates equates,\ \;mmx-instructions 'movd' ,.movd ,0 ,\ 'movq' ,.movq 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.bsl ,0 ,\ 'bsr' ,.bsr ,0 ,\ 'byte' ,.byte ,0 ,\ 'sbyte' ,.sbyte ,0 ,\ 'word' ,.word ,0 ,\ 'sword' ,.sword ,0 ,\ 'dword' ,.dword ,0 ,\ 'sdword' ,.sdword ,0 ,\ \ 'mul0' ,.mul0 ,1 ,\ 'mul1' ,.mul1 ,1 ,\ 'mul2' ,.mul2 ,1 ,\ \ 'and' ,.and ,3 ,\ 'or' ,.or ,3 ,\ 'xor' ,.xor ,3 ,\ \ 'sar' ,.sar ,4 ,\ 'shl' ,.shl ,4 ,\ 'shr' ,.shr ,4 ,\ 'shld' ,.shld ,4 ,\ 'shrd' ,.shrd ,4 ,\ 'shlq' ,.shlq ,4 ,\ 'shrq' ,.shrq ,4 ,\ \ 'neg' ,.neg ,5 ,\ 'not' ,.not ,5 ,\ '1/' ,.rcp ,5 ,\ 'rcp' ,.rcp ,5 ,\ 'reciprocal' ,.rcp ,5 ;,\ ; form: value mmx-command value .mmx_in:cmp eax,1 jne .mmx_in_nok cmp ebx,eax jne .mmx_in_nok add edi,9 mov al,2 stosb movq mm0,[edi] ret 0 .mmx_in_nok: pop eax stc ret 0 .mmx_out: movq [edi],mm0 add edi,8 clc ret 0 macro mmx [instro]{ forward label .#instro call .mmx_in instro mm0,[ecx+9+1] jmp .mmx_out } mmx movd ,\ movq ,\ packssdw ,\ packsswb ,\ packuswb ,\ paddb ,\ paddd ,\ paddsb ,\ paddsw ,\ paddusb ,\ paddusw ,\ paddw ,\ pand ,\ pandn ,\ pcmpeqb ,\ pcmpeqd ,\ pcmpeqw ,\ pcmpgtb ,\ pcmpgtd ,\ pcmpgtw ,\ pmaddwd ,\ pmulhw ,\ pmullw ,\ por ,\ pslld ,\ psllq ,\ psllw ,\ psrld ,\ psrlq ,\ psrlw ,\ psubb ,\ psubd ,\ psubsb ,\ psubsw ,\ psubusb ,\ psubusw ,\ psubw ,\ punpckhbw ,\ punpckhdq ,\ punpckhwd ,\ punpcklbw ,\ punpckldq ,\ punpcklwd ,\ pxor purge mmx
|
|||||||||||
22 Dec 2010, 03:54 |
|
edemko 23 Dec 2010, 19:13
hi
i found a bug in a get_number proc, which made me removing xxh numbers support(that's clocky) reading raw(string) values is this proc's job now main proc(calc) can count in direct and reversed modes it can also dump result to string the simplest form used ie. full-ecx dump(not until zero) hence mmx-commands' result look pretty there is a small shell inside an archive attached to this post http://fasmme.googlecode.com/files/calc.zip |
|||
23 Dec 2010, 19:13 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.