Misunderstanding the c-language logical operator

I have such questions in my book that I do this to test myself, but I do not know the correct answer and there are no explanations.

it has two parts: "a" and "b"

a) A = B & C[0]
b) A = A ? B : C[0]

C[0]  = 0x00001234
A = 0x00000000
B = 0x00002222

he wants me to

1)what is the result of A 
2) the MIPS instruction for each part
3)show the bit level representation of each in structure.

thank

+3
source share
3 answers

& - bit I. And each output bit is 1 if both corresponding input bits are 1:

0x00001234 = .... 0001 0010 0011 0100
0x00002222 = .... 0010 0010 0010 0010

AND result = .... 0000 0010 0010 0000 = 0x00000220

I do not know MIPS, but the instruction is probably just called and.

? - : " A , B else return C [0]". , C false true ( 100%, - , , ),

  • A = 0x0000 then (bool) A == false, - C [0].
  • A = 0x0220 ( a), (bool) A == true, - B.
+3

& C. . 0000 0001 = 0000

? - if

A = A ? B : C[0]

, A value = ( A , B ELSE C [0])

Hex .

edit: : "AND" - - "- "

+2

mips:

a) A = B C [0]

$t1 = C

$t2 = B

$t3 = A

lw $t0, 0 ($ t1); c temp reg

$t3, $t0, $t2;

b) A = A? B: C [0]

$t1 = C

$t2 = B

$t3 = A

beq $0, $t3, 3, A 0, 3

$t3, $0, $t2; B A

j end,

lw $ t0, 0 ($ t1); load c to temp reg

add $ t3, $ 0, $ t0; move the temporary value to

end:

+1
source

Source: https://habr.com/ru/post/1777067/


All Articles