flat assembler
Message board for the users of flat assembler.
Index
> Main > mutiple if conditions |
Author |
|
ProMiNick 21 Jul 2023, 06:17
there are many ways to do this, but because value.section_header.virtual_characteristics is a bit set we could scan it in loop
preserve esi,edi around Code: mov esi,1 ; initial value could be differ, for ex $20 or whatever with 1 bit set mov edi, [value.section_header.virtual_characteristics] loop: test edi,esi jne .skip bsr eax,esi push dword[characteristics+eax*4-4] call dword [printf] ; we live in 2023, console is a bit obsolete UI. could thou imagine console interface for example on smartphones? - unimaginable. .skip: ;test esi,$00000800 ; they could be not skipped but handled specialy ... ;jmp @F ;shl esi,8 ;, or skipped could be larger block of bits ;@@: shl esi,1 jnc loop Code: characteristics: ... ;00000001 ;00000002 ;00000004 ;00000008 ... ;00000010 dd ch_code ;00000020 dd ch_idata ;00000040 ... ;00000080 ;00000100 ;00000200 ;00000400 ;00000800 ;00001000 ;00002000 ;00004000 ;00000080 ;00010000 ;00020000 ;00040000 ;00080000 ;00100000 ;00200000 ;00400000 ;00800000 ;01000000 ;02000000 ;04000000 ;08000000 ... ;10000000 dd ch_exec ;20000000 dd ch_read ;40000000 dd ch_write ;80000000 Code: ch_code db ' .code. ',0 ch_idata db ' .initialized data. ',0 ch_exec db ' .executable. ',0 ch_read db ' .read. ',0 ch_write db ' .write. ',0 |
|||
21 Jul 2023, 06:17 |
|
revolution 21 Jul 2023, 08:16
Each check can be simplified with bt:
Code: characteristics_check: bt dword [value.section_header.virtual_characteristics],29 jnc .check_executable_done invoke printf, " .executable. " .check_executable_done: ;... |
|||
21 Jul 2023, 08:16 |
|
bitRAKE 21 Jul 2023, 15:25
The nice thing about BSF/BSR is the early exit, imho. If only one bit is set then there is no test for the others. ProMiNick's recommendation with minor change (just to show bit instructions working together):
Code: mov eax, [some_bit_flags] mov [.local_bits], eax .more_bits: bsf eax, [.local_bits] jz .done ; clear bit and respond to it being set btr [.local_bits], eax lea rcx, [some_bit_table] invoke printf, [rcx + rax*8] jmp .more_bits .done: * Happy 20 years to the board and me. One could say that BSR/BSF are bitRAKE's. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
21 Jul 2023, 15:25 |
|
Picnic 21 Jul 2023, 22:08
bitRAKE wrote: Happy 20 years to the board and me. bitRAKE, I admire your knowledge, style and attitude all these years on this forum. Sorry for the off-topic comment int0x50. just felt the need to write this. |
|||
21 Jul 2023, 22:08 |
|
AsmGuru62 22 Jul 2023, 01:42
FASM has .if/.endif macro extensions, so you would not need these labels.
|
|||
22 Jul 2023, 01:42 |
|
int0x50 24 Jul 2023, 14:23
@AsmGuru62 @Picnic @bitRAKE @revolution @ProMiNick
this really helps .. that's ok @Picnic .. i enjoy it ... |
|||
24 Jul 2023, 14:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.