Я новичок в ассемблере и у меня проблема с регистром ecx и циклом, кажется, цель этой программы -
- Ввести 10 целых чисел со знаком в массив DWORD
- Печать массива
- Поворот массива вправо на 1 индекс [1,2,3,4] -> [4,1,2,3]
- Печать массива
Мой код приведен ниже, и я, кажется, добавил 11-е значение в процессе его вращения, и я не могу перестать чесать голову, пытаясь понять, почему
TITLE RotateArray (RotateArray.asm)
;This program will ask the user to input 10 values into a DWORD array
;then proceed to rotate it to the right by one index then print both versions
;Tanner Boyle, Oct 15, 2019.
INCLUDE Irvine32.inc
.data
array DWORD 10 DUP(?) ;Uninitialized Array
prompt BYTE "Please enter a signed integer: ", 0
comma BYTE ", ", 0
.code
;************************* MAIN ***************************************
main PROC
mov edi, OFFSET array ;Set EDI to address of array
mov ecx, 10 ;Set ECX to size of array
;****************************************** Number Collection ***********************************
L1:
mov edx, OFFSET prompt ;Ask for anumber
Call WriteString
Call ReadInt
mov [edi], eax ;Move the number into the array
add edi, TYPE array ;OFFSET array by its type
loop L1
;******************************************* Print **********************************************
mov edi, OFFSET array ;Set EDI to address of array
mov ecx, 10 ;Set ECX to size of array
mov al, '[' ;Write a [ to indicate start of the array
call WriteChar
sub ecx, 1 ;Subracting so you dont print the last value for the comma
L2:
mov eax, [edi] ;Moving the value of array to eax
call WriteInt ;Writing it as a byte
mov edx, OFFSET comma ;Moving the h, comma and space to edx
call WriteString ;Write it
add edi, TYPE array ;Adding edi the type of array to shift the values
loop L2 ;Loop
mov eax, [edi] ;Moving the last value of the array
call WriteInt
mov al, ']' ;Writing the closing bracket
call WriteChar
call CrLf
;******************************************* Rotation *******************************************
mov edi, OFFSET array ;Set EDI to address of array
mov ecx, 10 ;Set ECX to size of array
mov eax, [edi] ;Move index 0 into eax to store as a temp
L3:
mov edx, [edi] ;Move into a second temp the value at edi
mov [edi], eax ;Move the temp into the value at edi
mov eax, edx ;Set the first temp to the second temp
add edi, TYPE array
loop L3
mov edi, OFFSET array
mov [edi], eax ;Set the temp to the first value
;******************************************* Print **********************************************
mov al, '[' ;Write a [ to indicate start of the array
call WriteChar
sub ecx, 1 ;Subracting so you dont print the last value for the comma
mov edi, OFFSET array ;Set EDI to address of array
mov ecx, 10 ;Set ECX to size of array
L4:
mov eax, [edi] ;Moving the value of array to eax
call WriteInt ;Writing it as a byte
mov edx, OFFSET comma ;Moving the h, comma and space to edx
call WriteString ;Write it
add edi, TYPE array ;Adding edi the type of array to shift the values
loop L4 ;Loop
mov eax, [edi] ;Moving the last value of the array
call WriteInt
mov al, ']' ;Writing the closing bracket
call WriteChar
call CrLf
exit
main ENDP
END main
Исправлен вывод
Массив поворота теперь работает, однако алгоритм добавляет 11-е значение в память. Кто-нибудь видит какие-либо проблемы с моим алгоритмом?