0

I have a program, that multiplies two numbers, and all works, but on the screen, I saw this. Can you suggest to me, what to do, so my program printed decimal value (eg. 24) Code:

section .text
   global _start

_start:
   ; 3 x 8
   mov ax, 3
   mov bl, 8
   mul bl
   mov [res], al
   mov edx,len
   mov ecx,msg
   int 0x80
   mov eax,4
   mov ebx,1
   mov edx,1
   mov ecx,res
   int 0x80
   mov eax,1
   int 0x80

section .data
   res db 0  

I use NASM Compiler, WSL Ubuntu 18.04, and ld (ld -m elf_i386 -s -o multiply multiply.o)

oleg002
  • 3
  • 4
  • 1
    The byte `res` contains 24, i.e. 0x18 which is nonprintable (invisible) character CANCEL. When you want it printed as **24**, [convert](https://stackoverflow.com/questions/28524535/add-2-numbers-and-print-the-result-using-assembly-x86/28524951#28524951) it from binary to decimal digits. – vitsoft Mar 23 '23 at 20:53
  • 1
    In some (many) environments all you can do is print ascii characters. So, if you want to print a number you have to output ascii digit characters, maybe more than one. That take an algorithm, to decompose the number into single digits. Such algorithm uses math, like modulus and division to extract individual digits numerically, then convert those individual digits to ascii digits. For example, if you know you have a two digit decimal number (in binary) then extract the first decimal digit using divide by 10, and extract the second decimal digit using modulus by 10. – Erik Eidt Mar 24 '23 at 01:17
  • What is `mov edx,len` `mov ecx,msg` `int 0x80` going to do without having specified a function number in EAX? AX==24, but other than that, who knows? – Sep Roland Mar 26 '23 at 09:52

0 Answers0