0

This is the output

I try to write a multiply code from c to assembly from 1 to 50 like:

1 MUL 1
2 MUL 2 

and so on but when its 4 MUL 4 doesn't give a right number it give me the character @.

I wrote it in assembly 8086 code can you help me to know where is the problem cause I am new at it

.MODEL SMALL
.DATA
Y DW 50 DUP (?) 
.CODE
MOV AX,@DATA
MOV DS,AX   
MOV WORD PTR SI,OFFSET Y
MOV Cx,1
L1:     
MOV Ax,Cx 
IMUL Ax  
ADD Ax,30H
MOV [SI],Ax
MOV Dx,[SI]
ADD SI,2         
MOV Ah,02H  
INT 21H 
INC Cx
CMP Cx,51
JE L2
JMP L1
L2:
.EXIT 
END
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
A.F312
  • 1
  • 1
  • The statement in the title conflicts with the content. Does it fail at 3x3 or 4x4? – Clifford Mar 12 '22 at 08:24
  • WHEN 4*4 IT GIVE A CHARACTER NOT NUMBER – A.F312 Mar 12 '22 at 08:25
  • 1) No need to shout. 2)If that is the case, clearly the required response is to correct the false statement in the title rather than repeat the question in a comment. – Clifford Mar 12 '22 at 08:28
  • The fact that it outputs a character is important information that you should include in the question, not a comment. You should also specify which character (clearly `@`). That information would confirm the veracity of my answer. – Clifford Mar 12 '22 at 08:37
  • i edit it could you see it and thanks – A.F312 Mar 12 '22 at 08:42
  • The title still needs correcting. What is hard to understand about that!? I have in any case answered the question already. If you need a solution, take a look at https://stackoverflow.com/questions/1922134/printing-out-a-number-in-assembly-language for example (not the accepted answer, but various solutions are presented that will suit). Int21,2 outputs a single character. For multiple digit results you need to output a _string_ (int21,9), and convert the integer to a decimal string. – Clifford Mar 12 '22 at 08:50
  • My apologies - I misread the title; it is fine. I have fixed other formatting issues with the post. – Clifford Mar 12 '22 at 08:57

1 Answers1

2

You appear to be adding 30h to the result to translate the value to an ASCII digit character. That wil clearly only work for single digit results 0 to 9.

It is not the multiplication that is in error, it is your output method that is flawed. Outputting a human readable result to the console is the most complex part of this task by far.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • IT DOESNT WORK I ADD TO THE RESULT – A.F312 Mar 12 '22 at 08:27
  • @a.f321 You appear to have a stuck caps key. Stop shouting. I know it does not work - this answer explains clearly why it does not work. It does not provide a solution - with respect, you did not ask for a solution, only an indication of the cause. – Clifford Mar 12 '22 at 08:32
  • iam sorry iam not shouting but i`ve tried to fix it and it don't be fixed – A.F312 Mar 12 '22 at 08:45
  • And as I pointed out, your question does not ask for a fix, only the cause. – Clifford Mar 12 '22 at 08:52
  • can you correct my code ? – A.F312 Mar 12 '22 at 09:27
  • @A.F312 I am no x86 assembly expert, and certainly not obsolete 16bit/DOS assembly. It is just easy to see where the issue is with only the bare minimum of read-only ASM skills. Besides your question asks _only_ "_help me to know where is the problem cause_" - you should perhaps ask a separate question about outputting an integer value to the DOS console, but clearly that would be a duplicate of the question I linked to in a previous comment. – Clifford Mar 12 '22 at 09:50
  • Also https://stackoverflow.com/questions/4244624/print-integer-to-console-in-x86-assembly – Clifford Mar 12 '22 at 09:59
  • https://riptutorial.com/x86/example/26199/ms-dos--tasm-masm--function-to-print-a-16-bit-number-in-decimal – Clifford Mar 12 '22 at 10:05
  • @A.F312: You asked basically the same question yesterday (https://stackoverflow.com/questions/71444362/trynna-write-a-multiply-code-in-assembly-8086), which I closed as a duplicate of [Displaying numbers with DOS](https://stackoverflow.com/q/45904075), then you deleted your question. That Q&A explains how to turn large integers into multi-digit ASCII strings. Go read it instead of taking up more of other people's time asking something that's already been answered. – Peter Cordes Mar 12 '22 at 11:36