1 Replies - 1926 Views - Last Post: 10 October 2012 - 03:30 PM

#1 kim92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-October 12

Extending a program adding two numbers

Posted 10 October 2012 - 07:29 AM

Greetings. Currently learning assembly myself (used tutorials), and I'm well on my way; but I just discovered that I don't seem to be able to add larger numbers (like 20+92 e.g) in this piece of code. How do I solve it? I reckon something isn't right in the Readdigit section but I'm not entirely sure how to attack this problem.

So asking for help here. Hope it's not too much trouble.

Thank you!

;Indata Program reads two digits separated with one or more spaces
;Outdata Program writes the sum of the two digits
	cr equ 13 ;Carriage return
	lf equ 10 ;Line feed

segment stack stack
	resb 64 ; Setter av 64 byte

segment data
Msg	db "Write two onedigit numbers separated with spacing",cr,lf,"$"
	db "Summen av de to tallene maa vaere minder enn 10.",cr,lf,"$"
Errormsg db cr,lf,"Skriv kun sifre!",cr,lf,"$"
Sl 	db cr,lf,"$"

;Codesegment with program
segment code
..start: mov ax,data
	mov ds,ax
	mov dx,Msg
	mov ah,09h
	int 21h
;Numbers written are returned in dl.
;Successful return if dh=0.
	call Readdigit
	cmp dh,0 	;Test if successfully read
	jne End 	;Jump to completion if error
			;i innlesningen
	mov ch,dl 	;First digit stored in reg ch
	call Readdigit 	;Read second digit
			;successful: dh=0, number in dl
	cmp dh,0 	;Test if successful read
	jne End
	mov cl,dl 	;Second digit stored in reg cl
	call Newline
	add cl,ch 	;sum in cl
	mov bl,10
	mov al,cl
	mov ah,0	
	div bl
	mov dl,al
	call Writedigit ;Print value in dl as one digit
	mov dl,ah
	call Skrivsiffer ;Print value in dl as one digit
End: 	mov ax,4c00h 	;Exit program
	int 21h
;; Writes the digit stored in dl. No check on valuearea.
	push ax
	push dx
	add dl,"0" ;converter tall til ascii.
	mov ah,02h ;Skriv ut tegnet
	int 21h
	pop dx
	pop ax

;; Search past all blank and next non-blanks.
;; Next non-blank returns in dl
	push ax
;; Reads a symbol from the keyboard
	mov ah,01h
	int 21h
	cmp al, " "
	je Loop
	cmp al,"0" ;Check that symbol is in the area of 0 - 9
	jb Error
	cmp al,"9"
	ja Error
	mov dl,al
	sub dl,"0" ;Convert ascii to number.
	mov dh,0 ;Signalize succesful input
	pop ax
	ret ;Successful return
	mov dx,Errormsg  ;
	mov ah,09h
	int 21h
	mov dh,1 ;Signalize failed number readings
	pop ax
	ret ;Failed return

;Move cursor to the left on the next line.
	push ax
	push dx
	mov dx,Sl
	mov ah,09h
	int 21h
	pop dx
	pop ax

;;End Start

Is This A Good Question/Topic? 0
  • +

Replies To: Extending a program adding two numbers

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon

Reputation: 856
  • View blog
  • Posts: 2,248
  • Joined: 28-March 11

Re: Extending a program adding two numbers

Posted 10 October 2012 - 03:30 PM


Currently learning assembly myself

As I ask all new folks to Assembly, why are you learning old antiquated 16bit DOS Assembly? You would do yourself a favor to learn 32bit Assembly (then even 64bit later on).

What is this TASM? Line 72, you have je Loop but yet you do not have a label named Loop, you have Lokke. Also, Loop is a mnumonic, so I would not use that as a label name. I do not see you adding anything, all I see you doing is converting a number to ASCII. I need to know what Assembler it is in order to see Assemble to see the outcome you are having a problem with.

*** Edit ***
You are reading 1 character at a time, in order to use more than one digit at a time, you need to read the characters into a buffer and go from there. Maybe Int 21/AH=0Ah
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1