section .data
input db "Enter a number: "
output db "Multiples less than input: "
sum_output db "Sum of multiples: "
section .bss
num resb 1
sum resb 2
section .text
global _start
_start:
; Output the prompt for user input
mov eax, 4
mov ebx, 1
mov ecx, input
mov edx, 16
int 0x80
; Read user input and convert to number
mov eax, 3
mov ebx, 0
mov ecx, num
mov edx, 1
int 0x80
sub eax, '0'
; Calculate multiples less than input and output them
mov ecx, 0
mov edx, sum
mov [edx], word 0
mov edx, output
next_multiple:
add eax, 1
cmp eax, 4
jge end_loop
mov ebx, eax
mov eax, ecx
div ebx
cmp edx, 0
jne next_multiple
mov eax, ebx
mov ebx, 1
mov ecx, output
mov edx, 25
int 0x80
mov eax, ecx
add eax, 1
mov ecx, eax
mov edx, sum
add [edx], ax
jmp next_multiple
end_loop:
; Output the sum of multiples less than input
mov eax, 4
mov ebx, 1
mov ecx, sum_output
mov edx, 18
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, sum
mov edx, 2
int 0x80
; Exit program
mov eax, 1
xor ebx, ebx
int 0x80