Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good evening! I have brushed up my old knowledge of assembly and I am close to the solution of this problem. I am going to sum two numbers. It works with one digit but it fails with two. I got lost again..if someone could help, I would really appreciate it. Thanks again. PS I wanted to delete my old posts but I didn't catch how to do that.

What I have tried:

.MODEL SMALL
.STACK 100h
.DATA
PRE1 DB 'digits of the number: ', '$'
DOM1 DB 'digit the first number: ', '$'
PRE2 DB 'digits of the second number: ', '$'
DOM2 DB 'digit the second number:  ', '$'
RISP1 DB 'the sum is: ', '$'   
VISUALIZZA DB 'you digited: ', '$'
ACAPO DB 13,10, '$'
NUM1 DB ?
NUM2 DB ?
CIFRE DB ?
BASE DB 10
CONT DB 0
 
.CODE
STAMPA MACRO frase
MOV AH, 09H   
LEA DX, frase
INT 21H
ENDM

.STARTUP
MOV AX,@DATA
MOV DS, AX
STAMPA PRE1
MOV AH, 01H
INT 21H       ;acq the number of digits 
MOV CIFRE, AL   

STAMPA ACAPO
STAMPA DOM1

MOV AH, 01H
INT 21H      ;acq first digit 
SUB AL, 30H            



CMP CIFRE, '2'
; it s OK here
JE DOPPIA
MOV NUM1, AL   
JMP SECONDO


  

DOPPIA: MUL BASE 

MOV BH, AL 
INT 21H     

MOV AH, 01H
INT 21H       ; 2° num 
SUB AL, 30H
MOV BL, AL   
MOV BL, BH  
MOV BH, 0

STAMPA ACAPO 
MOV NUM1, BL 

; parte aggiunta dopo
SUB AL, 30H ; transformation 
MOV DL, AL ;
ADD BL, BH ; sum to get the first number 
MOV BH, 0 ; clear 
STAMPA ACAPO
MOV NUM1, BL 
    
    
STAMPA ACAPO    
 
 
  
  
;prove 1
MOV CL, NUM1



CICLO0: MOV AL, CL 
MOV AH, 0
DIV BASE
MOV BL, AH   ; save the rest in BL
MOV CL, AL     ; quotient 

ADD BL,30H         ;TRASFORMA IL RESTO IN CHAR
MOV BH, 0
PUSH BX
;MOV AH, 02H
;MOV DL, BL 
;INT 21H        ;VISUAL
INC CONT  
 
CMP CL, 0        ;if it's not over..
JNE CICLO0 

WHILE: CMP CONT, 0
JE ESCIW
POP DX 
MOV AH, 02H
INT 21H
DEC CONT
JMP WHILE

ESCIW: NOP

STAMPA ACAPO
; let's go with the second number
SECONDO: 

STAMPA ACAPO   
STAMPA PRE2
MOV AH, 01H
INT 21H   

MOV CIFRE, AL   

STAMPA ACAPO
STAMPA DOM2

MOV AH, 01H
INT 21H  ; reading the first digit
SUB AL, 30H ; conversion 



CMP CIFRE, '2'
JE DOPPIA1
MOV NUM2, AL
JMP SOMMA


DOPPIA1: 
MOV AH, 0 
MUL BASE 
MOV BH, AL  
INT 21H     

MOV AH, 01H
INT 21H   ; reading the next 
SUB AL, 30H    
MOV BL, AL
MOV BL, BH  
MOV BH, 0

STAMPA ACAPO 
MOV NUM2, BL      


;prova 2
STAMPA ACAPO    

 
  
  
;prova 1
MOV CL, NUM2


CICLO1: MOV AL, CL 
MOV AH, 0
DIV BASE
MOV BL, AH   
MOV CL, AL   

ADD BL,30H   
MOV BH, 0
PUSH BX
;MOV AH, 02H
;MOV DL, BL 
;INT 21H        ;VISUALIZZ
INC CONT  
 
CMP CL, 0     
JNE CICLO1 

while1: CMP CONT, 0
JE ESCIW1
POP DX 
MOV AH, 02H
INT 21H
DEC CONT
JMP WHILE1

ESCIW1: NOP  



SOMMA:  
STAMPA ACAPO  
STAMPA RISP1 
MOV CL, NUM1 
ADD CL, NUM2 
 
CICLO: MOV AL, CL 
MOV AH, 0
DIV BASE
MOV BL, AH   
MOV CL, AL   

ADD BL,30H   
MOV BH, 0
PUSH BX
;MOV AH, 02H
;MOV DL, BL 
;INT 21H        ;VISUALIZZ
INC CONT  
 
CMP CL, 0        
JNE CICLO 

whileS: CMP CONT, 0
JE FINE
POP DX 
MOV AH, 02H
INT 21H
DEC CONT
JMP WHILES

FINE: NOP
     
MOV AH, 4CH
INT 21H
END
Posted
Updated 6-Oct-22 0:45am
Comments
OriginalGriff 5-Oct-22 15:42pm    
You can't delete questions that have answers; that is by design and part of the ideology of the site. This isn't an "individual tutoring" site, it's about sharing and communicating information with everybody, not just a single individual.
Member 15784866 5-Oct-22 17:01pm    
I understand it and I thank you for your reply. I promise that I'm going to stop posting about this problem. I really don't want to monopolize the site.
OriginalGriff 5-Oct-22 17:41pm    
That's not a problem - you aren't monopolising the site. It's the "deleting questions" that you can't do because that removes info that might help others.
Dave Kreskowiak 5-Oct-22 19:06pm    
If you have .STARTUP in your code, you do not need to do this:
MOV AX,@DATA
MOV DS, AX

.STARTUP sets the data segment register for you if you have a .DATA block in your code.
Dave Kreskowiak 5-Oct-22 19:52pm    
This is fun. I haven't played with Intel x86 Assembly in a really long time.

Why is your code 3 times longer than mine? Because you're not using functions to do repetitive work, like outputting a string or getting a character from the input stream.

1 solution

Hi Dave! many thanks! unfortunately I couldn't see your code, is it somewhere here in this site? I saw your hint, MOV AX,@DATAMOV DS, AX, but my problem is in the loop..I am pretty sure but I still don't understand where exactly..
 
Share this answer
 
Comments
Richard MacCutchan 6-Oct-22 6:52am    
You need to learn about the use of subroutines for repetitive processes. You also need to understand that when a number is greater than 9 you need to do some mathematics to generate each digit of the answer. The emu8086 emulator has good examples of both.

I also suggest you go back to your question at How can I correct this code?[^], and read again my suggestions.
Member 15784866 6-Oct-22 8:20am    
Hi Richard! yes, I took into account that the number can be greater than 9, it is the part called "doppia"/"doppia1" but it doesn't work properly anyway...when the number consists of 2 digits..something is missing to me. I'm using emu8086 indeed.
Richard MacCutchan 6-Oct-22 9:43am    
As I said in my comment the emu8086 emulator has sample code with the answers you need. You will learn much faster if you go and work through all the samples.
Dave Kreskowiak 6-Oct-22 8:23am    
First, you posted your comment to me as a solution to your own question, so I never received a notification that you responded.

Next, I never showed you my code. That would be me doing your work for you. If I did that, you wouldn't learn how to solve problems because it removes you from thinking about the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900