I'm trying to convert string to decimal and then add all the numbers up to that decimal(for example if number is 5, i need to add 1+2+3+4+5) and then print that number after converting it back to decimal.
I'm trying below steps, code is not complete, till now im just converting string to decimal and checking if it got converted, there is some error
title fill in title
;------------------------------------------------------------------------------
stacksg segment para stack 'Stack'
db 32 dup(0)
stacksg ends
;---------------------------------------------------------------------------------------------
datasg segment para 'Data'
paralst label byte
maxlen DB 20
actlen DB ?
indata DB 20 dup ('$')
strout DB "Enter a number between 1 and 20: $"
errors DB "USER ERROR$"
sum DB "The sum is: $"
datasg ends
;-----------------------------------------------------------------------------------
codesg segment para 'Code'
main proc far
assume ss:stacksg, ds:datasg, cs:codesg
mov ax, datasg ;initialize data segment registers
mov ds, ax
mov es, ax
MOV AH, 06H
MOV AL, 0
MOV CX, 0 ; ch-row, cl-columns
MOV DH, 79
MOV DL, 79
MOV BH, 01000000B
int 10H
Mov AH, 02H
MOV BH, 00H
MOV DH, 12 ; or mov dx 0c28h
MOV DL, 25
INT 10H
MOV AH, 09H
LEA DX, STROUT
INT 21H
Mov AH, 0AH
LEA DX, paralst
int 21H
;converting string to decimal
CALL READ_NUM
READ_NUM Proc Near
push BX
push CX
push DX
LEA BX, indata
Mov AX, 0
Mov CX, 0
Mov DL, 10
again:
MOV CL, [BX]
CMP CL, 0DH
JE THEEND
SUB CX, 30H
MUL DL
ADD AX, CX
INC BX
THEEND:
POP DX
POP CX
POP BX ; conversion complete
CMP AX, 20 ; since converted decimal is in AX,
; i am checking if it is over 20 or below 1....
; there is where i get error.
JG ERRS
CMP AX, 1
JL ERRS
mov ax, 4c00h
int 21h
MOV DX, 0
MOV CX, 1
TOPPY:
CMP DX, AX
JG ENDDY
ADD CX, DX
INC DX
JMP TOPPY
ERRS:
Mov AH, 02H
MOV BH, 00H
MOV DH, 15 ; or mov dx 0c28h
MOV DL, 25
INT 10H
MOV AH, 09H
LEA DX, errors
INT 21H
mov ax, 4c00h
int 21h
ENDDY:
Mov AH, 02H
MOV BH, 00H
MOV DH, 16 ; or mov dx 0c28h
MOV DL, 25
INT 10H
MOV AH, 09H
LEA DX, sum
INT 21H
mov ax, 4c00h
int 21h
Ret
READ_NUM endp
main endp ;end of procedure
codesg ends ;end of code segment
end main ;end of program