gpt4 book ai didi

assembly - 在汇编 8086 中输出数字的 ASCII 字符

转载 作者:行者123 更新时间:2023-12-02 19:57:16 27 4
gpt4 key购买 nike

我在斐波那契序列计算的每个步骤中输出计算值时遇到问题,它输出计算值的相应 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

最佳答案

  • 始终将数据放置在执行路径之外。现在,您已在指令之间放置了 prevcurrentspace 的数据。这将导致失败。

    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 " ","$"
  • 为了实际打印数字,您需要将其转换为字符。您的当前变量保存的是二进制值,而不是字符!此快速解决方案将仅显示单位数斐波那契数:

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

关于assembly - 在汇编 8086 中输出数字的 ASCII 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34710291/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com