I have been messing around with this code forever.. I know im missing something but I am completely lost at this point.


The code is suppose to print the array, then shift all the values to the right with SHRD, then reprint the array. Please help! Thank you!

INCLUDE Irvine32.inc
.data
intArray DWORD 20d,40d,80d,100d,200d
msgA BYTE "OLD - ",0
msgB BYTE "NEW - ",0

.code
main PROC
	mov edx,OFFSET msgA				; load old array msg
	mov esi,0						; last element	
	call WriteString				; display old array
	call display					; calls display proc - prints out array values
	call shift
	call display

	; display proc - takes integer array and outputs the values
	display PROC					; counter
	mov ecx,0						; counter	
		.WHILE ecx < 5
			mov eax,intArray[esi]	; load first element
			call WriteInt			; display element
			add esi,4				; move up one element
			add ecx,1				; inc counter
		.ENDW	
		ret							;	go back
	display ENDP

	; shift proc - shifts all values of elements in the array to the right
	sub esi,4						; re-align esi
	shift PROC						; counter
		.WHILE ecx < 10
			mov eax,intArray[esi]	; load value
			sub esi,4				; move down an element
			mov ebx,intArray[esi]	; load value
			shrd eax,ebx,4			; shift to the right 4 bits
		.ENDW
		ret							; go back
	shift ENDP
	call Crlf						; new line
exit
main ENDP
END main

Figured it out, also changed the conditional structure wording.

TITLE Chapter 7 Exercise 4  

; Program Description: Program takes an array of 5 elements and shifts them all 16bits with SHRD.
; The program prints each element, old and new, before moving the to next element in the array.
; Assignment #: 6a
; Author: meowbits
; Due Date: 12/6/11

     
Comment !
	This program takes a DWORD array length 5.
	The program takes the array and shifts elements 16bits with SHRD
	Program prints each element of the array before and after each shift

	*Note* 
	Since the problem states to use a 5 element array and to shift all elements. 
	The last element will get 8 random bits places in the high positions from the "6th" element.
!

INCLUDE Irvine32.inc
.data
intArray DWORD 11111111h,22222222h,33333333h,44444444h,55555555h
msgA BYTE "OLD - ",0
msgB BYTE "NEW - ",0

.code
main PROC
	mov ecx,0					; zero
	mov esi,0					; last element

	@@while:
		cmp ecx,4				; compare ecx to 4
		jg exit1				; if true, exit

		mov eax,intArray[esi]	; load value
		mov edx,OFFSET msgA		; load old element msg

		call WriteString		; display old element msg
		call WriteHex			; display current array element in hex
		call Crlf				; new line

		add esi,4				; move up one element
		mov ebx,intArray[esi]	; load value
		shrd eax,ebx,16			; shift 16bits, half of element
		mov edx,OFFSET msgB		; load new element msg
		add ecx,1				; counter

		call WriteString		; display element msg
		call WriteHex			; display current updated array element in hex
		call Crlf				; new line
		call Crlf				; new line
		jmp @@while				; loop

		exit1:					; done
exit
main ENDP
END main
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.