问题
Things to note: Working in x86 assembly (16-bit); using Nasm; running program in 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.
Here is my code:
;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.
Thanks in advance
回答1:
You should learn to use a debugger as "early in development" as possible.
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.
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.
Nevertheless, DOS .com
files don't have sections, it's just a convenience feature of nasm
that I don't recommend using.
来源:https://stackoverflow.com/questions/33356493/why-does-my-assembly-program-x86-freezes-in-dosbox-when-i-try-to-run-it