简体   繁体   English

在Assembly 8086中输出数字的ASCII字符

[英]Outputting numbers' ASCII character in Assembly 8086

I'm having problem outputting the calculated value in each step of Fibonacci sequence calculation, it outputs the respective ascii character of the calculated value like ☺ ☻ ♥ ♣ and how many times the sequence should run is depended on the user however it's limited to 47: 我在Fibonacci序列计算的每一步输出计算值时遇到问题,它输出计算值的相应ascii字符,如☺☻♥♣,序列应运行的次数取决于用户,但它限制为47 :

org 100h

ask_for_input db " Please enter a number[1-47]: ","$"
inputNumber DB 0  
conv DB 10D 
newL DB 0AH,"$"      


ask-again:        
    LEA DX, newL
    MOV AH,9H
    int 21H       

   ; Ask for user input       
   LEA DX, ask_For_input                       
   mov AH,9H
   int 21H             

   ; Gets user input
   ; First digit           
    MOV ah, 01H          
    int 21h

    SUB AL, 30H
    MUL conv   
    MOV inputNumber, AL

    ; Second Digit
    MOV AH, 01H 
    int 21h

    SUB AL, 30H
    add inputNumber, AL

    ; Checks if number is above 47D
    CMP inputNumber, 2FH
    JNLE ask-again  
    ; Checks if number is below 00D
    CMP inputNumber, 00H
    JLE ask-again    

; Squence loop Counter                      
MOV CH, 00H
MOV CL, inputNumber 

; Starting calculation
prev DB 01D   
current DB 1D            

Begin:
   space DB " ","$"
   LEA DX, space
   MOV AH,9H
   int 21H    

   ; Print Current Number                            
   LEA DX, current,"$" 
   mov AH,09H
   int 21H 

   ; Finds next number
   MOV BL, prev
   add current, BL 

   ; Advances prev
   MOV BL, current
   SUB BL, prev
   MOV prev, BL             

   Loop Begin
  • Always place the data outside of the execution path. 始终将数据放在执行路径之外。 Now you've placed the data for prev , current , and space between the instructions. 现在,您已在指令之间放置了prevcurrentspace的数据。 This will lead to failure. 这将导致失败。

     ask_for_input db " Please enter a number[1-47]: ","$" inputNumber DB 0 conv DB 10D newL DB 0AH,"$" prev DB 01D current DB 01D,"$" space DB " ","$" 
  • In order to actually print the number you need to convert it to a character. 为了实际打印您需要将其转换为字符的数字。 Your current variable holds a binary value, not a character! 当前的变量包含二进制值,而不是字符! This quick solution will display the single digit Fibonacci numbers only: 此快速解决方案仅显示单个数字斐波那契数字:

     ; Print Current Number add current, 30H LEA DX, current mov AH,09H int 21H sub current, 30H 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM