0

i`ve tried to write a code that take two digit number from user and multiply it by 9 then display the result : first digit is 1 then second digit is 1 so it will be 11 * 9 =99 but it give another number this is my code :

.MODEL SMALL
.DATA 
NUM1 DB ?
NUM2 DW ? 
NUM3 DB ?
NUM4 DB ?
RESULT DW ?
.CODE
MOV AX,DATA
MOV DS,AX 


L1:MOV AH,1
INT 21H
SUB AL,30H
MOV dl,10
MUL dl
MOV NUM1,AL


L2:MOV AH,1
INT 21H
SUB AL,30H 
ADD AL,NUM1
AAM
ADD AH,30H
ADD AL,30H 
MOV dx,AX


L3: 
MOV Bh,9
MUL Bh
MOV BL,AL
MOV BH,AH
MOV AH,2
MOV DL,al
INT 21H
MOV AH,2
MOV DL,bh
INT 21H
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
AdYa
  • 1
  • 1
  • 1
    You are thinking in a way complicated way to print a number. Try printing any positive number in C with just `putchar`. It's a very simple algorithm. Once it works implement that in assembly. – xiver77 Mar 14 '22 at 16:52
  • i cant use c language and i dont now how to use it – AdYa Mar 14 '22 at 17:01
  • @xiver77 I just want to write it in assembly not any language – AdYa Mar 14 '22 at 17:16
  • 1
    The only instructions you need in order to transform an integer to string in assembly is `mov`, `add`, `mul`, `div`, `cmp`, `jxx` (`jmp`, `je`, `jb`, etc.). It's also possible to do it without `mul`. It's one of the simplest algorithms to implement compared to any complex programs you might have to write. I really recommend doing it yourself rather than waiting for somebody else to do it for you. – xiver77 Mar 14 '22 at 17:21
  • `mul` produces a binary integer, not two ASCII digits. You got this right earlier, when combining two ASCII digits into a single integer (ending with `ADD AL,NUM1`, and then for some reason splitting it into decimal digits with AAM *before* multiply), but then in L3: you're just using the low and high 8 bits of the integer product as ASCII codes, with no attempt to split it up into decimal digits. See [Displaying numbers with DOS](//stackoverflow.com/q/45904075). And single-step your code with a debugger. It seems like you put the `mul` by 9 to late, after you'd already split into digits – Peter Cordes Mar 14 '22 at 17:44
  • BTW, I closed this before noticing the code before the `mul` by 9 that messed up the integer you were multiplying. But if you understood what the `aam` and adding `30h` was doing, you wouldn't have put the mul in the wrong place. So it's still close enough for a question with no debugging details (register values from a debugger), or even the actual output as part of the [mcve]. Or any comments about why you put these instructions in this order. – Peter Cordes Mar 14 '22 at 17:56

0 Answers0