News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Branching Test

Started by hutch--, October 23, 2022, 05:16:43 PM

Previous topic - Next topic

hutch--

This demo compares two techniques, sequential comparison versus a table based branching. The table based system has a fixed number of instructions for small to very large ranges.

comment # «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

    Comparison of two techniques, sequential comparison versus a table based branching system
    that can handle very large ranges without speed loss with its fixed instruction count

«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» #

    include \masm64\include64\masm64rt.inc

    .code

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

entry_point proc

    rcall sequential_cmp,0
    rcall sequential_cmp,1
    rcall sequential_cmp,2

    rcall table_branch,0
    rcall table_branch,1
    rcall table_branch,2
    rcall table_branch,3

    .exit

entry_point endp

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

sequential_cmp proc num1:QWORD

    cmp num1, 0
    jne @F
    rcall MessageBox,0,str$(num1),"sequential Zero",MB_OK
    ret
  @@:
    cmp num1, 1
    jne @F
    rcall MessageBox,0,str$(num1),"sequential One",MB_OK
    ret
  @@:
    cmp num1, 2
    jne @F
    rcall MessageBox,0,str$(num1),"sequential Two",MB_OK
    ret
  @@:
    ret

sequential_cmp endp

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

table_branch proc num1:QWORD                                ; input range, 0 to 2

    .data
      lbls dq lbl0,lbl1,lbl2                                ; table of labels
    .code

    mov rax, num1                                           ; load input into rax
    cmp rax,2                                               ; test for range

    jna @F
    rcall MessageBox,0,"Number out of range","Table Branch Error",MB_OK
    ret

  @@:
    lea rdx, lbls                                           ; load table offset
    jmp QWORD PTR [rdx][rax*8]                              ; branch to offset + input * 8

  lbl0:
    rcall MessageBox,0,str$(num1),"table branch Zero",MB_OK
    ret

  lbl1:
    rcall MessageBox,0,str$(num1),"table branch One",MB_OK
    ret

  lbl2:
    rcall MessageBox,0,str$(num1),"table branch Two",MB_OK
    ret

table_branch endp

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

    end


NoCforMe

Assembly language programming should be fun. That's why I do it.

hutch--

David,

Don't let me stop you. I have it done, have used the technique for years and if you need very fast options by number, its genuinely fast but seriously I don't have time to write a benchmark.