Assembly

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

```assembly

section .data

numbers db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;

count dw 0 ;

section .text

global _start

add_number:

mov eax, 3 ;

mov ebx, 0 ; stdin

mov ecx, numbers ;

mov edx, 2 ;)

int 0x80 ;

cmp dword [numbers],

je end_add_number

cmp dword [numbers], 0 ;

jl add_number

mov ax, [count] ; ax

mov byte [numbers + eax], dl ; eax

inc ax ; 1

mov [count], ax ;

jmp add_number ;

end_add_number:

ret

sort_numbers:

mov ax, [count] ; ax

dec ax ;

mov bx, ax ; bx
outer_loop:

mov cx, bx ; cx

inner_loop:

mov al, [numbers + cx - 1] ; al

cmp al, [numbers + cx - 2] ;

jl swap ;

dec cx ;

cmp cx, 1 ;

jg inner_loop ;

dec bx ;

cmp bx, 0 ;

jg outer_loop ;

jmp end_sort_numbers ;

swap:

mov dl, [numbers + cx - 1] ;

mov [numbers + cx - 1], [numbers + cx - 2] ;

mov [numbers + cx - 2], dl ;

dec cx ;

cmp cx, 1 ;

jg inner_loop ;

jmp outer_loop ;

end_sort_numbers:

ret

calculate_statistics:

mov ax, [count] ; cmp ax, 0 ;


je end_calculate_statistics

mov bx, [numbers] ;

mov cx, [numbers] ;

mov dx, [numbers] ;

mov si, [numbers] ;

mov ax, [count] ;

mov bx, 0 ;

loop_sum:

add bx, [si] ;

inc si ;

dec ax ;

jnz loop_sum ;

mov ax, [count] ;

mov bx, [bx] ;

mov dx, [numbers + ax - 2] ;

mov ax, [bx] ;

mov cx, [bx] ;

shl ax, 16 ;

div [count] ;

mov bx, ax ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, str_min ;

mov edx, 14 ;

int

0x80 ;
mov eax, 4 ;

mov ebx, 1 ;

mov ecx, [numbers] ;

mov edx, 1 ;

int 0x80 ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, str_max ;

mov edx, 14 ;

int 0x80 ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, dx ;

mov edx, 1 ;

int 0x80 ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, str_sum ;

mov edx, 5 ;

int 0x80 ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, bx ;

mov edx, 1 ;

int 0x80 ;

mov eax, 4 ;
mov ebx, 1 ;

mov ecx, str_avg ;

mov edx, 8 ;

int 0x80 ;

mov eax, 4 ;

mov ebx, 1 ;

mov ecx, bx ;

mov edx, 1 ;

int 0x80 ;

end_calculate_statistics:

ret

_start:

call add_number ;

call sort_numbers ;

call calculate_statistics ;

mov eax, 1 ;

xor ebx, ebx ;

int 0x80 ;

section .data

str_min db 'Minimum value: ', 0

str_max db 'Maximum value: ', 0

str_sum db 'Sum: ', 0

str_avg db 'Average: ', 0

```

You might also like