【发布时间】: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
如果重要的话,程序应该以无符号十进制值的形式接受输入,并将其输出为有符号十进制值,然后输出为八进制值。我知道我的程序没有做到这一点,即使它确实运行了;它仍处于开发初期。
提前致谢
【问题讨论】: