0

I'm having difficulties in solving this Assembly Language problem. If anyone can explain on how to do this, I really appreciate it. Thank you.

Instructions: Extend the program add to enable the addition of 2 decimal values that result in printing the decimal value.

Expected output:

add 8 7

15

add 12 99

111

Code:

ASSUME DS:MYDATA,CS:MYCODE
MYDATA  SEGMENT     
x       DW      ?
y       DW      ?
z       DW      ?
buf     DW      ?
MYDATA  ENDS
MYCODE  SEGMENT
MAIN    PROC    
        MOV AX,SEG MYDATA
        MOV ES,AX
        CALL GCMDP  
        MOV AX,SEG MYDATA 
        MOV DS,AX
        MOV AX,X    ;  DS:[X]
        MOV BX,Y
        ADD AX,BX
        MOV z,AX
        CALL PRNINT
        MOV AH,4CH
        INT 21H
MAIN    ENDP    
GCMDP   PROC
        MOV SI, 80H
        LODSB           ; DS:[SI] --> AL  SI = SI +1 
        MOV CL,AL
        MOV CH,0
L1:     LODSB
        CMP AL,20H
        JE L1
        SUB al,'0'      ; '0' = 30H = 48
        MOV ah,0        ; ensures AX = AL  =  00AL
        MOV ES:[x],AX
L2:     LODSB
        CMP AL,20H
        JE L2
        SUB al,'0'      ; '0' = 30H = 48
        MOV ah,0        ; ensures AX = AL  =  00AL
        MOV ES:[y],AX       
        RET
GCMDP   ENDP
; prints the value of the int in the standard output
PRNINT  PROC
        ADD AX,30H
        MOV DL,AL
        MOV AH,2
        INT 21H
        RET
PRNINT  ENDP
MYCODE  ENDS
        END     MAIN
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Search for "multi-digit number" in the FAQ section of https://stackoverflow.com/tags/x86/info – Peter Cordes Jun 18 '20 at 01:56
  • @rcgldr: Parsing the command line is a part of the problem that's already solved by the code in the question with `lodsb` / `cmp al, 20h`/`je`. And [my answer](https://stackoverflow.com/a/49548057/224132) on the string->number question has a loop that stops at the first non-digit, so it's all set for use as a stop-on-spaces parser. – Peter Cordes Jun 18 '20 at 03:24
  • 1
    @PeterCordes - I missed that in GCMDP. I deleted my prior comment, and will delete this comment later. – rcgldr Jun 18 '20 at 03:33

0 Answers0