Programming 5. The following design will input numbers into an array or doublewo
ID: 3589650 • Letter: P
Question
Programming 5. The following design will input numbers into an array or doublewords, using the sentinel value -9999 to terminate nbr Elts-= 0; get address of array prompt for and input number while number -9999 loop add 1 to nbrElts store number at address add 4 to address prompt for and input number end while; Implement this design in a windows 32 program that uses a dialog box to prompt for and input each number. Assume that no more than 100 numbers will be entered. Use a single message box to report the sum of the numbers, how many numbers were entered (not counting the sentinel value), the average of the numbers, and the count of array entries that are greater than or equal to the average value.Explanation / Answer
Solution:
code:
.MODEl FLAT
INCLUDE io.h
;exit process declaration
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
;declaring constants
car EQU 0dh
lineFedd EQU 0ah
AllowedCnt EQU 100
.STACK 4096
;data section
.DATA
info BYTE 'Enter up to 100 numbers'
getInput BYTE 'Enter value?',0
enterVal BYTE 20 DUP (?)
nbrElts DWORD ?
myAry DWORD AllowedCnt DUP(?)
mySum BYTE 10 DUP (?),car,lineFedd,0
sumStr BYTE car,lineFedd,lineFedd,'The sum is'
cntStr BYTE car,lineFedd,lineFedd,'The number of elements is'
;code section
.CODE
_start:
output info
mov nbrElts,0
lea ebx,myAry
output getInput
input enterVal,20
atod enterVal
while: cmp enterVal,-9999
je whileEnd
inc nbrElts
mov [ebx],eax
add ebx,4
output getInput
input enterVal,20
atod enterVal
jmp while
whileEnd:
mov eax,0
lea ebx,myAry
mov ecx, nbrElts
jecxz endExec
forLoop: add eax,[ebx]
add ebx,4
loop forLoop
dtoa mySum,nbrElts
output cntStr
output mySum
dtoa mySum,eax
output sumStr
output mySum
endExec: INVOKE ExitProcess,0
PUBLIC _start
END
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.