flat assembler
Message board for the users of flat assembler.

Index > Main > how do i set flag?

Author
Thread Post new topic Reply to topic
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox
1. how do i set flags in FL register?
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
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.
Post 18 May 2008, 02:11
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
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 Very Happy
Post 18 May 2008, 10:23
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
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).
Post 18 May 2008, 10:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
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 x86-32 is nativelly a 32 bits architecture, then, 32 bits instructions on 32 bits register is supposed to be faster that 8 and 16 bits.
Post 18 May 2008, 10:47
View user's profile Send private message Visit poster's website Reply with quote
dap



Joined: 01 Dec 2007
Posts: 61
Location: Belgium
dap
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.

_________________
(French only) http://dap.developpez.com
Post 18 May 2008, 10:51
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3056
Location: vpcmipstrm
bitRAKE
asmrox wrote:
2. how do i set 'bits'.
x86 also supports bit strings.

; 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)*(P-1)/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:    

_________________
¯\(°_o)/¯ unlicense.org
Post 18 May 2008, 14:23
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
vid wrote:
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:


You forgot "clc", "stc", "cmc" (clear, set, complement carry flag). Wink
Post 24 May 2008, 21:01
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.