Assembly language: The given code finds the average of all the numbers entered b
ID: 3765707 • Letter: A
Question
Assembly language:
The given code finds the average of all the numbers entered by the user.
The problem im having is how to find the average of negative number and for the output, there should be no space between the decimal and the remainder.
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
number1 DWORD ?
number2 DWORD ?
userInputs DWORD 0
source DWORD ?
totalCount DWORD ?
avg DWORD ?
prompt7 BYTE "WELCOME!!", 0
prompt1 BYTE "Enter first number", 0
prompt2 BYTE "Enter number to add or subtract", 0
prompt3 BYTE "See you later!" , 0
prompt4 BYTE "BYE!" ,0
prompt9 BYTE "test!", 0
resultAvg BYTE "The average is: ", 0
aveOutput BYTE 11 DUP (?), 0
string BYTE 40 DUP (?)
resultLbl BYTE "The sum is: ", 0
prompt5 BYTE "TOTAL: "
hexLbl BYTE "0x", 0
display BYTE "TOTAL:"
sum BYTE 11 DUP (?)
dsfgd BYTE "(0x"
dest BYTE 8 DUP (?)
dfgsg BYTE ")",0
resultOut BYTE "The count is: ", 0
.CODE
_MainProc PROC
output prompt7, string
input prompt1, string, 40
atod string
mov number1, eax
rdloop:
inc userInputs
input prompt2, string, 40
atod string
mov number2, eax
mov eax, number1
add eax, number2
dtoa sum, eax
mov totalCount, eax
mov number1, eax
mov source, eax
lea eax, dest
push eax
push source
call hexToAscii
add esp, 8
output resultLbl, display
cmp number2, 0
jne rdloop
mov eax, totalCount
mov ebx, userInputs
idiv ebx
dtoa avg, eax
output resultAvg, avg
;output prompt4, prompt3
mov eax, 0
ret
_MainProc ENDP
hexToAscii PROC
push ebp
mov ebp, esp
push eax
push ebx
push ecx
push edx
mov eax,[ebp+8]
mov edx,[ebp+12]
mov ecx,8
forIndex: mov ebx, eax
and ebx, 0000000fh
ifDigit: cmp bl,9
jnle elseHex
or bl,30h
jmp endIfDigit
elseHex: add bl, 'A'-10
endIfDigit:
mov [edx+ecx-1], bl
shr eax,4
loop forIndex
pop edx
pop ecx
pop ebx
pop eax
pop ebp
ret
hextoAscii ENDP
END
Explanation / Answer
Answer :