DOSSEG ; A Assembler program that reads fixed input numbers and averages ; Author: ; Purpose: ;Data section .model huge .stack 100h .586 .data ; Data goes here inp db 5 newlen db ? block db 5 dup (' ') newbl db 4 dup (' ') sum dd 0 count dd 0 greet db "This program will enter 4 digit numbers and average",13,10,'$' prompt1 db "Enter the number of integers you want (fixed 4 char width)",13,10,'$' prompt2 db 13,10,"Enter a value - 4 positions only",13,10,'$' out1 db 13,10,"Input is "; out2 db " ",13,10,13,10,'$'; out3 db 13,10,"Average is "; out4 db " ",13,10,13,10,'$'; .code ; Here is the code start: mov ax,@data ; Address the data mov ds,ax mov es,ax ; get a number lea dx,prompt1 call readn ; convert it mov ecx,eax push ecx lea ebx,out2 call int_to_str ; display it lea dx,out1 mov ah,9 int 21h xor ebx,ebx lea dx,prompt2 aloop: call readn add ebx,eax loop aloop mov eax,ebx pop ecx cwd idiv cx cwde lea ebx,out4 call int_to_str mov ah,9 lea dx,out3 int 21h mov ax,4c00h ; Leave the program int 21h ; Any subroutines would go here readn proc near ; eax will hold the result ; dx is address of the prompt push ebx push ecx push edx ; write the prompt mov ah,9 int 21h mov ah,10 lea dx,inp int 21h mov ebx, DWORD PTR block and ebx,0f0f0f0fh mov cx,4 xor edx,edx looper: mov al,bl ; move and convert cbw cwde imul edx,10 add edx,eax ror ebx,8 ; gets byte in bl loop looper mov eax, edx pop edx pop ecx pop ebx ret readn endp include int2str.asm ; Last line of assembly is end end