How to use xor and and in SPARC assembly

-2
set 0xDEADBEEF, %o1 

set 0x13579246, %o2 

xor %o1, %o2, %o1 

What will be in register o1?

set 0xDEADBEEF, %o1 

set 0x13579246, %o2 

and %o1, %o2, %o1

What will be in register o1?

assembly
bit
sparc
asked on Stack Overflow Apr 25, 2013 by user2318744 • edited Jul 12, 2017 by StayOnTarget

1 Answer

0

CDFA2CA9 and 12059246 respectively, since both are bitwise operations, there is no architecture dependency here. see: http://en.wikibooks.org/wiki/SPARC_Assembly/Arithmetic_Instructions#Logic_Instructions

Regarding the actual calculation:

Note that:

0x0 == 0b0000
0x1 == 0b0001
0x2 == 0b0010
...
0xf == 0b1111

Since in bitwise operations, each digit in any base that is a power of 2 is independnt, it is simple to create a table for any base:

in base 2 (^ means xor, & means and):

& 0 1
0 0 0
1 0 1

^ 0 1
0 0 1
1 1 0

And in base 16 (hexadecimal):

and 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
0   0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
1   0   1   0   1   0   1   0   1   0   1   0   1   0   1   0   1
2   0   0   2   2   0   0   2   2   0   0   2   2   0   0   2   2
3   0   1   2   3   0   1   2   3   0   1   2   3   0   1   2   3
4   0   0   0   0   4   4   4   4   0   0   0   0   4   4   4   4
5   0   1   0   1   4   5   4   5   0   1   0   1   4   5   4   5
6   0   0   2   2   4   4   6   6   0   0   2   2   4   4   6   6
7   0   1   2   3   4   5   6   7   0   1   2   3   4   5   6   7
8   0   0   0   0   0   0   0   0   8   8   8   8   8   8   8   8
9   0   1   0   1   0   1   0   1   8   9   8   9   8   9   8   9
A   0   0   2   2   0   0   2   2   8   8   A   A   8   8   A   A
B   0   1   2   3   0   1   2   3   8   9   A   B   8   9   A   B
C   0   0   0   0   4   4   4   4   8   8   8   8   C   C   C   C
D   0   1   0   1   4   5   4   5   8   9   8   9   C   D   C   D
E   0   0   2   2   4   4   6   6   8   8   A   A   C   C   E   E
F   0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F

xor 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
0   0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
1   1   0   3   2   5   4   7   6   9   8   B   A   D   C   F   E
2   2   3   0   1   6   7   4   5   A   B   8   9   E   F   C   D
3   3   2   1   0   7   6   5   4   B   A   9   8   F   E   D   C
4   4   5   6   7   0   1   2   3   C   D   E   F   8   9   A   B
5   5   4   7   6   1   0   3   2   D   C   F   E   9   8   B   A
6   6   7   4   5   2   3   0   1   E   F   C   D   A   B   8   9
7   7   6   5   4   3   2   1   0   F   E   D   C   B   A   9   8
8   8   9   A   B   C   D   E   F   0   1   2   3   4   5   6   7
9   9   8   B   A   D   C   F   E   1   0   3   2   5   4   7   6
A   A   B   8   9   E   F   C   D   2   3   0   1   6   7   4   5
B   B   A   9   8   F   E   D   C   3   2   1   0   7   6   5   4
C   C   D   E   F   8   9   A   B   4   5   6   7   0   1   2   3
D   D   C   F   E   9   8   B   A   5   4   7   6   1   0   3   2
E   E   F   C   D   A   B   8   9   6   7   4   5   2   3   0   1
F   F   E   D   C   B   A   9   8   7   6   5   4   3   2   1   0

The first method means doing 32 very simple calculations (after a simple conversion to binary and then reconverting to hexadecimal), the second means doing 8 lookups in a table that you may or may not be able to prepare in advance.

answered on Stack Overflow Apr 25, 2013 by Ofir • edited Apr 25, 2013 by Ofir

User contributions licensed under CC BY-SA 3.0