【问题标题】:Why does my assembly program (x86) freezes in Dosbox when I try to run it?为什么我尝试运行我的汇编程序 (x86) 在 Dosbox 中冻结?
【发布时间】:2016-01-26 04:28:42
【问题描述】:

注意事项:使用 x86 汇编(16 位);使用纳斯姆;在 DosBox 中运行程序。

当我尝试在 DosBox 中运行程序时,模拟器冻结(我不确定 freezes 是正确的词,因为光标仍在闪烁)并拒绝响应输入。我第一次尝试运行它时,DosBox 实际上崩溃了。

这是我的代码:

;ASSIGNMENT 3

    org 100h

section.data:

prompt1 db  0dh, 0ah, 0dh, 0ah, "Please input a signed base-10 integer: $"
prompt2 db  0dh, 0ah, "Your number in binary is: $"
prompt3 db  0dh, 0ah, "Pretty sure that wasn't a number. Please enter a number value. $"

section.text:

START:
    mov ah, 9       ;Display input prompt
    mov dx, prompt1 
    int 21h

DEC_IN: 
    mov bx, 0       ;Get input
    mov ah, 1
    int 21h

    cmp al, 0dh     ;compare input to carriage return; check if user is finished
    je  DEC_OUT     ;if yes, go display the prompt

    cmp al, '0'     ;compare to '0'
    jg  IS_DIGIT    ;jump to IS_DIGIT to confirm that it is a number
    jl  NAN_ERROR   ;if below 0, print error prompt and start over

IS_DIGIT:
    cmp al, '9'     ;confirms digit value
    jl  BIN_CONV    ;if digit, convert to binary
    jg  NAN_ERROR   ;if not, print 'not a number' error message

BIN_CONV:
    and al, 0fh     ;converts ASCII to binary
    neg al      ;one's complement
    add al, 1       ;add 1 to make two's compliment
    jmp ADDIT       ;add to bx

ADDIT:
    or  bl, al      ;adds new digit to sum in bx
    int 21h
    jmp DEC_IN

NAN_ERROR:
    mov ah, 9       ;display error message
    mov dx, prompt3
    int 21h

    jmp START       ;Go back to beginning

DEC_OUT:
    mov ah, 9       ;Display the signed decimal value
    mov dx, prompt2
    int 21h

如果重要的话,程序应该以无符号十进制值的形式接受输入,并将其输出为有符号十进制值,然后输出为八进制值。我知道我的程序没有做到这一点,即使它确实运行了;它仍处于开发初期。

提前致谢

【问题讨论】:

    标签: assembly x86 nasm


    【解决方案1】:

    您应该尽可能在“开发早期”学习使用调试器。

    也就是说,请确保您的数据代码之后,否则 cpu 会尝试将其作为指令执行,这不会很漂亮。

    请注意section.data: 是双重错误的,您不能使用冒号,因为它不是标签,并且您必须在点之前放置一个空格,如section .data。当然,section.text: 也是如此。如果你这样做了,nasm 会很聪明地把数据放在代码后面。

    尽管如此,DOS .com 文件没有分区,这只是 nasm 的一个方便功能,我不建议使用。

    【讨论】:

    • 太好了,谢谢。我之前实际上没有冒号。我添加它们是因为我确实阅读了调试器告诉我的内容。我想我误解了它告诉我的内容。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多