Author Topic: DOSBOX crashes when i try to run my program?  (Read 6431 times)

Offline wezzazzew

  • Jr. Member
  • *
  • Posts: 2
DOSBOX crashes when i try to run my program?
« on: January 03, 2016, 12:42:41 AM »
i have win64 so my professor advised me to use DOSBOX to run .com applications generated through NASM.
i wrote this program that multiply two numbers that the user entered, nut when i try to run it, this happens:


here's my code
Code: [Select]
org 100h
section .data

message1         dd  13, "Enter first number", 13, 10, '$'
message2         dd  13, "Enter second", 13, 10, '$'
inputNumber      db   3, "    "
valueToPrint     db   3, "    "
numOne           db   3, "    "
numTwo           db   3, "    "



section .text

_start:

call    multi
mov     esi, 0
call    convert       
jmp     safe_exit

multi:
mov     dx, message1
mov     ah, 9
int     21h
mov     dx, inputNumber
mov     ah, 0Ah
int     21h

mov    esi, 0
mov    ecx, inputNumber

top:
mov     al, [ecx]
inc     ecx
cmp     al, 0 
jz      done
sub     al, '0' 
jl      done
cmp     al, 9 
jz      done
sub     al, '9' 
jg      done
mov     ah, 0
push    eax
add     al, '0' 
inc     esi
jmp     top

done:
   call endl
         pop  edx
   dec  esi
   jz    secondStep
   pop  eax
   imul eax, 10
   add  edx, eax
   dec  esi
   jz    secondStep
   pop  eax
   imul eax, 100
   add  edx, eax
   dec  esi
   jz    secondStep
   pop  eax
   imul eax, 1000
   add  edx, eax
   dec  esi
   jz    secondStep

secondStep:
         mov     [numOne], edx
         mov     dx, message1
         mov     ah, 9
         int     21h
         mov     dx, inputNumber
         mov     ah, 0Ah
         int     21h

         mov esi, 0
         mov ecx, inputNumber
toptwo:
   mov  al, [ecx]
   inc  ecx
   cmp  al, 0 
   jz   done
   sub  al, '0'
   jl   done
   cmp  al, 9
   jg   done
   mov  ah, 0
   push eax
   add  al, '0'
   inc  esi
   jmp  toptwo
donetwo:
   call endl
         pop  edx
   dec  esi
   jz    letsgo
   pop  eax
   imul eax, 10
   add  edx, eax
   dec  esi
   jz    letsgo
   pop  eax
   imul eax, 100
   add  edx, eax
   dec  esi
   jz    letsgo
   pop  eax
   imul eax, 1000
   add  edx, eax
   dec  esi
   jz    letsgo


letsgo:
   mov [numTwo], edx
   mov eax, [numOne]
   mov edx, [numTwo]

   mul edx
   ret


convert:
mov     edx,0
mov     ecx,0Ah               
idiv    ecx
push    eax     
mov     eax,edx
add     eax,'0'
push    eax
pop     ebx                     
pop     eax
push    ebx
inc     esi
or      eax,eax                 
jnz     convert
call    endl

labella:
pop     eax
call    print_char

dec     esi
or      esi,esi
jnz     labella

endl:
mov     eax, 10                 
call    print_char
ret

print_char:
mov     [valueToPrint], eax
mov     dx, valueToPrint
mov     ah, 9
int     21h
ret

safe_exit:
mov     ah,00h
int     16h
ret

is it something wrong with it that's makig DOSBOX behave this way?
« Last Edit: January 03, 2016, 02:23:33 AM by Frank Kotler »

Offline rkhb

  • Jr. Member
  • *
  • Posts: 7
  • Country: de
Re: DOSBOX crashes when i try to run my program?
« Reply #1 on: January 04, 2016, 02:44:48 PM »
First: You should not use 32-bit stuff (eax,ebx,ecx,edx...) in a 16-bit program. It's possible but there are pitfalls.

Second: You should always use a documentation for the system calls (int 21h). Every operating system has different requirements. Look at Ralf Brown's interrupt list for DOS: Int 21/AH=09h and Int 21/AH=0Ah and check if you fulfilled all conditions (register usage, memory defines etc.). Hint: you made mistakes on both calls.

Third: You should use a debugger to let the code run step by step and to see if the program does what it should do. I recommend for 16-bit-DOSBox-MSDOS-programs the Turbo Debugger (google for "turbo debugger download").