1

I'm started 30 hours ago on learning assembly and I'm trying to do a activity, I can run some of the code but I cannot print the sum of the two numbers, whats wrong with my code?

this is my current output

Enter First Number:
Enter Second Number:

but the some wont print

here is my code

.MODEL small
.STACK 100h
.DATA

        operation db, 13, 10, "Addition $"
        message1 db 13, 10, "Enter First Number: $"
        message2 db 13, 10, "Enter second Number: $"
        message3 db 13, 10, "Sum: $"
        newline db 13, 10, "$"

        nameinput label byte
        maxnamelen db 50
        curnamelen db ?
        namefield db 50 dup(?)

.CODE
start:
        mov ax, @data
        mov ds,ax

        mov ah,09h
        mov dx, offset operation
        int 21h

        mov ah, 01h
        int 21h

        cmp al, '1'
        je Addition

        Addition:
        mov ah, 09h
        mov dx, offset message1
        int 21h
        mov ah, 01h
        int 21h

        mov ah, 09h
        mov dx, offset newline
        int 21h

        mov ah, 09h
        mov dx, offset message2
        int 21h
        mov ah, 01h
        int 21h

        add al, bl
        mov ah, 09h
        mov dx, offset newline
        int 21h

        mov ax, 4c00h
        int 21h

        END
  • If you need to capture a number from keyboard as string then convert it to numeric, make some math on it, then convert the numeric into string to display it, this answer contains two procs : string2number and number2string = http://stackoverflow.com/questions/30243848/assembly-x86-date-to-number-breaking-a-string-into-smaller-sections/30244131#30244131 – Jose Manuel Abarca Rodríguez Apr 19 '16 at 16:30

1 Answers1

1

You are reading ascii characters and not converting them in numbers. I don't see the part where you try to write the result (beware, this works only if there is no carry! 9+2 -> ascii ';')

    mov dx, offset message1
    int 21h
    mov ah, 01h
    int 21h
    mov bl,al   ; save what you read
    sub bl,48   ; subtract '0'
    ...
    add bl,al   ; won't subtract '0' from second number... (save in bl)
    mov ah, 09h
    mov dx, message3
    int 21h
    mov ah, 02  ; print dl
    mov dl,bl   ; get value
    int 21h     ; ...because you would add '0' to print
Exceptyon
  • 1,584
  • 16
  • 23