News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

LEA phun !

Started by hutch--, July 21, 2011, 06:22:06 AM

Previous topic - Next topic

hutch--

Just playing with the LEA multiply capacity. Some of these can be done with shifts and some can be done in one register, this is just a technique to provide a consistent interface to multiple by 2 up to 32.


IF 0  ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      Build this template with "CONSOLE ASSEMBLE AND LINK"
ENDIF ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include\masm32rt.inc

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    srcnum equ <100>

main proc

    mov ecx, srcnum
    lea eax, [ecx+ecx]          ; *2
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*2]        ; *3
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*4]            ; *4
    print ustr$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *5
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *6
    add eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *7
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *8
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *9
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *10
    add eax, eax
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *11
    lea eax, [eax+eax]
    add eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*2]        ; *12
    lea eax, [eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*2]        ; *13
    lea eax, [ecx+eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *14
    lea eax, [eax+eax*2]
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *15
    lea eax, [eax+eax*2]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *16
    add eax, eax
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *17
    add eax, eax
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *18
    add eax, eax
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *19
    add eax, eax
    add eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *20
    lea eax, [eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *21
    lea eax, [ecx+eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *22
    lea eax, [ecx+eax*4]
    add eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *23
    lea eax, [eax+eax*2]
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *24
    lea eax, [eax+eax*2]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*4]        ; *25
    lea eax, [eax+eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *26
    lea eax, [eax+eax*2]
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *27
    lea eax, [eax+eax*2]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *28
    lea eax, [eax+eax*2]
    add eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *28
    sub eax, ecx
    lea eax, [ecx+eax*4]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx+ecx*8]        ; *30
    add eax, ecx
    lea eax, [eax+eax*2]
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *31
    lea eax, [eax*4]
    sub eax, ecx
    print str$(eax),13,10

    mov ecx, srcnum
    lea eax, [ecx*8]            ; *32
    lea eax, [eax*4]
    print str$(eax),13,10

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Bill Cravener

That was fun Steve. Just a couple more years and I plan on getting back to having some fun. :bg
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

dedndave

    mov eax, srcnum
    shl eax, 5                  ; *32
    print str$(eax),13,10


:P

Bill Cravener

You're cheating Dave, that's not using LEA. :bg
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

anunitu

AHHHH,assembler PARTY!!!......lets all count to 1000 in binery....Hell,make it a billion!!!

hutch--

 :bg

> Some of these can be done with shifts and some can be done in one register

May as well add that some can be done with ADD as well.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php