装配:反转数组

时间:2015-10-13 00:14:48

标签: assembly x86 masm irvine32

我在一个名为“在程序集中反转数组”的线程中找到了一段代码,并尝试将其应用于我的作业。这是我得到的错误代码,我不知道如何从这里修复它...

1>FirstAssignment.asm(29): error A2022: instruction operands must be the same size
1>FirstAssignment.asm(34): error A2022: instruction operands must be the same size
1>FirstAssignment.asm(36): error A2022: instruction operands must be the same size
1>FirstAssignment.asm(38): error A2022: instruction operands must be the same size

代码:

    ; Assignment 1
INCLUDE Irvine32.inc
; .386
;.model flat, stdcall
; .stack 4096
; ExitProcess proto, dwExitCode:dword
.data
Uarray WORD 1000h, 2000h, 3000h, 4000h
Sarray Sword - 1, -2, -3, -4

.code
main proc
movzx eax, [Uarray]
movzx ebx, [Uarray + 2]  //all these are part of part 1 of homework
movzx ecx, [Uarray + 4]
movzx edx, [Uarray + 6]
movsx eax, [Sarray]
movsx ebx, [Sarray + 2]
movsx ecx, [Sarray + 4]
movsx edx, [Sarray + 6]

mov ax, LENGTHOF Uarray/2; Moves the length(divided by 2) into the eax register.
mov bx, 0; Sets the ebx register to 0 to serve as the counter.
mov cx, LENGTHOF UARRAY; Loads the length of the array into the ecx register.
mov dx, [Uarray + 6]; Sets a counter that starts at the end of the array.


L1:

mov ax, UArray[si + (TYPE Uarray * bx)]; Assigns to eax the value in the current beginning counter.

xchg ax, Uarray[si + (TYPE Uarray * dx)]; Swaps the value in eax with the value at the end counter.

mov Uarray[si + (TYPE Uarray * bx)], ax; Assigns the current beginning counter the value in eax.

dec dx; Decrements the end counter by 1.
inc bx; Increments the beginning counter by 1.
loop L1



call DumpRegs
; invoke ExitProcess, 0
main endp
end main

这是我第一次尝试编写汇编语言程序,所以请尽量放松我,尽可能地减少所有内容。谢谢你的时间!

1 个答案:

答案 0 :(得分:0)

mov ebx, 0                   ; beginning counter
mov ecx, LENGTHOF UARRAY - 1 ; end counter

L1:

mov ax, UArray[esi + (TYPE Uarray * ebx)]; Assigns to ax the value in the current beginning counter.

xchg ax, Uarray[esi + (TYPE Uarray * ecx)]; Swaps the value in ax with the value at the end counter.

mov Uarray[esi + (TYPE Uarray * ebx)], ax; Assigns the current beginning counter the value in eax.

inc ebx      ; Increments the beginning counter by 1.
dec ecx      ; Decrements the end counter by 1
cmp ecx, ebx ; compare end to beginning
ja L1        ; continue if end > beginning