Search code examples
assemblyx86tasm

Assembly language-How to make two inputted number as one?


I'm trying to do an assembly language programming with this condition:

    if age = 18 then write "You are of legal age" 
    else if age<18 then write "You are too young"
    else write "You should be working now"

Here's where I have a problem:

    mov ah,01h  "This is the first digit"
    int 21h
    mov bl,al
    mov ah,01h "This is the second'
    int 21h

When I input a two digit number, there are two different values of AL. I move the first value to BL to save it and I don't know what to do next. Can I ask how to make them combine as in when I input "17", it'll be 17h. I've read I need to subtract 30h but that only works with 0-9. I can't figure out what to do starting number 10 onwards. I'm using Tasm.

Hope someone can help me.


Solution

  • To store two digit input as one, try this

    num db 0     ;declare a variable to store the two digit input
    ten db 10     ;declare a variable that holds a value 10
    
    mov ah,01h  ;This is the first digit
    int 21h
    SUB al,48D     ;subtract 48D 
    MUL ten        ;multiply with 10 because this digit is in ten's place
    mov num,al    ;mov first digit input in num
    
    mov ah,01h  ;This is the second digit
    int 21h
    SUB al,48D 
    ADD num,al   ;add second digit to num
    

    Now your two digit number is in variable num

    Note that i multiplied first digit input with 10 but i didn't multiply second digit input with anything because it's in one's place.