Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly language: The given code finds the average of all the numbers entered b

ID: 3765785 • Letter: A

Question

Assembly language:

The given code finds the average of all the numbers entered by the user and changes the answer into hex

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

DATA VAL1 DB ? NL1 DB 0AH,0DH,'ENTER HOW MANY NO U WANT:','$' NL2 DB 0AH,0DH,'ENTER NO:','$' NL3 DB 0AH,0DH,'AVEARGE:','$' .CODE MAIN PROC MOV AX,@DATA MOV DS,AX LEA DX,NL1 MOV AH,09H INT 21H MOV AH,01H INT 21H SUB AL,30H MOV CL,AL MOV BL,AL MOV AL,00 MOV VAL1,AL LBL1: LEA DX,NL2 MOV AH,09H INT 21H MOV AH,01H INT 21H SUB AL,30H ADD AL,VAL1 MOV VAL1,AL LOOP LBL1 LBL2: LEA DX,NL3 MOV AH,09H INT 21H MOV AX,00 MOV AL,VAL1 DIV BL ADD AX,3030H MOV DX,AX MOV AH,02H INT 21H MOV AH,4CH INT 21H MAIN ENDP END MAIN

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote