flat assembler
Message board for the users of flat assembler.

 Index > Main > emulating bitwise op in sw
Author
Ali.Z

Joined: 08 Jan 2018
Posts: 689
Ali.Z 02 Feb 2023, 05:07
this is an open discussion, a question pop'ed in my head is how many bitwise operations can be emulated in software.

- shl a simple shl by 1 can be done by multiplying by 2
- shr can be done with div
- and may also be done with div by taking the remainder

the thing here is to count how many instructions can be emulated using non-bitwise operations; things that may not be possible are (i think) rcr/l ror/l, other stuff may need complex operations like rising to n power of so..

_________________
Asm For Wise Humans
02 Feb 2023, 05:07
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20246
revolution 02 Feb 2023, 05:18
You can do everything you need with just one instruction.

https://en.wikipedia.org/wiki/One_instruction_set_computer?useskin=vector

The only problem you have is choosing which instruction you like the most. There are many options.
02 Feb 2023, 05:18
macomics

Joined: 26 Jan 2021
Posts: 922
Location: Russia
macomics 02 Feb 2023, 07:24
Ali.Z wrote:
how many bitwise operations can be emulated in software.
Then think about the fact that computer technology is entirely built of transistors and logic signals. From which it follows that all instructions in the processor are implemented using logical operations.

Of course, reverse operations can also be performed using non-bit instructions. To begin with, try to express all 16 bit functions from two arguments through mathematical operations.
02 Feb 2023, 07:24
Furs

Joined: 04 Mar 2016
Posts: 2475
Furs 02 Feb 2023, 14:49
macomics wrote:
Of course, reverse operations can also be performed using non-bit instructions. To begin with, try to express all 16 bit functions from two arguments through mathematical operations.
Yeah, you don't even need to rely on gimmicks like fixed-width registers. The simplest case is that you can isolate single bits with modulus and shift them with multiplications.
02 Feb 2023, 14:49
macomics

Joined: 26 Jan 2021
Posts: 922
Location: Russia
macomics 02 Feb 2023, 18:41
Furs wrote:
Yeah, you don't even need to rely on gimmicks like fixed-width registers.
I didn't write about functions for fixed-length bit sequences. Logical functions for two bit variables were meant. There are 16 variants in total
Code:
```x y f(x,y)

CONST(0) = mov edx, 0/mul edx
0 0 0
0 1 0
1 0 0
1 1 0

AND
0 0 0
0 1 0
1 0 0
1 1 1

0 0 0
0 1 0
1 0 1
1 1 0

0 0 0
0 1 0
1 0 1
1 1 1

0 0 0
0 1 1
1 0 0
1 1 0

0 0 0
0 1 1
1 0 0
1 1 1

XOR
0 0 0
0 1 1
1 0 1
1 1 0

OR
0 0 0
0 1 1
1 0 1
1 1 1

0 0 1
0 1 0
1 0 0
1 1 0

0 0 1
0 1 0
1 0 0
1 1 1

0 0 1
0 1 0
1 0 1
1 1 0

0 0 1
0 1 0
1 0 1
1 1 1

0 0 1
0 1 1
1 0 0
1 1 0

0 0 1
0 1 1
1 0 0
1 1 1

0 0 1
0 1 1
1 0 1
1 1 0

CONST(1) = mov edx, 0/div eax/neg eax
0 0 1
0 1 1
1 0 1
1 1 1    ```
I will not list all the names. Only those for which there are abbreviations.
02 Feb 2023, 18:41
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum