Cleaning BSS in ARMv8-A

I am trying to write good and basic 'cleaning bss' code for my bootloader but AI's arguing me and I don't know what to do..

My code is this:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ldr x2, =__bss_start
    ldr x3, =__bss_size

    cbz x3, start_main
    udiv x3, x3, #8
    mul x4, x3, #8
    sub x5, __bss_size, x4

clear_bss:
    cbz x3, check_remainder
    str xzr, [x2], #8
    sub x3, x3, #1
    cbnz x3 clear_bss
check_remainder:
    cbz x5, start_main
    str xzr, [x2], #1
    cbnz x5, check_remainder
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
But AI's forcing me to write instead of it:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ldr x2, =__bss_start
    ldr x3, =__bss_size
    cbz x3, start_main

clear_bss:
    str xzr, [x2], #8
    sub x3, x3, #1
    cbnz x3, clear_bss

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

They say my code sucks, so complex and their code is basic and optimised.
What should I do??___###

Okay, Im reporting my question. I just write a question and think about it, update things and someone reports it..



  • ChatGPT is offering me different solutions, making mistakes and just updating 1 line for every iteration (my long question)
    I'm feeling really crazy

    we have 9 bytes for clean.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    chatGPT_cleaning:


    cmp x3, #8

    blt there_is_a_remainder

    clean_aggressively:

    str xzr, [x2], #8
    sub x3, x3, #8

    cbz x3, cleaning_done

    b clean_aggressively

    there_is_a_remainder:

    cbz x3, cleaning_done

    str xzr, [x2], #1

    sub x3, x3, #1

    b there_is_a_remainder


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    -> Cleaned 8 bytes of 9 bytes.
    -> Cleaned 8 bytes of 1 bytes. ???What happens here, code is clean 8 bytes but gpt says if there is a 8x+k for x =0, it cleans just k???


    Or it really cleans 8 bytes of 1 bytes, some hotel rooms are raided?

    Maybe we can use a security prosedure, adding an extra 8 bytes to end of the bss section. So we don't have to calculate remainders.

    continue:
    str xzr, [x2], #8
    sub x3, x3, #8
    cbnz x3, continue

    But now the problem is negative values of size on x3 register.
    Uhh...

    I'll write an article about this problem..

    As a real engineer, please comment and write some advise, what should I do exactly?
    I think my first code improved to two functions (one is for big size values and other one is smalls) is the answer just now, I don't know....