flat assembler
Message board for the users of flat assembler.
Index
> Main > how do i set flag? 
Author 

DJ Mauretto 18 May 2008, 10:23
Quote: 1. how do i set flags in FL register? There is SAHF instruction (Store AH into Flags), or you can manipulate the stack with PUSHF  POPF instruction. Quote: 2. how do i set 'bits'. Register (al) has 8 bits, and i wana use 1 of them to make bool variable. Set it, and check it after it OR instruction to set bit ,TEST instruction to check, INTEL MANUALS for LEARN 

18 May 2008, 10:23 

vid 18 May 2008, 10:27
Quote: 1. how do i set flags in FL register? by FL, i quess you mean flags. Some bits can be set directly ("sti", "cld", "stc", ...), for others you must do this: Code: pushf pop eax ;ax in 16bit mode ;now set bits in EAX push eax popf Quote: 2. how do i set 'bits'. Register (al) has 8 bits, and i wana use 1 of them to make bool variable. Set it, and check it after it prior to 386 you used "or" to set bit, "and" to clear bit, and "xor" to flip bit: Code: or eax, 1 shl 5 ;set bit 5 of eax and eax, not (1 shl 5) ;clear bit 5 of eax xor eax, 1 shl 5 ;flip bit 5 of eax since 386, you have "bt", "btr", "bts" and "btc" instructions, which are bit easier to use (pun intended). 

18 May 2008, 10:27 

edfed 18 May 2008, 10:47
Quote: 3. what is faster? operations on 32 bit registers, or 8? logically, when i loop smth 255 times, using al is faster than eax. But ppl say many things. 32 bits is faster that 8bit. whith 32 bits, your 8 bits loop can be divided byt 4. then, it is up to 4 times faster. and x8632 is nativelly a 32 bits architecture, then, 32 bits instructions on 32 bits register is supposed to be faster that 8 and 16 bits. 

18 May 2008, 10:47 

dap 18 May 2008, 10:51
It's better to use full 32 bits register because there is much more chance that the processor will be able to rename them efficiently.


18 May 2008, 10:51 

bitRAKE 18 May 2008, 14:23
asmrox wrote: 2. how do i set 'bits'. ; all of these put the bit value in the carry flag: BT eax,5 ; do not change bit BTR eax,5 ; reset bit to zero BTS eax,5 ; set bit to one BTC eac,5 ; compliment bit ; they work with memory and arbitrary bit number (>31!), too! (very powerful, imho) BT [esi],ecx Prime sieve in only a dozen instructions: Code: mov edi,sieve xor ecx,ecx .0: bt [edi],ecx inc ecx jnc .0 ; ECX*2 + 1 is prime number (P) lea eax,[ecx*2+2] mul ecx ; (P+1)*(P1)/2 dec eax ; exit if out of range cmp eax,MAX_BITS jnc .x ; clear bits representing odd multiples of (P) .1: btr [edi],eax lea eax,[eax+ecx*2+1] cmp eax,MAX_BITS jc .1 jmp .0 MAX_BITS = 1 shl 24 ; if bit(n) then (2*n+3) is prime sieve db MAX_BITS/8 dup (1) .x: 

18 May 2008, 14:23 

rugxulo 24 May 2008, 21:01
vid wrote:
You forgot "clc", "stc", "cmc" (clear, set, complement carry flag). 

24 May 2008, 21:01 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.