-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?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • If you have SPARC at your disposal, why can't you just try it? – mvp Apr 25 '13 at 08:12
  • I am sorry. I understand how to do it. My method of doing it, for example for XOR, convert both numbers to binary, then use the logic if both are 0 or if both are 1, put 0 and if either is different put 1 and create a new binary number, then convert it back to Hex But the problem with that is, I have to do it on a timed test and I do not think I have time to do all that and other questions. So I am looking for a faster way to do this – user2318744 Apr 25 '13 at 08:31
  • Just start Linux `gnome-calculator` or Windows `calc` in programmers mode and use `XOR` or `AND` buttons (I am sure Mac has something similar as well). – mvp Apr 25 '13 at 08:51
  • Can't use a calculator / computer on the test xDD – user2318744 Apr 25 '13 at 09:05
  • 1
    Then just work on it one hex digit at a time - I guess that's what you have been doing anyway. For example, `D xor 1` = `C`, `E xor 3` = `D`, ... – mvp Apr 25 '13 at 09:09
  • You have time... first off practice converting from a hex digit directly to binary in your head. So you don't have to look those up at the very least and I do mean going directly from C -> 1101 and so on. – cb88 Apr 30 '13 at 12:41

1 Answers1

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.

Ofir
  • 8,194
  • 2
  • 29
  • 44