case H_FOR:
compile_expression();
/* We will loop back to the conditional */
gen_label("_l", h.h_name);
/* A blank conditional on the for is a C oddity and means 'always true' */
if (compile_expression() != VOID) {
/* Exit the loop if false */
gen_jfalse("_b", h.h_name);
}
/* Jump top the main body if not */
gen_jump("_n", h.h_name);
This will output the following code:
In most cases, the update part is small and the body is large. Therefore, jeq is expanded to 5 bytes (bne + jmp).
If changing jeq to jne and switch the jmp and destination, It can reduce the number of unnecessary jmps.
L29_l: ;; condition
tsx
ldb 1,x
cmpb #8
jsr boollt
jeq L29_b
jmp L29_n
L29_c: ;; update
tsx
inc 1,x
;
jmp L29_l
L29_n: ;; body
:
:
L29_b: ;; end of body
backend.c, which processes the for statement:
This will output the following code:
In most cases, the update part is small and the body is large. Therefore, jeq is expanded to 5 bytes (bne + jmp). If changing jeq to jne and switch the jmp and destination, It can reduce the number of unnecessary jmps.