I am trying to make a calculator in assembly. You introduce two variables and then you choose the operation. Now the operation is only addition. I am working only with BIOS interrupts, no DOS. Can someone explain to me how to make it? I have two problems and I am stuck with them:
- The first problem is when I add 5+6 for example it returns 59(48+11) in ASCII. I think a solution would be to print in decimal but I found nothing on the internet using only BIOS interrupts.
- The second problem is that when I add 49+59 it returns 9, so it adds the first characters only.
Code:
    firstVariableKeyboard: ;store in var1 first variable
        mov ah,0x0
        int 16h ;keyboard interrupt
        cmp al,0x0d
        je returnEnter
        mov ah,0eh ;tty mode
        int 10h
        mov byte [var1 + bx],al
        inc bx
        jmp firstVariableKeyboard
    secondVariableKeyboard: ;store in var2 second variable
        mov ah,0x0
        int 16h
        cmp al,0x0d
        je returnEnter
        mov ah,0eh
        int 10h
        mov byte [var2 + bx],al
        inc bx
        jmp secondVariableKeyboard
   equalMath:
        ;introduce first variable
        mov si,math_description0
        call printString
        mov bx,0
        call firstVariableKeyboard
        mov dl,[var1]
        ;conversion from ascii to decimal
        sub dl, '0'
        ;new line
        mov si,newLine
        call printString
        ;introduce second variable
        mov si,math_description1
        call printString
        mov bx,0
        call secondVariableKeyboard
        mov dh,[var2]
        ;conversion from ascii to decimal
        sub dh, '0'
        ;new line
        mov si,newLine
        call printString
        ;the result
        mov si,math_description2
        call printString
        ;adding
        add dl, dh
        ;conversion from decimal to ascii
        add dl, '0'
        mov byte [result], dl
        mov si,result
        call printString
        ;new line
        mov si,newLine
        call printString
        jmp mainLoop
printString:
    push ax                   ; save ax to stack
    mov ah, 0x0e              ; call tty function
    call printChar      
    pop ax                    ; take ax out of the stack
    ret                      
printChar:
    mov al, [si]              ; load symbol
    cmp al, 0                 ; if si empty then jump
    jz ifZero               
    int 0x10                  ; if not print al
    inc si                    ; increment si
    jmp printChar       ;again untill stack empty
ifZero:
    ret
    var1: times 64 db 0 
    var2: times 64 db 0 
    result:  times 64 db 0 
- 5+6=11 example
  
- two char + two char example
  
 
     
    