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
3
  • Search for "multi-digit number" in the FAQ section of stackoverflow.com/tags/x86/info Commented Jun 18, 2020 at 1: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 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. Commented Jun 18, 2020 at 3:24
  • 1
    @PeterCordes - I missed that in GCMDP. I deleted my prior comment, and will delete this comment later. Commented Jun 18, 2020 at 3:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.