Translating C to MIPS with a ternary operator

谁都会走 提交于 2019-12-13 07:35:26

问题


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]


来源:https://stackoverflow.com/questions/28160408/translating-c-to-mips-with-a-ternary-operator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!