Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

On the MC6800, it is better to reverse the order of branches in a for statement. #173

@zu2

Description

@zu2

backend.c, which processes the for statement:

      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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions