section .bss
buffer resb 20     
inbuf  resb 1     
num1   resd 1
num2   resd 1

section .text
global _start

_start:
    call scan_int
    mov [num1], eax

    call scan_int
    mov [num2], eax

    mov eax, [num1]
    add eax, [num2]
    push eax
    call print_int

    mov eax, [num1]
    imul eax, [num2]
    push eax
    call print_int

    mov eax, 1
    xor ebx, ebx
    int 0x80

scan_int:
    push ebp
    mov ebp, esp
    push ebx
    push ecx
    push edx
    push esi
    push edi

    xor esi, esi  
    xor edi, edi  

.skip_ws:
    mov eax, 3
    mov ebx, 0   
    mov ecx, inbuf
    mov edx, 1
    int 0x80
    cmp eax, 0
    je .done

    mov al, [inbuf]
    cmp al, ' '
    je .skip_ws
    cmp al, 9
    je .skip_ws
    cmp al, 10
    je .skip_ws
    cmp al, 13
    je .skip_ws

    cmp al, '-'
    jne .check_plus
    mov edi, 1
    jmp .read_digits

.check_plus:
    cmp al, '+'
    je .read_digits

.first_digit:
    sub al, '0'
    cmp al, 9
    ja .done
    movzx esi, al

.read_digits:
    mov eax, 3
    mov ebx, 0
    mov ecx, inbuf
    mov edx, 1
    int 0x80
    cmp eax, 0
    je .done

    mov al, [inbuf]
    sub al, '0'
    cmp al, 9
    ja .done

    movzx eax, al
    imul esi, esi, 10
    add esi, eax
    jmp .read_digits

.done:
    mov eax, esi
    test edi, edi
    jz .ret
    neg eax

.ret:
    pop edi
    pop esi
    pop edx
    pop ecx
    pop ebx
    pop ebp
    ret

print_int:
    push ebp
    mov ebp, esp
    push ebx
    push ecx
    push edx
    push esi
    push edi

    mov ecx, [ebp+8]
    mov edi, 18
    mov byte [buffer + 18], 0xA
    mov byte [buffer + 19], 0

    cmp ecx, 0
    jge .positive
    mov ebx, 1        
    neg ecx
    jmp .convert

.positive:
    xor ebx, ebx

.convert:
    mov esi, 10

.loop:
    mov eax, ecx
    xor edx, edx
    div esi
    mov ecx, eax
    add edx, '0'
    dec edi
    mov byte [buffer + edi], dl
    cmp ecx, 0
    jne .loop

    test ebx, ebx
    jz .output
    dec edi
    mov byte [buffer + edi], '-'

.output:
    mov eax, 4
    mov ebx, 1
    mov ecx, buffer
    add ecx, edi
    mov edx, 19
    sub edx, edi
    int 0x80

    pop edi
    pop esi
    pop edx
    pop ecx
    pop ebx
    pop ebp
    ret