Wilmington Write Code to Implement Procedures for Array Multiplication Coding Task

User Generated

FreEb

Computer Science

College of Wilmington

Description

This program prompts the user for six integers, stores them in an array, calculates the sum of the array, and displays the sum.

TO DO:

Write code to implement the requirement for procedures : ArrayMultiplication

Write code to implement the requirement for procedure: ArraySumOdd

Keep in mind that INTEGER_COUNT = 6 can be changed to other number.

INCLUDE Irvine32.inc

INTEGER_COUNT = 6

.data

str1 BYTE "Enter a signed integer: ",0

str2 BYTE "The sum of the integers is: ",0

array DWORD INTEGER_COUNT DUP(?)

divider DWORD 2

.code

;-----------------------------------------------------------------

; you do not need to change any code in the main procedure

;-------------------------------------------------------------------

main PROC

call Clrscr

mov esi,OFFSET array

mov ecx,INTEGER_COUNT

call PromptForIntegers

call ArraySum

call DisplaySum

mov esi,OFFSET array

mov ecx,INTEGER_COUNT

call ArrayMultiplication

call DisplaySum

mov esi,OFFSET array

mov ecx,INTEGER_COUNT

call ArraySumOdd

call DisplaySum

exit

main ENDP

;-----------------------------------------------------

PromptForIntegers PROC USES ecx edx esi

;

; Prompts the user for an arbitrary number of integers

; and inserts the integers into an array.

; Receives: ESI points to the array, ECX = array size

; Returns: nothing

;-----------------------------------------------------

mov edx,OFFSET str1 ; "Enter a signed integer"

L1: call WriteString ; display string

call ReadInt ; read integer into EAX

call Crlf ; go to next output line

mov [esi],eax ; store in array

add esi,TYPE DWORD ; next integer

loop L1

ret

PromptForIntegers ENDP

;-----------------------------------------------------

ArraySum PROC USES esi ecx

;

; Calculates the sum of an array of 32-bit integers.

; Receives: ESI points to the array, ECX = number

; of array elements

; Returns: EAX = sum of the array elements

;-----------------------------------------------------

mov eax,0 ; set the sum to zero

L1: add eax,[esi] ; add each integer to sum

add esi,TYPE DWORD ; point to next integer

loop L1 ; repeat for array size

ret ; sum is in EAX

ArraySum ENDP

;-------------------------------------------------------------------------------------------

; Calculate the multiplications for an array of 32-bit integers

; int the main procedure, we asked a user to enter numbers, the times

; of entering the number is defined by INTEGER_COUNT

; and the entered numbers are stored in the array and its address is loaded to ESI

; you can use other registers in code

; You need to implement the code in this procedure to calculate the addition of first-half numbers in the array

; and then calculate the addition of the second-half half numbers in the array,

; and finally calculate the multiplication of these two addition results.

; Your final result has to be moved to EAX.

; Please document your steps

;-----------------------------------------------------------------------------------------------

ArrayMultiplication PROC USES esi ecx edx

Write code here to implement the requirement for procedures : ArrayMultiplication

ret

ArrayMultiplication ENDP

;------------------------------------------------------------------------------------------------

; calculate the sum of the array, only summarize the Odd numbers

; int the main procedure, we asked a user to enter numbers, the times

; of entering the number is defined by INTEGER_COUNT

; and the entered numbers are stored in the array and its address is loaded to ESI

; You can other registers in your code.

; You need to implement the code in this procedure to add up only the odd numbers in this array

; your final result must be moved to EAX

; Please document your steps

;--------------------------------------------------------------------------------------------------

ArraySumOdd PROC USES esi ecx edx

Write code here to implement the requirement for procedure: ArraySumOdd

ret

ArraySumOdd ENDP

;--------------------------------------------------------------------

DisplaySum PROC USES edx

;

; Displays the sum on the screen

; Receives: EAX = the sum

; Returns: nothing

;---------------------------------------------------------------------

mov edx,OFFSET str2 ; "The result of the..."

call WriteString

call WriteInt ; display EAX

call Crlf

ret

DisplaySum ENDP

END main

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

hey man, can you check this file. I've highlighted the code i've written in bold so you can easily check

INCLUDE Irvine32.inc
INTEGER_COUNT = 6
.data
str1 BYTE "Enter a signed integer: ",0
str2 BYTE "The sum of the integers is: ",0
array DWORD INTEGER_COUNT DUP(?)
divider DWORD 2
.code
;----------------------------------------------------------------; you do not need to change any code in the main procedure
;------------------------------------------------------------------main PROC
call Clrscr
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call PromptForIntegers
call ArraySum
call DisplaySum
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call ArrayMultiplication
call DisplaySum
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call ArraySumOdd
call DisplaySum

exit
main ENDP
;----------------------------------------------------PromptForIntegers PROC USES ecx edx esi
;
; Prompts the user for an arbitrary number of integers
; and inserts the integers into an array.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;----------------------------------------------------mov edx,OFFSET str1 ; "Enter a signed integer"
L1: call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
add esi,TYPE DWORD ; next integer
loop L1
ret
PromptForIntegers ENDP
;----------------------------------------------------ArraySum PROC USES esi ecx
;
; Calculates the sum of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = number
; of array elements
; Returns: EAX = sum of the array elements

;----------------------------------------------------mov eax,0 ; set the sum to zero
L1: add eax,[esi] ; add each integer to sum
add esi,TYPE DWORD ; point to next integer
loop L1 ; repeat for array size
ret ; sum is in EAX
ArraySum ENDP
;------------------------------------------------------------------------------------------; Calculate the multiplications for an array of 32-bit integers
; int the main procedure, we asked a user to enter numbers, the times
; of entering the number is defined by INTEGER_COUNT
; and the entered numbers are stored in the array and its address is loaded to ESI
; you can use other registers in code
; You need to implement the code in this procedure to calculate the addition of first-half numbers in
the array
; and then calculate the addition of the second-half half numbers in the array,
; and finally calculate the multiplication of these two addition results.
; Your final result has to be moved to EAX.
; Please document your steps
;----------------------------------------------------------------------------------------------ArrayMultiplication PROC USES esi ecx edx
;
; Calculates the product of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = number
; of array elements
; Returns: EAX = product of the array elements

;----------------------------------------------------mov eax,1 ; set the product to one
L1: mul eax,[esi] ; add each integer to sum
add esi,TYPE DWORD ; point to next integer
loop L1 ; repeat for array size
ret ; product is in EAX
ArrayMultiplication ENDP
;-----------------------------------------------------------------------------------------------; calculate the sum of the array, only summarize the Odd numbers
; int the main procedure, we asked a user to enter numbers, the times
; of entering the number is defined by INTEGER_COUNT
; and the entered numbers are stored in the array and its address is loaded to ESI
; You can other registers in your code.
; You need to implement the code in this procedure to add up only the odd numbers in this array
; your final result must be moved to EAX
; Please document your steps
;-------------------------------------------------------------------------------------------------ArraySumOdd PROC USES esi ecx edx
;
; Calculates the sum of an array of 32-bit integers that are odd.
; Receives: ESI points to the array, ECX = number
; of array elements
; Returns: EAX = sum of the array elements
;----------------------------------------------------mov eax,0 ; set the sum to zero
AND eax,1 ;ANDing with 1 means checking the least significant bit if its 1, it is. Then it’s odd.

Jnz skip

;we skip it when it’s not odd.

L1: add eax,[esi] ; add each integer to sum
add esi,TYPE DWORD ; point to next integer
skip:
loop L1 ; repeat for array size
ret; sum is in EAX
ArraySumOdd ENDP
;-------------------------------------------------------------------DisplaySum PROC USES edx
;
; Displays the sum on the screen
; Receives: EAX = the sum
; Returns: nothing
;--------------------------------------------------------------------mov edx,OFFSET str2 ; "The result of the..."
call WriteString
call WriteInt ; display EAX
call Crlf
ret
DisplaySum ENDP
END main

Attached. Please let me know if you have any questions or need revisions.

INCLUDE Irvine32.inc
INTEGER_COUNT = 6
.data
str1 BYTE "Enter a signed integer: ",0
str2 BYTE "The sum of the integers is: ",0
array DWORD INTEGER_COUNT DUP(?)
divider DWORD 2
.code
;----------------------------------------------------------------; you do not need to change any code in the main procedure
;------------------------------------------------------------------main PROC
call Clrscr
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call PromptForIntegers
call ArraySum
call DisplaySum
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call ArrayMultiplication
call DisplaySum
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call ArraySumOdd
call DisplaySum

exit
main ENDP
;----------------------------------------------------PromptForIntegers PROC USES ecx edx esi
;
; Prompts the user for an arbitrary number of integers
; and inserts the integers into an array.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;----------------------------------------------------mov edx,OFFSET str1 ; "Enter a signed integer"
L1: call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
add esi,TYPE DWORD ; next integer
loop L1
ret
PromptForIntegers ENDP
;----------------------------------------------------ArraySum PROC USES esi ecx
;
; Calculates the sum of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = number
; of array elements
; Returns: EAX = sum of the array elements

;----------------------------------------------------mov eax,0 ; set the sum to zero
L1: add eax,[esi] ; add each integer to sum
add esi,TYPE DWORD ; point to next integer
loop L1 ; repeat for array size
ret ; sum is in EAX
ArraySum ENDP
;------------------------------------------------------------------------------------------; Calculate the multiplications for an array of 32-bit integers
; int the main procedure, we asked a user to enter numbers, the times
; of entering the number is defined by INTEGER_COUNT
; and the entered numbers are stored in the array and its address is loaded to ESI
; you can use other registers in code
; You need to implement the code in this procedure to calculate the addition of first-half numbers in
the array
; and ...

Similar Content

Related Tags