Something like this? (not complete)
section .data
; Welcome message
wellmsg db "This program will compute the average of 10 2-digit numbers.",0xA
wellmsglen equ $-wellmsg
askmsg db "Enter number #"
askmsglen equ $-askmsg
section .bss
numlist: resb 10 ; list of our numbers
total: resd 1 ; to store the sum of the 10 numbers
inputBufferSize equ 3 ; three characters (num1, num2 and enter key)
inputBuffer resb inputBufferSize
inputBufferEnd:
outputBufferSize equ 10
outputBuffer resb outputBufferSize
outputBufferEnd:
section .text
global _start
_start:
; print welcome message once
mov eax, 4
mov ebx, 1
mov ecx, wellmsg
mov edx, wellmsglen
int 0x80
; loop to run 10 times to read input and store number
mov ecx, 0
prompt:
; store count
push ecx
; prompt message
mov eax, 4
mov ebx, 1
mov ecx, askmsg
mov edx, askmsglen
int 0x80
; pop eax ; get loop cunter back
; push eax ; put it back
mov eax, [esp]
inc eax ; we want to start with "1", not "0"
call print_num
; need a space here, maybe a ":"
mov al, ':'
call print_char
mov al, ' '
call print_char
; get input number
call get_num
add [total], eax
pop ecx
inc ecx
cmp ecx, 9
jne prompt
mov eax, [total]
call print_num
;exit
mov eax, 1
mov ebx, 0
int 0x80
get_num:
; input into buffer
mov eax, 3
mov ebx, 0
mov ecx, inputBuffer
mov edx, inputBufferSize
int 0x80
; eax = length of string
; make esi the start of the string
mov esi, inputBuffer
; make edi the end of the string
mov edi, inputBuffer
add edi, eax
dec edi
mov eax, 0
get_num_loop:
mov edx, 10
mul edx ; edx:eax = eax * operand
mov edx, 0
mov dl, [esi]
sub dl, 0x30
inc esi
add eax, edx
cmp esi, edi
jne get_num_loop
ret ; eax = inputed value
print_num:
; point to the end of the buffer
mov edi, outputBufferEnd
print_num_loop:
; move one character left
dec edi
; set up division
mov edx, 0
mov ebx, 10
div ebx ; eax = edx:eax / ebx, remainder in edx
; put the remainder on the buffer
add dl, 0x30 ; make it ASCII first
mov [edi], dl
; if after the above division, eax != 0, continue to loop, otherwise exit the loop
cmp eax, 0
jne print_num_loop
; set up registers and make system call
mov eax, 4
mov ebx, 1
mov ecx, edi
mov edx, outputBufferEnd
sub edx, edi
int 0x80
ret
print_char:
; prints the character in al
push edx
push ecx
push ebx
push eax ; must be pushed last - it's our "buffer"
mov ecx, esp ; our buffer
mov edx, 1 ; just one
mov ebx, 1
mov eax, 4
int 80h
pop eax
pop ebx
pop ecx
pop edx
ret
Edit: well I see you've come up with essentially the same thing...
Best,
Frank