EDIT: okay, there's the code:
global _start
section .text
_start:
; presetting variables
mov [rev_ans], byte 0
mov [multiplier], byte 1
; square of num
mov eax,31
mov ebx,eax
mul ebx
mov [left_num],eax
; know the digits count of the answer
mov [digit_count_left_num],eax
call digit_num
; convert into ascii digits and store one by one reversed
call reverse_ans
; print
mov eax, [rev_ans]
mov [left_num], eax
call print_ans
; exit
mov eax,1
mov ebx,0
int 80h
reverse_ans:
; restoring eax data
mov eax,[left_num]
mov edx,0
mov ebx,10
div ebx
; moving left number (undisplayed yet) into left_num
mov [left_num],eax
; building reversed answer integer
mov eax,[multiplier]
mov ecx,edx
mov edx,0
mul ecx
add [rev_ans],eax
; incrementing the multiplier
mov eax,[multiplier]
mov ebx,10
mov edx,0
div ebx
mov [multiplier],eax
; repeating process for other digits
cmp [left_num], byte 0
jg reverse_ans
ret
print_ans:
; restoring eax data
mov eax,[left_num]
mov edx,0
mov ebx,10
div ebx
mov [ans],edx
; converting into ascii digit
add [ans], byte 0x30
; moving the number which is left (undisplayed yet) into left_num
mov [left_num],eax
; print
mov eax,4
mov ebx,1
mov ecx,ans
mov edx,1
int 80h
; repeating process for other digits
cmp [left_num], byte 0
jg print_ans
ret
digit_num:
; increment multiplier
mov eax, [multiplier]
mov ebx,10
mov edx,0
mul ebx
mov [multiplier],eax
; check
mov eax,[digit_count_left_num]
mov ebx,[multiplier]
mov edx,0
div ebx
; updating the number which was left after division
mov [digit_count_left_num],eax
cmp eax, byte 0
jg digit_num
ret
section .bss
ans resb 256
digit resb 256
left_num resb 256
digit_count_left_num resb 256
rev_ans resb 256
multiplier resb 256
My program takes a hardcoded decimal number, squares it, and prints the answer on the screen. Everything works just fine if I give it a number, whose square is less than 1000. For example: I give it 2, it says 4;I give 31, it says 961. When I give it 32, it just prints 1 (where the answer should be 1024). When I input 65, the answer should be 4225, but appears as 0.
Also, I noticed a strange behavior: inputting 20 (and expecting 400) I get only 4. Giving 10 also results in just 1 instead of 100. Giving 30 outputs 9.
A couple of things to mention:
While swapping the data between variables, at quite a few times I used general purpose registers (which are 32 bits in size) to temporarily store those variables' data. I thought that this could be an issue, but then I remembered that the maximum integer these registers can hold is over 4 billion! And my numbers are going just over a thousand!
All my variables in this program were reserved and not pre-initiated. For each variable I reserved 256 bytes in memory.