为什么我尝试运行汇编程序(x86)在Dosbox中冻结? [英] Why does my assembly program (x86) freezes in Dosbox when I try to run it?

查看:107
本文介绍了为什么我尝试运行汇编程序(x86)在Dosbox中冻结?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意事项:在x86汇编中工作(16位);使用Nasm;在DosBox中运行程序.

Things to note: Working in x86 assembly (16-bit); using Nasm; running program in DosBox.

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

When I try to run the program in DosBox, the emulator freezes (I'm not sure freezes is the right word since the cursor still blinks) and refuses to respond to input. The first time I tried running it DosBox actually crashed.

这是我的代码:

;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

如果有关系,应该假定程序以无符号十进制值的形式输入,然后将其输出为有符号十进制值,然后输出为八进制值.我知道我的程序即使执行了也不会执行该操作;它仍处于发展初期.

If it matters, the program is supposed to take input in the form of an unsigned decimal value and output it as a signed decimal value, and then as an octal value. I'm aware my program doesn't do that yet even it did run; it's still early in development.

预先感谢

推荐答案

您应该学习尽可能早于开发"使用调试器.

You should learn to use a debugger as "early in development" as possible.

也就是说,请确保您的数据在代码后 之后,否则CPU会尝试按照指令执行它,而且效果会不太好.

That said, make sure your data is after the code, otherwise the cpu will try to execute it as instructions and that won't be very pretty.

请注意,section.data:是双重错误,您不能使用冒号,因为它不是标签,并且必须在点前放置一个空格,如section .data所示.当然,对于section.text:也是如此.如果这样做,nasm将足够聪明,可以将数据放在代码之后.

Note that section.data: is doubly wrong, you must not use a colon since it's not a label, and you must put a space before the dot, as in section .data. Similarly for the section.text: of course. If you do that, nasm will be clever enough to place the data after the code.

尽管如此,DOS .com文件没有部分,这只是我不建议使用的nasm便利功能.

Nevertheless, DOS .com files don't have sections, it's just a convenience feature of nasm that I don't recommend using.

这篇关于为什么我尝试运行汇编程序(x86)在Dosbox中冻结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆