Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Greeting, I am not sure if this qualify as a question. I have this program, it u

ID: 3807835 • Letter: G

Question

Greeting,

I am not sure if this qualify as a question. I have this program, it uses loops with indirect or indexed addressing to permutates (re-arranges) an integer array. I tried to run it in assembly but it does not work. Could please you, tell me what is wrong with the coding?

Thanks.

INCLUDE Irvine32.inc
.386
.model flat,stdcall
.stack 4096

.data
welcome BYTE "Welcome! This program permutates an array of size 10.", 0Ah, 0Dh, 0 ;initialize the string
promptVal BYTE "Please enter the 10 integers to be permutated:", 0Ah, 0Dh, 0 ;initialize the string
permutedR BYTE "The permutated array is: ", 0Ah, 0Dh, 0 ;initialize the string

permutation DWORD 8, 3, 5, 9, 2, 6, 0, 4, 1, 7 ;initialize the permutattion
array DWORD 10 DUP(?) ;declare array of 10 Dwords.

.code
main PROC
MOV EDX, OFFSET welcome ;display the message
CALL WriteString
MOV EDX, OFFSET promptVal ;display the message
CALL WriteString

MOV ESI, OFFSET array ;prompt user for the integers entry
MOV ECX, 10 ;set the counter with the value 10

L1:
CALL ReadInt
MOV [ESI], EAX
ADD ESI, TYPE array
LOOP L1 ;repeat the loop until the count is 0

MOV EDI, OFFSET permutation
MOV ESI, OFFSET array
MOV ECX, 10 ;set the counter with the value 10

L2:
MOV EAX, [EDI]
PUSH ECX ;push ECX register
MOV ECX, 10 ;set the counter with the value 10

L3:
CMP EAX, [ESI] ; compare the EAX value with [ESI]
JE output ; if yes, then jump to label output
ADD ESI, TYPE array
  
LOOP L3 ;repeat the loop until the count is 0
back:

ADD EDI, TYPE permutation
POP ECX ;pop ECX register
LOOP L2 ;repeat the loop until the count is 0

JMP quit ; jump to quit and exit the program

output:
MOV EDX, OFFSET permutedR ;display the message
CALL WriteString
MOV EAX,[EDI]
MOV EAX,[ESI+EAX*4]
CALL WriteInt ;display the integers
MOV ESI, OFFSET array ;display the result
  
JMP back

quit:
exit ;exit to operating system
main ENDP
END main

Explanation / Answer

INCLUDE Irvine32.inc
.386
.model flat,stdcall
.stack 4096

.data
welcome BYTE "Welcome! This program permutates an array of size 10.", 0Ah, 0Dh, 0 ;initialize the string
promptVal BYTE "Please enter the 10 integers to be permutated:", 0Ah, 0Dh, 0 ;initialize the string
permutedR BYTE "The permutated array is: ", 0Ah, 0Dh, 0 ;initialize the string

permutation DWORD 8, 3, 5, 9, 2, 6, 0, 4, 1, 7 ;initialize the permutattion
array DWORD 10 DUP(?) ;declare array of 10 Dwords.

.code
main PROC
MOV EDX, OFFSET welcome ;display the message
CALL WriteString
MOV EDX, OFFSET promptVal ;display the message
CALL WriteString

MOV ESI, OFFSET array ;prompt user for the integers entry
MOV ECX, 10 ;set the counter with the value 10

L1:
CALL ReadInt
MOV [ESI], EAX
ADD ESI, TYPE array
LOOP L1 ;repeat the loop until the count is 0

MOV EDI, OFFSET permutation
MOV ESI, OFFSET array
MOV ECX, 10 ;set the counter with the value 10

L2:
MOV EAX, [EDI]
PUSH ECX ;push ECX register
MOV ECX, 10 ;set the counter with the value 10

L3:
CMP EAX, [ESI] ; compare the EAX value with [ESI]
JE output ; if yes, then jump to label output
ADD ESI, TYPE array
  
LOOP L3 ;repeat the loop until the count is 0
back:

ADD EDI, TYPE permutation
POP ECX ;pop ECX register
LOOP L2 ;repeat the loop until the count is 0

JMP quit ; jump to quit and exit the program

output:
MOV EDX, OFFSET permutedR ;display the message
CALL WriteString
MOV EAX,[EDI]
MOV EAX,[ESI+EAX*4]
CALL WriteInt ;display the integers
MOV ESI, OFFSET array ;display the result
  
JMP back

quit:
exit ;exit to operating system
main ENDP
END main