Reputation: 27
I have this simple code in assembly:
1000 Add R3,R2,#20
1004 Susbtract R5,R4,#3
1008 And R6,R3,#0x3A
1012 Add R7,R2,R4
My question is what does the "And" do... I am really confused about it, I am doing my homework and I'm stuck.
Thank you so much.
Upvotes: 0
Views: 247
Reputation: 25695
0x3A = 00111010b
for an 8bit machine. That looks like a 64 bit machine, so prepend 56 zeros to that.
It will mask all the bits of the number in R3 except [starts from 0](1st, 3rd, 4th, 5th and 6th) starting from right. All other bits will be nullified and stored in R6
For example if R3 contains 0x5848 then, (0x5848 (and) 0x3A) = 0x08 (will be stored in R6 register)
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0101 1000 0100 1000
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0011 1010 (AND)
--------------------------------------------------------------------------------------
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000
--------------------------------------------------------------------------------------
The truth table for AND operation =
A B A(and)B
-----------------
0 | 0 | 0
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1
-----------------
Upvotes: 0
Reputation: 490018
It does a bitwise and
between the two source operands, and puts the result in the destination operand. To visualize the result in detail, convert each number to binary, then do the and
. For example, if R0 = 0x1234 and R1 = 0x8765, then:
R0 = 0x1234 = 0001 0010 0011 0100
R1 = 0x8765 = 1000 0111 0110 0101
Result = 0000 0010 0010 0100
Hex result = 0x0224
I.e., each bit in the result is a 1
if and only if the bits in that position in both input operands are 1's.
Upvotes: 4