in question, answers showed how possible make decisions without using "if" statements, suspect possible because "if" not statement generates jump
instructions.
given fixed compiled language (in example c++), can generated assembly kind of decisions without using jump
, goto
instructions?
please give example alternative simple if/else statement not use such instructions in case of affirmative answer.
the arm architecture has interesting conditional execution trait. running in full arm mode, every instruction can have condition attached it. these same conditions used on b
ranch instructions. instruction such add r0, r0, #15
execute, instruction such addeq r0, r0, #15
execute if 0 flag set. equivalent using branches be:
beq afteradd ; skip add if equal add r0, r0, #15 ; add 15 r0 afteradd:
when running on core uses thumb-2, conditional execution more limited, still possible using it
instruction. instruction create "if-then" construct without using branches. it
construct part of arm's unified assembly language, , should used whether you're writing arm or thumb-2. here's ual version of conditional add above.
it eq ; if equal addeq r0, r0, #15 ; add 15 r0
the it
construct can include more single instruction. using series of t
, e
in instruction, can add more conditional instructions. in below example, add 15 r0
if 0 flag set, otherwise subtract 15 r0
. ite
means, literally, if-then-else. first following instruction should have condition matches ite
condition, , second instruction become "else" , should have condition opposite of ite
condition.
ite eq ; if equal addeq r0, r0, #15 ; add 15 r0 subne r0, r0, #15 ; else subtract 15 r0
i guess kind of use if, may go against asking. in terms of execution, implements if without using jump, though.
Comments
Post a Comment