Getting Assembly to Work

Started by
13 comments, last by WheelsRCool 17 years, 8 months ago
Alright, I am trying to figure out how to get this assembler I downloaded to work for Assembly programs. I went to the "For Beginners" section, went into the FAQ section with all the links for programming language guides, and went to the first Assembly guide, the Assembly Tutorial by Hugo Perez. I first went and tried to write an assembly program using the Debug program, but when I typed in C:\>Debug [Enter] as instructed, my command prompt said, "Debug is not recognized as an internal or external command, operable program, or batch file." So I couldn't get any further there. I then decided to try and build an assembler program with an assembler. The guide said it uses Borland's tasm assembler, but that you have to buy, and I have no $$$ or transportation for the moment, so I went to google and downloaded an assembler called Lazy Assembler. I assumed that assembler should work the same, but I'm not toally sure. I went and copied and pasted the following program code (which was in the guide) into a Notepad file, saved it as examp1.asm, then went to the directory in the command prompt, typed lzasm examp1.asm and got a bunch of errors. As in the tutorial, where at the top, it says, "Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 Borland International" with mine it said, "Lazy Assembler, Version 0.52, etc..." but then said, referring to lines 2-4, "Illegal instruction" for each and for lines 5-9, it said, "Code or data emission to undeclared segment" for each. Is this guide just too old and computer hardware (processors) and assembly language have changed, or is it just that this code will only work with Borland's Turbo Assembler? I know once this code works, then I'd have to use a linker to generate the executable code, but I can't get to that step right now. I looked at Randall Hyde's "The Art of Assembly Language Programming" stuff, but from what I have read, that is high-level assembly language and not "true" assembly. Is my assembler just screwy or is this code too dated, and if the latter, where can I find a more up-to-date guide? Thanks, ---Wheels---
Advertisement
What assembler did you download?
daerid@gmail.com
Lazy Assembler
Quote:Original post by WheelsRCool
Alright, I am trying to figure out how to get this assembler I downloaded to work for Assembly programs. I went to the "For Beginners" section, went into the FAQ section with all the links for programming language guides, and went to the first Assembly guide, the Assembly Tutorial by Hugo Perez. I first went and tried to write an assembly program using the Debug program, but when I typed in C:\>Debug [Enter] as instructed, my command prompt said, "Debug is not recognized as an internal or external command, operable program, or batch file."

So I couldn't get any further there. I then decided to try and build an assembler program with an assembler. The guide said it uses Borland's tasm assembler, but that you have to buy, and I have no $$$ or transportation for the moment, so I went to google and downloaded an assembler called Lazy Assembler.

I assumed that assembler should work the same, but I'm not toally sure. I went and copied and pasted the following program code (which was in the guide) into a Notepad file, saved it as examp1.asm, then went to the directory in the command prompt, typed lzasm examp1.asm and got a bunch of errors.

As in the tutorial, where at the top, it says, "Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 Borland International" with mine it said, "Lazy Assembler, Version 0.52, etc..." but then said, referring to lines 2-4, "Illegal instruction" for each and for lines 5-9, it said, "Code or data emission to undeclared segment" for each.

Is this guide just too old and computer hardware (processors) and assembly language have changed, or is it just that this code will only work with Borland's Turbo Assembler?

I know once this code works, then I'd have to use a linker to generate the executable code, but I can't get to that step right now.

I looked at Randall Hyde's "The Art of Assembly Language Programming" stuff, but from what I have read, that is high-level assembly language and not "true" assembly.

Is my assembler just screwy or is this code too dated, and if the latter, where can I find a more up-to-date guide?

Thanks,
---Wheels---


The Perez article is quite dated. It's 16 bit. DOS based. A large chunk of it's information is still useful, but a large chunk of it isn't (imo).

Imo, you'll probably be better off starting with inline assembly in a C/C++ program and moving from there to declspec(naked) functions before jumping into full on assembly based programs.

If you're not that patient and want to jump in head first, check out Iczelion's Win32 Assembly Homepage.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanks, but what do you mean by "inline assembly" in a C/C++ program? Do you mean just incorporating some bits of assembly throughout a C/C++ program to enhance it?
Inline assembler

Quote:
In computer programming, the inline assembler is a feature of some compilers that allows very low level code written in assembly to be embedded in a high level language like C or Ada.
...


See also: Visual C++ Language Reference: Inline Assembler
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanks again; that website on Assembly really helped. I compiled and ran the beginner assembly program code he has using the IDE thing that came with the masm32 package. I have no idea how the code works yet, as I have yet to read the tutorial, but I mean, I know I should be able to write code now for learning.

I am wondering though, I noticed that masm32 (the assembler) was stored directly on the C drive. When I tried to save a program to a specific directory, it wouldn't assemble. Only when I saved it directly into the masm32 directory in the C drive did it compile. This is because when I click "Assemble and Link" the command prompt window that comes up is default set to C:\masm32.

I am guessing I don't need the IDE to assemble, link, and run the programs, but what are the commands for this? I know I can just start up the command prompt from Windows and navigate my way into the directory I want, or I can start it up from the IDE and navigate my way to the directory I want, but once there, what commands do I use to assemble, link, and then execute/run the program from the command prompt? I tried starting it (the cmd) up from the IDE and navigating my way into the directory I want, then trying the "Assemble and Link" button, but it didn't work. I am guessing I would have to change the default setting of the IDE command prompt to the directory I save the Assembly programs in.

I don't want to have to keep saving program files to the masm32 directory, so I would like to know how to change this default directory if possible and also how to assemble, link, and execute the program from the cmd prompt.

Thanks again,
---Wheels---
Read the masm32 documentation.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Considering the scope of all that documentation, I am guessing you mean, "Learn masm32 inside and out and you'll find the answers to your questions..." Oh well, that's something I had planned anyhow.
To run masm32 from the command line in any directory, you need to add the masm32 directory to your PATH environment variable.

You can do this by either:

Create a C:\autoexec.bat file, containing the line:

set path=%path%;c:\masm32;

or go to Control Panel->System->Advanced->Environment Variables, click Path in the bottom list, click Edit, then add ;C:\Masm32 (note the semicolon) to the end.

If you use the first approach, you may need to restart your computer before it takes effect.

You should now be able to type "masm32" in any directory at the command prompt and have it run.

HTH Paul

This topic is closed to new replies.

Advertisement