News:

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

newbee need help and explanation

Started by ghmail2, January 25, 2010, 07:34:49 PM

Previous topic - Next topic

ghmail2

.data
l dw (2)
r dw (3)

.code
start:
mov AX, l
mov BX, r
shr BX, 1
mov CX, AX
shl CX, 15
shr AX, 1
or BX, CX
shl EAX, 16
or AX, BX

end start
i am just about start lerning masm.
can anybody tell me what has the code above done and how?

thx

dedndave


        .data

l       dw 2
r       dw 3

        .code

start:  mov     ax,l        ;AX = l  (L)
        mov     bx,r        ;BX = r  (R)
        shr     bx,1        ;BX = R shifted right by 1 bit (1 bit discarded)
        mov     cx,ax       ;CX = AX = L
        shl     cx,15       ;CX = L shifted left by 15 bits (15 bits discarded)
        shr     ax,1        ;AX = L shifted right by 1 bit (1 bit discarded)
        or      bx,cx       ;BX = R shifted right by 1 bit (OR) L shifted left by 15 bits
        shl     eax,16      ;high word = L shifted right by 1 bit
        or      ax,bx       ;low word = R shifted right by 1 bit (OR) L shifted left by 15 bits

;need some kind of termination code here
;different for 16-bit and 32-bit programs

        end     start


AX   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
    L15 L14 L13 L12 L11 L10 L09 L08 L07 L06 L05 L04 L03 L02 L01 L00

BX   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1
    R15 R14 R13 R12 R11 R10 R09 R08 R07 R06 R05 R04 R03 R02 R01 R00


result

EAX  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
     0  L15 L14 L13 L12 L11 L10 L09 L08 L07 L06 L05 L04 L03 L02 L01  L00 R15 R14 R13 R12 R11 R10 R09 R08 R07 R06 R05 R04 R03 R02 R01

shorter code...

        mov     ax,l        ;AX = L
        shl     eax,16      ;high word = L
        mov     ax,r        ;AX = R
        shr     eax,1