Study this disassembled code, I have written exactly how the function works in the comments behind.
Disclaimer: this is the Philadot Mbox code, so all adresses below are ONLY for that ecu and need to be replaced with your own. But it can help you understand what you are writing.
LC:
seg018:E800 jnb word_FD56.8, loc_8E82A ;if b_kuppl is not set, jump to NLS
seg018:E804 mov r4, word_8E40 ;move vfil_w to r4
seg018:E808 exts #81h, #1
seg018:E80C mov r9, 7E00h ;move speed_threshold to r9
seg018:E810 cmp r4, r9 ;compare r4 to r9
seg018:E812 jmpr cc_NC, loc_8E82A ;jump to NLS if vfil_w is larger than speed_threshold
seg018:E814 mov r4, word_F87A ;move nmot_w to r4
seg018:E818 exts #81h, #1
seg018:E81C mov r9, 7E02h ;move launch rpm to r9
seg018:E820 cmp r4, r9 ;compare r4 to r9
seg018:E822 jmpr cc_ULE, loc_8E82A ;jump to EXIT if rpm is less or equal to launch_rpm
seg018:E824 movb byte_8DAC, ZEROS ;zeros tsrldyn (interrupt spark)
seg018:E828 jmpr cc_UC, loc_8E888 ;jump to EXIT unconditionally
NLS:
seg018:E82A loc_8E82A:
seg018:E82A
seg018:E82A jnb word_FD56.8, loc_8E880 ;if b_kuppl is not set, jump to UNSET RAMCOUNTER
seg018:E82E jb word_FD56.6, loc_8E876 ;if b_br is set, jump to SET RAMCOUNTER
seg018:E832 mov r4, word_F87A ;move nmot_w to r4
seg018:E836 exts #81h, #1
seg018:E83A mov r9, 7E06h ;move rmp threshold to r9
seg018:E83E cmp r4, r9 ;compare r4 to r9
seg018:E840 jmpr cc_ULE, loc_8E876 ;jump to SET RAMCOUNTER if rpm is less or equal to rpm_threshold
seg018:E842 movbz r4, byte_8B02 ;move wped to r4
seg018:E846 exts #81h, #1
seg018:E84A movbz r9, 7E08h ;move pedal_threshold to r9
seg018:E84E cmp r4, r9 ;compare r4 to r9
seg018:E850 jmpr cc_ULE, loc_8E876 ;jump to SET RAMCOUNTER if wped is less or equal to pedal_threshold
seg018:E852 exts #38h, #1
seg018:E856 mov r4, 4FF0h ;move ramcounter to r4
seg018:E85A exts #81h, #1
seg018:E85E mov r9, 7E04h ;move cut_duration to r9
seg018:E862 cmp r4, r9 ;compare r4 to r9
seg018:E864 jmpr cc_NC, loc_8E888 ;jump to EXIT if no carry (ramcounter value is larger than cut_duration)
seg018:E866 movb byte_8DAC, ZEROS ;zeros tsrldyn
seg018:E86A add r4, #1 ;add 1 to r4 (increments ramcounter value with 1)
seg018:E86C exts #38h, #1
seg018:E870 movb 4FF0h, rl4 ;move rl4 to ramcounter
seg018:E874 jmpr cc_UC, loc_8E888 ;jump to EXIT unconditionally
SET RAMCOUNTER:
seg018:E876 loc_8E876:
seg018:E876
seg018:E876 exts #38h, #1
seg018:E87A mov 4FF0h, ONES ;Ones in ramcounter 384FF0h (FFFF hex or 65535 dec)
seg018:E87E jmpr cc_UC, loc_8E888
UNSET RAMCOUNTER:
seg018:E880 loc_8E880:
seg018:E880 exts #38h, #1
seg018:E884 mov 4FF0h, ZEROS ;Zeros in ramcounter 384FF0h (0000 hex or 0 dec)
EXIT:
seg018:E888 loc_8E888:
seg018:E888
seg018:E888 movb rl4, byte_8AF3 ;restore original code that was replaced with call
seg018:E88C rets ;jump back to call adress
seg018:E88C ; --------------------------------------------------------------------------