Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Assembly Language, Reverse an Array, Error with code

$
0
0
Hey, so this is what I have done so far, but my code does not work. We are supposed to make a code that accept 10 user inputs, then puts them back out in reverse order. I have the loop working to print the numbers in the same order they were pushed into, I know this by commenting out the "call ReverseArray" I can see my program work, but once I un-comment it, the code does not work. I am supposed to use SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible to support the array size and type being changed in the future, but I am not fully there yet. Any help would be much appreciated. I am new to Assembly Language and finding it rather challanging.

INCLUDE Irvine32.inc ;// include the Irvine code for WriteInt
.data
	arr DWORD 10 DUP(?)					;// create an array that holds 10 elements supplied by user
	num WORD ?
	msg BYTE "Please enter # 10 numbers",0dh,0ah,0
	newLine BYTE 0dh,0ah,0
	msg2 BYTE "Here are the numbers printed backwards",0dh,0ah,0



.code

main PROC
	call Clrscr  

	mov esi, OFFSET arr					;//
	mov ecx, 10							;//counter (# of items in array to loop through)

	call FillArray
	call ReverseArray
	call PrintArray

	exit

main ENDP

FillArray PROC
	push esi
	push ecx
	mov edx, OFFSET msg
	call WriteString
	myLoop1:
		call ReadInt
		mov [esi], eax
		add esi, TYPE DWORD
	loop myLoop1
	pop ecx
	pop esi
	ret
FillArray ENDP


ReverseArray PROC
	
	myLoop1:
		pop esi
		pop ecx
		mov eax, arr[esi]
		add eax, TYPE DWORD
		call WriteInt
		
	Loop myLoop1
	push esi
	push ecx
ReverseArray ENDP

PrintArray	PROC

	push esi
	push ecx
	mov edx, OFFSET msg2
		call WriteString
	myLoop1:
		mov eax, [esi]
		call WriteInt
		add esi, TYPE DWORD
		call EndLine
	loop myLoop1

	pop ecx
	pop esi
	ret
PrintArray	ENDP

EndLine PROC
	push edx
	mov edx, OFFSET newline
	call WriteString
	pop edx
	ret
EndLine ENDP

;//procedure to fill loop based on user input
;//procedure to reverse the loop
;//procedure to print loop
;//endl procedure to put new line
	push esi
	push ecx

	pop ecx
	pop esi


END main


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>