Click here to Skip to main content
12,760,992 members (26,078 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASM
I am trying to learn ASM programming on MS-DOS to get a string from User.
But during the run-time it reboots the OS automatically or hangs or misbehaves while the same program is executed on Windows-XP it does not give any run-time errors.

Could you please help me in this regards as to where am I going wrong.

Below is the environment:
Assembler: Tasm

.Model Small
.Stack 100H
    CR Equ 0DH
    LF Equ 0AH
    NL Equ 00H
    MsgX db 32H Dup (NL)
    MOV AX, @Data
    MOV DS, AX
    MOV AX, Offset MsgX
    CALL GetStr
    CALL Exit

        PUSH BX
        PUSH CX
        PUSH DX
        MOV AH, 01H
        INT 21H
        POP  DX
        POP  CX
        POP  BX

        PUSH AX
        PUSH BX
        PUSH CX
        PUSH DX
        MOV BX, AX
            CALL GetChr
            MOV Byte Ptr [BX], AL
            CMP Byte Ptr [BX], CR
            JE GetStrFree
            INC BX
            JMP GetStrLoop
            MOV Byte Ptr [BX], NL
            POP DX
            POP CX
            POP BX
            POP AX

        MOV AH, 4CH
        INT 21H
End Run
Posted 29-Sep-12 10:07am
Zerr0cool 29-Sep-12 15:39pm
Well I wanted to mention one of the errors I get during the run-time as below
"cpu error incorrect opcode. killing process"
Kuthuparakkal 29-Sep-12 16:54pm
try changing this MOV AH, 01H
to: MOV AH, 09H
Zerr0cool 29-Sep-12 17:03pm
Are you just guessing? 09H function is used to display string to the screen while 01H is used to accept a character from screen.
What difference you think so it really makes if i even change them ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This codepiece reminds me of some good old times... :-)
At first sight your code has no serious errors that should cause a crash. maybe you compiled and/or linked it incorrectly. Your prgram should be compiled into an exe file, not a com file. Check if it has an exe header, open it with a binary viewer and check if the file starts with "MZ" or "ZM". If it doesn't have an exe header then you linked it incorrectly as a com file.

For string input I would use dos function 10 unless your task is write one using character input. The one using character input is useful when you want restrictions on the input (for example allowing only digits or maximize string length).

Some notes about the code:
- You are too paranoid and using too many PUSHs and POPs. Your getchar function could be inlined to your loop.
- You don't check for max string length, this can lead to buffer overrun if the user enters a very long string.
- You don't handle backspace but that would involve much more work.
- You don't specify the program exit code in al when you exit, for example zero: mov ax, 4c00h int 21h
- The correct name for the "newline character" (ascii 10) is Line Feed (aka LF) in DOS, CR is okay. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100