SHLD换档

问题描述 投票:0回答:0

我仍在研究这个程序,我应该编写一个程序,通过使用下一个元素将双字数组向左移动 n 位(传递 BL 寄存器中的位数)来执行 SHLD源操作数。我想我已经接近了,但是我遇到了一个异常错误……具体来说,我对 mov eax,[esi + (LENGTHOF array * TYPE DWORD) - 1] 之后循环中发生的事情有点困惑,所以如果我可以得到帮助,我真的很感激!

INCLUDE Irvine32.inc

.data
array DWORD 648B2165h,8C943A29h,6DFA4B86h,91F76C04h,8BAF9857h
prompt BYTE "Enter the number of bits shift to the left using SHLD: ", 0

.code
main PROC

    mov edx, OFFSET prompt      
    call WriteString            ; display menu
    call ReadHex
    ;call Crlf               go to next output line

    mov  bl,AL
    call ShiftDoublewords

; Display the results
    mov  esi,OFFSET array
    mov  ecx,LENGTHOF array
    mov  ebx,TYPE array
    call DumpMem

    exit
main ENDP

;---------------------------------------------------------------
ShiftDoublewords PROC
;
; Shifts an array of doublewords to the right.
; The array is a global variable.
; Receives: BL = number of bits to shift
; Returns: nothing
;---------------------------------------------------------------
    mov  esi,OFFSET array
    mov  ecx,(LENGTHOF array) - 1

L1: push ecx                ; save loop counter
    mov  eax,[esi + (LENGTHOF array * TYPE DWORD) - 1]
    mov  CL,BL              ; shift count
    shld [esi],eax,cl           ; shift EAX into high bits of [esi]
    sub  esi,TYPE DWORD         ; point to next doubleword pair
    pop  ecx                    ; restore loop counter
    loop L1

; Right-shift the last doubleword
    mov CL, BL
  shl DWORD PTR [esi], CL

    ret
ShiftDoublewords ENDP

END main
assembly irvine32
© www.soinside.com 2019 - 2024. All rights reserved.