flat assembler
Message board for the users of flat assembler.
Index
> Main > Boolean Logic Instructions 
Author 

DJ Mauretto
hello
for each logic function, at least initially you have to write a table of truth ' Code: 0 and 0 = 0 0 and 1 = 0 1 and 0 = 0 1 and 1 = 1 _________________ Nil Volentibus Arduum 

24 Jun 2011, 13:16 

DJ Mauretto
Quote: 5 or 3 = 7 Sad Why ? It's like x+y1 Code: 0 or 0 = 0 0 or 1 = 1 1 or 0 = 1 1 or 1 = 1 5 = 101 3 = 011 5 or 3 = 101 or 011 = 111 ( 7 ) _________________ Nil Volentibus Arduum 

24 Jun 2011, 13:21 

Overflowz
Ohh, I guess I should work with binary numbers only.. I asked this question because I saw many programs were using something like "and eax,ebx" where EAX and EBX were more than 0 or 1.. but I don't know what they wanted to do. Thanks..


24 Jun 2011, 14:05 

garystampa
You should be thinking about bits and not decimal numbers.
OR and AND aren't really for operating on numbers per se, although they can be... If you want an index to wrap around a buffer you might make the buffer 7f+1 in length. Then you can increment the index and AND it with 7f to make sure it's always in range. ORing is often used to turn bits on. ANDing is often used to turn them off. I have never found a use for ORing decimal numbers for the sake of creating a new decimal number. XOR is also useful. You can test for an odd or even number by testing the lowest bit with AND: if (x & 1) odd! else even! test ax,1 jnz odd jz even 

25 Jun 2011, 03:42 

idle
i'd never guess what Agner meant:
Code: [Find minimum of two unsigned values] [Assembler][/][8086] This small gem show how you can find the minimum of two unsigned numbers: if (b < a) a = b; The approach used here does not use any branches which may mess up your BTB (Branch Target Buffer) ; ; Find minimum of two unsigned values ; ; input: ; eax = value a ; ebx = value b ; ; output: ; eax = smallest value ; ; destroys: ; ebx, ecx ; flags ; sub ebx,eax sbb ecx,ecx and ecx,ebx add eax,ecx You can use this gem on 16 bit machines too, just use 16 bit registers. This gem comes from Agner Fog's Pentium optimization manual. Be sure to get this manual. Gem writer: Agner Fog last updated: 19980316 

25 Jun 2011, 06:12 

Madis731
If it was a question, I will post an answer:
Code: ; Variant A: EAX > EBX i.e. 7 and 5 sub ebx,eax ; 57=2 sbb ecx,ecx ; carry flag was raised: ecxecx1=1 (0FFFFFFFFh) and ecx,ebx ; ecx=ebx because 0FFFFFFFFh & 2 = 2 (0FFFFFFFEh) add eax,ecx ; 7+(2)=5 ;EAX = 5 (5 < 7) ; Variant B: EAX < EBX i.e. 4 and 8 sub ebx,eax ; 84=4 sbb ecx,ecx ; carry flag not set: ecxecx0=0 and ecx,ebx ; ecx=0 because 0 & 4 = 0 add eax,ecx ; 4+0=4 ;EAX = 4 (4 < I provide a simpler example: Code: cmp eax,ebx cmovg eax,ebx ; conditional mov is relatively old (P6). It acted slowly on some AMD64 CPUs. I think its okay to use it today. ;One can use cmova if unsigned operation is needed. ;EAX = MIN(EAX,EBX) 

27 Jun 2011, 11:40 

< Last Thread  Next Thread > 
Forum Rules:

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