Implementing a flow “(1) if {…} else if {…} … (2)” in Assembly

前端 未结 2 986
北荒
北荒 2021-01-27 15:18

I have the following flow in C:

// some stuff1
//................


if (something1) {
    func1();
    func2();
} else if (something2) {
    func3();
    func4()         


        
2条回答
  •  醉酒成梦
    2021-01-27 15:33

    As i see it you have two options:

    1. Use functions like you said. then all you need to do is call func. the advantage is readability and more slick code as well as automatic jump back to where you called the function, but it will cost you the overhead of using a function (setting up the registers and pushing and popping the stack pointer).
    2. Use labels. this is straightforward. But you will need to declare a label for getting back to the function, or save the return address somewhere, which affects readability.

    Anyway your conditional piece of code :

    cmp [some_struc], SOME_CONST2 
    

    seems OK.

提交回复
热议问题