Konvertieren Sie einzelne hexadezimale Ziffer Dezimalwert Intel 8086 Assembler

Hallo, ich habe Probleme mit diesem code. Es wird gedruckt, 0-9 fein, aber A-F oder a-f es macht mir einfach ein smiley-Gesicht, das ist nicht einmal ein ASCII-symbol mindestens entsprechend der Liste der Symbole, meine Professorin hat uns zur Verfügung gestellt. Hier ist mein code. Bitte helfen Sie. Ich bin mit NASM und DosBox.

    org 100h
; hexadecimal to base 10 conversion program
section .data
    MSG1    dw  " Enter a hexadecimal digit ", '$'
    MSG2    dw  " In decimal it is: ", '$'
    MSG3    dw  " Do you want to do it again? ", '$'
    EMSG    dw  " Illegal character, enter 0..9 or A..F: ", '$'
section .text
main:   
; print user prompt 
     mov    dx, MSG1    ; get message
     mov    ah, 09h     ; display string function
     int    21h     ; display it
     jmp    userin      ; jumps to user input so if illegal character is entered message won't display again
userin:
; input a hexidecimal number then compare to ASCII codes
     mov    ah, 01h     ; keyboard input function
     int    21h     ; character input, copies character into al
     mov    bh, al      ; moves al into bh to avoid al being messed with
     cmp    bh, 30h     ; compares input to ASCII code for 0
      jl    error       ; if input is less than 0 jump to main
     cmp    bh, 39h     ; compares input to ASCII code for 9
     jle    print1      ; if input is less than or equal to 9 jump to print
     cmp    bh, 41h     ; compares input to ASCII code for 'A'
      jl    error       ; if input is less than 'A' jump to main
     cmp    bh, 46h     ; compares input to ASCII code for 'F'
     jle    convert1    ; if input is less than or equal to 'F' jump to convert1
     cmp    bh, 61h     ; compares input to ASCII code for 'a'
      jl    error       ; if input is less than 'a' jump to main
     cmp    bh, 66h     ; compares input to ASCII code for 'f'
     jle    convert2    ; if input is less than of equal to 'f' jump to convert2
      jg    error       ; if input is greater than 'z' jump to main
error:
; displays error message then jumps back
     mov    dx, EMSG    ; moves error message into display string register
     mov    ah, 09h     ; display string function
     int    21h     ; displays it
     jmp    userin      ; jumps back to user input
convert1:
; converts input from hexadecimal A-F to decimal
     sub    bh, 16      ; subtracts 0Fh from input to get decimal
     jmp    print2      ; jumps to print
convert2:
; converts input from hexidecimal a-f to decimal
     sub    bh, 48      ; subtracts 30h from the input to get 
     jmp    print2      ; jumps to print
print1:
; prints the input in decimal form
     mov    dx, MSG2    ; moves MSG2 into display string register
     mov    ah, 09h     ; display string function
     int    21h     ; display MSG2 "In decimal it is:"
     mov    dl, bh      ; moves input into display character register
     mov    ah, 02h     ; display character function
     int    21h     ; display input in decimal form
     jmp    again       ; jumps to again
print2:
;prints the input in decimal form
     mov    dx, MSG2    ; moves MSG2 into display string register
     mov    ah, 09h     ; display string function
     int    21h     ; display MSG2 "In decimal it is:"
     mov    dl, 1d      ; will add 10 to the converted ASCII code
     mov    ah, 02h     ; display character function
     int    21h     ; display 1 in front of input in decimal form
     mov    dl, bh      ; moves converted input to display character register
     mov    ah, 02h     ; display character function
     int    21h     ; displays converted input
     jmp    again       ; jumps to again
again:
; asks if user wants to do it again
     mov    dx, MSG3    ; moves MSG2 into display string register
     mov    ah, 09h     ; display string function
     int    21h     ; display MSG3 "Do you want to do it again?"
     mov    ah, 01h     ; keyboard input function
     int    21h     ; character input, copies into al
     cmp    al, 59h     ; compares input to ASCII code for 'Y'
      je    main        ; if input is equal to 'Y' jump to main
      jl    exit        ; if input is less than 'Y' jump to exit
     cmp    al, 79h     ; compares input to ASCII code for 'y'
      je    main        ; if input is equal to 'y' jump to main 
     jne    exit        ; if input is not equal to 'y' jump to exit
exit:
;exit to DOS
      mov     ah, 04Ch      ; DOS function: Exit program 
      mov     al, 0         ; Return exit code value
      int     21h           ; Call DOS. Terminate program 
InformationsquelleAutor Joey Platt | 2014-02-22
Schreibe einen Kommentar