954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

another addition with tasm

.model small
.stack 
.data
.code

start:
mov ah,1  
int 21h
mov ah,2
mov dl,0ah
int 21h
push ax
mov ah,1
int 21h
mov ah,2
int 21h
pop bx
add ax,bx
aaa
add al,30h
mov dl,al
mov ah,2
int 21h
end start

Ok guys?this is another addition program in tasm..
im using a different approach in adding 2 digits..
i was wondering why my 2nd input wont show even there is service 2,,can someone help me with this problem..thnks

jingo1126
Junior Poster in Training
57 posts since Aug 2009
Reputation Points: 10
Solved Threads: 1
 

You need something like the following. I did this in an editor so you'll have to debug it! Note the comments!

.model small
.stack 
.data
.code

start:
	mov ah,1  
	int 21h		; DOS - Read character from StdIn (Key)
		; al=char read

;	mov ah,2
;	mov dl,0ah	; WRITE LineFeed ????
;	int 21h		; DOS - Write character to StdOut
;		; NOTE: AL is now destroyed! as LineFeed was written!

;;; BASED upon your error, and this next push....
	mov	ah,2
	mov	dl,al
	int	21h

	push ax		; Save Old Character

	mov ah,1
	int 21h		; DOS - Read character from StdIn (Key)
		; al = char read

	mov ah,2
	int 21h		; DOS - Write character to StdOut

	pop bx		; Restore Old Character
		; al = 2nd char   bl = 1st char

; You aren't doing BCD so why are you using the instruction AAA ?

;;;	add ax,bx
;;;	aaa

	mov	ah,0
	add al,bl
	daa			; Decimal adjust  High Nibble, Low Nibble
                       ;ah=high digit, al=low digit

	mov	dh,al	; Save lower digit

	mov	dl,ah	; Upper digit
	add	dl,30h
	mov ah,2
	int 21h		; DOS - Write Digit Upper ASCII

	mov dl,dh	; Lower Digit
	add	dl,30h
	mov ah,2
	int 21h		; DOS - Write digit Lower ASCII



	end start
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

My mistake

Line #40 should be

;daa         ; Decimal adjust
aaa           ; Ascii adjust


daa puts result of two unpacked adds into upper nibble of al.
aaa adds the BCD (lower nibble) carry result onto the ah register. Why it needs to be pre-cleared.

wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

ok thanks wildgoose im gona try and debug..cheers

jingo1126
Junior Poster in Training
57 posts since Aug 2009
Reputation Points: 10
Solved Threads: 1
 

awts... is this code right?im troubled by this codes.. NEW kid in town.. just studied assembly..can any1 help me out? here is me e-add..

[email]lockheart_l@yahoo.com[/email]

fr0sts
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

sir can u make an assembly code that will add 2 input please?

Leeron2009
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You