×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Newbie help with first program (program crashes)

Newbie help with first program (program crashes)

Newbie help with first program (program crashes)

(OP)
Hello,
I have tried, using 32-bit assembly language code I found online, to write my own program. It assembled and link, but when I run it, I get a message saying the program had "encountered a problem and needs to close." It is a message that is common on Windows, asking to send a report to Microsoft. I tried using a Turbo Debugger, but I got the same message, but for the debugger. The code is the following:

CODE

    .586
    .MODEL    FLAT, STDCALL
    .DATA
DATA1    DB    52H
DATA2    DB    29H
SUM    DB    ?
    .CODE
START:
    MOV    AL, DATA1
    MOV    BL, DATA2
    ADD    AL, BL
    MOV    SUM, AL
END    START
As you can see, the point of the program is simply to add some values (the result would be checked through a debugger).
I'm using a pentium III processor with Windows XP. What would be the problem(s) with my code? Thank you very much

RE: Newbie help with first program (program crashes)

Your code has no controled end and therefore your program will continue into some old code and crashes.

So you must end it with some code, see your book.

Tessa

RE: Newbie help with first program (program crashes)

Try try adding on the following:

CODE

  MOV ah, 4CH  ;EXIT PROCESS FUNCTION
  INT 21H      ;EXECUTE DOS SERVICES INT
Asembler programs are "stupid"; they assume nothing. If you don't tell it exactly what to do, they won't do it, so you must tell the program to return to the operating system or it will continue to execute past the end point, as Tessa points out

The simplest solution is the best!

RE: Newbie help with first program (program crashes)

(OP)
I corrected it, but I still get the same problem.

CODE

    .586
    .MODEL    FLAT, STDCALL
    .DATA
DATA1    DB    52H
DATA2    DB    29H
SUM    DB    ?
    .CODE
START:
    MOV    AL, DATA1
    MOV    BL, DATA2
    ADD    AL, BL
    MOV    SUM, AL
        MOV   AH, 4CH
        INT   21H
END    START

RE: Newbie help with first program (program crashes)

You wrote that you're writing 32bit code, and you're using model 'flat', but int 21h is the 16-bit DOS interrupt, with ah=04Ch being the DOS call to end a program. These are two different worlds.

RE: Newbie help with first program (program crashes)

won't a simple RET instruction suffice?

with DOS programs the stack pointer points to an INT 20h instruction upon program startup.
i'm not saying that INT 20h is the answer for flat model programs, to be honest i don't know,
but maybe the stack pointer will point at the answer.

RE: Newbie help with first program (program crashes)

(OP)
The RET instruction seems to be working: I don't get a message saying the program caused an error. The problem this time is that I get this message when attempting to run it in turbo debugger and I when I tried running it in debugger, I simply was not able to run it: if I use the G(o) command, it tells me that the program cannot be run in MS-DOS mod, and I cannot find my code using U(nassemble) command. What should I do? Any advice? Thank you for your past and future answers.

RE: Newbie help with first program (program crashes)

this might be because you assembled your program as a windows executable,
and you use a debugger that can only handle DOS programs (or is configured as such).

what kind of assembler and linker are you using?

RE: Newbie help with first program (program crashes)

You really do need to decide whether you're writing a 16-bit DOS program or a 32-bit windows program. They are fundamentally different, and won't run in each other's environment. It will really help you to find out which environment you're in, because soon you will want to look at the result of your calculation, which is where an operating system really is useful. You need to know whether the operating system is going to be windows, or DOS (or more likely, windows pretending to be dos!).

From your name, I'd guess you are already a happy C++ programer. If so, have you considered embedding little bits of assembler into C or C++ programs? It might be an easier way to see how it works, and also more practically useful. Generally, assembler is most valuable in speeding up a very, very small bit of completely critical code, or for the occasional very hardware-near thing. Very few people will benefit from writing whole applications in assembler.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close