ok
im kinda new to this forum and new to assembly as well.
i was given a homework on tasm if someone could help me fix or add or delete some codes in wat ive place thank you very much..
program is about adding two input charactars like 1+1=2. ive been figuring this thing for 3 days still cant get it..my teacher didnt even showed us the add command so i jst made it up myself..
my code is

.model small
.stack 100h
.data
.code
start:
mov ah,1h ; input number
int 21h
mov dl,0ah
mov ah,1h ; input number
int 21h

mov dl,0ah

mov ah,2h
add bx,ax  ; sum of the first input
int 21h

mov ax,4c00h
int 21h
end start

Recommended Answers

All 8 Replies

Actually your code needs work. Compare what you have to the following...

.model small
	.stack 100h
	.data
	.code

start:
	mov ah,1	; input character from keyboard (with echo)
	int 21h   ; DOS Interrupt
		; al = character

	mov dl,al		; Save character 

	mov ah,1		; input character from keyboard
	int 21h    ; DOS Interrupt

		; dl = 1st char, al = 2nd char  (DIGIT)
		; ASSUMING only digits were entered!
	sub	dl,'0'		; 0...9 <--  '0'...'9'
	sub	al,'0'		; 0...9 <--  '0'...'9'

	add	dl,al		; 0...18

; I'm going to let you work out the code to handle the result > 9

; NOTE:  I've omitted something here!
;   Won't work without it! Can you figure it out?

		; dl has ASCII digit
	mov ah,2h
	int 21h			; DOS - Display Ouput (char)

	mov ax,4c00h	; Terminate Process with return code (0)
	int 21h     ; DOS Interrupt


	end start

Aww, and I was hoping they might have to figure out the sub al,'0' thing for themselves....

Please of better titles, not things like: HELP, Error, help with..., but your problem in the title, just to be better for the other users.
Thanks!

:)
thnks for the help guys..
i already figured it out on how to do it the code for the conversion symbol to interger is

add dl,'0'

..correct me if im wrong though.. btw sorry for the title..ill make a better one next time

AH, but I left the easy one! Now fix your own assignment. Modify the code to properly handle the addition of any two digits or it isn't a proper solution!

rofl...thnx man..
but i cant get why the sum of two digits becomes a symbol its like tasm is very far form c++..
uhmm do i have to use another register for it or an interrupt would solve the problem?i have another question.. i wanted to add a linefeed like

.model small
.stack 100h
.data
.code
start:

mov ah,1                    ;input digit
int 21h                        ;ax = character
mov dl,0ah                  ;linefeed
mov dx,ax                   ;save character
mov ah,1                    ;input character
int 21h  
                                  ;dx=first char ax=2nd char
mov dl,0ah                  ;linefeed
sub dx,'0'                 ;1,2,3,4,5.....9
sub ax,'0'                 ;1,2,3,4,5.....9
add dx,ax                   ;0......18
add dx,'0'                 ;convert char and symbol to integer
mov ah,2h                  ;output
int 21h
mov ax,4c00h             ;exit
int 21h
end start

how come it change the answer to symbol?is there anyway i can fix this?

You need to look at my original code post again. You are inputing an ASCII character then storing a 0Ah (Line Feed) character. The DOS input character returns the character in register AL.
If trying to expand it to 16-bits (which you don't need to do with your particular solution) is to merely set the upper bits then temporarily store it, or vice-versa.
One of the following will work on all the 80x86 family processors.
mov ah,0
xor ah,ah
Convert from ASCII to decimal, then move it out of the way.

Then do it again.

Sum your 16-bit values (which you really don't need 16-bit because 0...9 + 0...9 is 18. Unsigned you have a limit of 255 in a single byte.

To convert from decimal to string you would normally use a loop, but you only have up to two digits.

d = n / 10
if (d <> 0) print d as ASCII digit.
n = n mod 10
print n as ASCII digit

Eventually you should enter this as an ASCII string then convert the string to a decimal number, do the math, the convert from a decimal number back to a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.