Ha...problem solved.
The problem was in the macro print.I was doing:
%macro sys_print 2
mov al,4
mov bl,1
mov edx,%2
lea ecx,[%1]
int 80h
%endmacro
Instead of:
%macro sys_print 2
mov eax,4
mov ebx,1
mov edx,%2
lea ecx,[%1]
int 80h
%endmacro
Ha...I'll correct the code...
Corrected code:
%include "sys_macros.inc"
;Macros
%macro ulj 4
cmp %1,%2
jl %4
cmp %1,%3
jg %4
%endmacro
%macro check_val 0
cmp bl,00h
je %%check_done
sub bl,'0'
ulj bl,0,9,%%invalid_value
jmp %%check_done
%%invalid_value:
sys_print invalidValue
sys_exit 0
%%check_done:
nop
%endmacro
;Program
section .data
msg1:
db "Exercicio - somador de 0 a n.", 0Ah, 0Ah
db "Digite n [0 a 999]:"
msg1_l: \
equ $ - msg1
invalidValue:
db "Digite um valor de 0 a 999!", 0Ah
invalidValue_l: \
equ $ - invalidValue
msg2:
db "Resultado da soma:"
msg2_l: \
equ $ - msg2
section .bss
n_s: resq 1
res: resb 7
section .text
global main
main:
sys_print msg1
sys_read n_s,4
mov ebx,dword [n_s]
mov dl,4
sub dl,al
mov al,dl
mov dl,8
mul dl
mov cl,al
shl ebx,cl
check_val
mov al,bl
mov cl,100
mul cl
mov dx,ax
ror ebx,8
check_val
mov al,bl
mov cl,10
mul cl
add dx,ax
ror ebx,8
check_val
mov al,bl
movzx ax,al
add dx,ax
mov ax,dx
movzx ecx,dx
mul dx
mov bx,ax
rol ebx,16
mov bx,dx
rol ebx,16
add ebx,ecx
mov edx,0
mov eax,ebx
mov ebx,2
div ebx
mov ecx,eax
mov ebx,100000
div ebx
add al,'0'
mov byte [res],al
mov eax,edx
mov edx,0
mov ebx,10000
div ebx
add al,'0'
mov byte [res+1],al
mov ax,dx
mov dx,0
mov cx,1000
div cx
add al,'0'
mov byte [res+2],al
mov ax,dx
mov cl,100
div cl
add al,'0'
mov byte [res+3],al
movzx ax,ah
mov cl,10
div cl
add al,'0'
mov byte [res+4],al
add ah,'0'
mov byte [res+5],ah
mov byte [res+6],0Ah
sys_print msg2
sys_print res,7
sys_exit 0