flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > FOREACH macro from perl/awk |
Author |
|
Dima1205 06 Jul 2023, 22:18
Colleagues finally implemented the foreach cycle from perl. The syntax of perl is foreach elm (array). The macro code is built for my macro package, from this post.
Macro source: Code: macro _FOREACH arg { common item_arguemnt_foreach_size equ item_arguemnt_foreach equ ;Определяем если у нас ячейка памяти где и в каких случаях: match item_arguemnt_foreach1 (arr_main_value1),arg \{ item_arguemnt_foreach equ item_arguemnt_foreach1 testequ item_arguemnt_foreach_size,sizeof.,item_arguemnt_foreach1 arr_main_value equ arr_main_value1 \} match [item_arguemnt_foreach1] (arr_main_value1),arg \{ item_arguemnt_foreach equ item_arguemnt_foreach1 arr_main_value equ arr_main_value1 testequ item_arguemnt_foreach_size,sizeof.,item_arguemnt_foreach1 \} ;Т.к. константа размерности уже определена - переходим к заполнению данных: ;Переходим к формированию цикла ассемблированием: local ..endfor __ENDWHILE1 equ ..endforeach local ..FOREACH __WHILE1 equ ..FOREACH if item_arguemnt_foreach_size=sizeof.db if item_arguemnt_foreach eqtype ACC ;Нет идеи на регистр: mov item_arguemnt_foreach,BYTE arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [item_arguemnt_foreach] != 0 else mov al,BYTE arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [al] != 0 mov [item_arguemnt_foreach],BYTE end if else if item_arguemnt_foreach_size=sizeof.dw ;Используем регистр SI: if item_arguemnt_foreach eqtype ACC mov item_arguemnt_foreach,WORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [item_arguemnt_foreach] != 0 else mov RSI,WORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [ESI] != 0 mov [item_arguemnt_foreach],SI end if else if item_arguemnt_foreach_size=sizeof.dd if item_arguemnt_foreach eqtype ACC mov item_arguemnt_foreach,DWORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [item_arguemnt_foreach] != 0 else mov ESI,DWORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [ESI] != 0 mov [item_arguemnt_foreach],ESI end if else if item_arguemnt_foreach_size=sizeof.dq if item_arguemnt_foreach eqtype ACC mov item_arguemnt_foreach,QWORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [item_arguemnt_foreach] != 0 else mov RSI,QWORD arr_main_value __WHILE1: CheckedArgumentIF __ENDWHILE1,0,BYTE [ESI] != 0 mov [item_arguemnt_foreach],RSI end if end if } macro _ENDFOREACH { if item_arguemnt_foreach_size = 1 if item_arguemnt_foreach eqtype ACC inc item_arguemnt_foreach else inc al end if else if item_arguemnt_foreach eqtype ACC add item_arguemnt_foreach,item_arguemnt_foreach_size else if item_arguemnt_foreach_size=sizeof.dw add SI,item_arguemnt_foreach_size else if item_arguemnt_foreach_size=sizeof.dd add ESI,item_arguemnt_foreach_size else if item_arguemnt_foreach_size=sizeof.dq add RSI,item_arguemnt_foreach_size end if end if end if jmp __WHILE1 __ENDWHILE1: RESTORE __ENDWHILE1,__WHILE1,item_arguemnt_foreach,arr_main_value } The macro itself is already included in the delivery of the extended macro package . Sample Win32/Win64 foreach: Code: ; Foreach eaxmple format PE GUI 3.1 include 'Win32M.inc' ;format PE64 GUI 5.0 ;include 'Win64M.inc' struct CLIENT_ID UniqueProcess dd ? UniqueThread dd ? ends ; test2 dd 5 str_err db "",0 g_ClassName1 db "edit",0 test15 db 1 HANDLE TEST_buf1; EntryMain start TEST_buf1=capi malloc,MAX_PATH; capi GetLogicalDriveStringsA,MAX_PATH,TEST_buf1 GetCurrentDirectoryA(sizeof.CD,CD); capi MessageBoxA,0,CD,0,0 ;Примеры использования: ;_FOREACH test2 (TEST_buf1) _FOREACH [test2] (TEST_buf1) ;_FOREACH ESI (TEST_buf1) ;mov [test2],ESI MessageBoxA(0,[test2],[test2],0); _ENDFOREACH capi free,TEST_buf1 ExitProcess(0); proc test1,arg capi MessageBoxA,0,[arg],test3,0 ret test3 db 'test',0 endp CD rb MAX_PATH IMPORTTABLE _________________ Best regards, Dmitry |
|||
06 Jul 2023, 22:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.