Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello again, I am trying to read 2 one digit numbers and then sum them thorugh an assembly program. Thanks to you I am close to the end, but I still need to convert the chars into binary numbers..for this last reason , I found this code...can it help me? I understand that I need to brush up assembly before asking...so, I beg your perdon.
ASCII-Binary conversion in Assembly Language - ProjectsGeek[^]

What I have tried:

.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW ?
NUM2 DW ?
DOM1 DB 'digit the number: ',13, 10 , '$'
DOM2 DB 'digit the other one: ',13, 10 , '$'
RIS1 DB 'the sum: ', 13,10, '$'
SOMMA DW ?
.CODE
.STARTUP
MOV AX, @DATA
MOV DS, AX
MOV AH, 09H
MOV DX, OFFSET DOM1
INT 21H

    MOV AH, 01H
INT 21H
XOR AH,AH  
SUB AL,'0' 
MOV NUM1,AX


MOV AH, 09H
MOV DX, OFFSET DOM2
INT 21H






MOV AH, 01H
INT 21H
XOR AH,AH  
SUB AL,'0' 
MOV NUM2,AX


MOV AL, NUM1
MOV AL, NUM2
MOV SOMMA, AL 

MOV AH, 09H
MOV DX, OFFSET RIS1
INT 21H



MOV AH, 09H
MOV DX, OFFSET RIS1
INT 21H
 


MOV AH,02H
MOV DL, SOMMA
INT 21H

MOV AH, 40H
INT 21H 

END
Posted
Updated 2-Oct-22 7:08am
Comments
Afzaal Ahmad Zeeshan 2-Oct-22 10:55am    
For questions regarding the code, maybe it is best to check with the author on the website where you found it. :)

You're doing this all wrong. You're searching the internet for code that you think will do what you want when you should be thinking about the problem and looking at the data you're getting.

Hint: What are the ASCII values of the characters you're getting from the user?
 
Share this answer
 
v2
Comments
Member 15784866 2-Oct-22 11:13am    
to be honest, I barely understand the question.. the first ten numbers should be the same, in ex and in the binary form...well, I have to read the assembly's basics again...thank you anyway.
Dave Kreskowiak 2-Oct-22 11:18am    
What's hard to understand? You show a prompt for a number and get A CHARACTER from the user. You show a prompt for another number and get that CHARACTER from the user. You then do some very simple math to convert those characters to their numerical equivalents. What's the ASCII value for '0'? What's the ASCII value for '9'? How would do a little math on those values to get them to be actual values for 0 and 9?
Member 15784866 2-Oct-22 11:28am    
beh as I said, the ASCII value for '0' is always 00h, and Null as code, , and 9 becomes 09h and HT as code. This program is supposed to add two one digit numbers, and the risult should be kept until 9. This is my first goal, then I will improve it. Unfortunately I didn't catch the last question
Dave Kreskowiak 2-Oct-22 11:49am    
The ASCII value for '0' is not 0. You might want to Google for "ASCII chart".

Your code is getting the correct values from the keyboard and converting them to the proper values for the calculation. After that, your code makes no sense at all. Your problems start here:

MOV AL, NUM1MOV AL, NUM2MOV SOMMA, AL
You might want to seriously think about what you're doing in those three statements. If you don't know what those statements are doing, I seriously doubt you wrote the code above them.
How many times must I point out:
ASM
MOV AL, NUM1
MOV AL, NUM2
MOV SOMMA, AL 

Please read your code and think what it is supposed to be doing. The above code does not add two numbers together. And what follows is just random instructions.
 
Share this answer
 
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW ?
NUM2 DW ?
DOM1 DB 'digit the number: ',13, 10 , '$'
DOM2 DB 'digit the other one: ',13, 10 , '$'
RIS1 DB 'the sum: ', 13,10, '$'
SOMMA DW ?
.CODE
.STARTUP
MOV AX, @DATA
MOV DS, AX
MOV AH, 09H
MOV DX, OFFSET DOM1 ; showing the question
INT 21H

MOV AH, 01H
INT 21H
XOR AH,AH  
SUB AL,'0' 
MOV NUM1,AX


MOV AH, 09H
MOV DX, OFFSET DOM2 ; showing the question
INT 21H

MOV AH, 01H
INT 21H
XOR AH,AH  
SUB AL,'0' 
MOV NUM2,AX


MOV AL, NUM1
MOV AH, NUM2  
ADD AL,AH    ; effective sum
MOV AL, 48
MOV DL, AL
MOV AH,02H     ; showing the result
INT 21H
MOV AH, 4CH    ; going back to DOS
INT 21H


END
 
Share this answer
 

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