flat assembler
Message board for the users of flat assembler.

Index > Main > emulating bitwise op in sw

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 718
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.

on top of my head:
- 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
Post 02 Feb 2023, 05:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
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.
Post 02 Feb 2023, 05:18
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 952
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.
Post 02 Feb 2023, 07:24
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2504
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.
Post 02 Feb 2023, 14:49
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 952
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.
Post 02 Feb 2023, 18:41
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.