Translating C to MIPS with a ternary operator

2019-09-03 15:49发布

问题:

In my class we are translating C to MIPS.

We are asked to translate this snippet: A = A ? B : C[0]

I believe I understand the ternary operator, but what is wanted here? Shouldn't A be a boolean? So would it be represented in MIPS with a 1 or 0 value?

Thank you

回答1:

It might help to translate the ternary expression to pseudo code first, e.g.:

if A != 0       // if A is non-zero, i.e. TRUE
    A = B
else            // otherwise A is zero, i.e. FALSE
    A = C[0]


标签: c mips translate