• Advertisement

# Getting Assembly to Work

This topic is 4180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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--- #### Share this post ##### Link to post ##### Share on other sites Advertisement What assembler did you download? #### Share this post ##### Link to post ##### Share on other sites Lazy Assembler #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by WheelsRCoolAlright, 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.

#### Share this post

##### Share on other sites
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?

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
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---

#### Share this post

##### Share on other sites
Read the masm32 documentation.

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
Quote:
 Original post by WheelsRCoolConsidering 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.

Honestly, I was trying to be more polite than simply saying rtfm, but rtfm. If you're like most everyone else, you'll have to read it several times through before you get near to knowing it inside and out, but don't take that as an excuse to not read it. That's just the nature of the beast. As you get more familiar with the terminology, you'll have an easier time finding what you're looking for in the manual, but before then it's a bit of a hard slog.

You'll also probably want to download copies of the Intel manuals, all three volumes. The instruction set manuals are vital. The other two volumes will take some time to grok as well, but they are worth it.

And you probably should give props to EasilyConfused for providing the correct answer to your follow up question.

#### Share this post

##### Share on other sites
Yes, thanks EasilyConfused, and LessBread, I wasn't meaning to sound like a dick when I wrote the previous post, if that's how it sounded. If you interpreted it as, "Okay man, I can see you want to be a dick and not tell me what I need to know, I understand, I will read the manual," I DID NOT mean it to sound that way. I just meant I thought you meant, "RTFM and you will understand it a lot better than if I just tell you the answer straight off the bat."

And you can be sure I will read all of it through, multiple times if necessary, I want to understand the system inside and out, I was serious when I said I had planned to read all the docs.

Thanks for all the information though, I appreciate it.

For computers with an AMD processor, do the Intel manuals apply to those or AMD manuals need to be studied (I know AMD processors have a different architecture, so I'm assuming so).

#### Share this post

##### Share on other sites
Quote:
 Original post by WheelsRCoolYes, thanks EasilyConfused, and LessBread, I wasn't meaning to sound like a dick when I wrote the previous post, if that's how it sounded. If you interpreted it as, "Okay man, I can see you want to be a dick and not tell me what I need to know, I understand, I will read the manual," I DID NOT mean it to sound that way. I just meant I thought you meant, "RTFM and you will understand it a lot better than if I just tell you the answer straight off the bat."

I didn't think you were being a dick, but that you were a little miffed. The manual likely touches on adding the software to the PATH, but probably not in a way that you would have recognized it as your answer. Environment variables don't get the same coverage that they used to.

Quote:
 Original post by WheelsRCoolAnd you can be sure I will read all of it through, multiple times if necessary, I want to understand the system inside and out, I was serious when I said I had planned to read all the docs.

If you're like me, there will be some parts that you will read multiple times and some parts you will only read once.

Quote:
 Original post by WheelsRCoolThanks for all the information though, I appreciate it.

You're welcome.

Quote:
 Original post by WheelsRCoolFor computers with an AMD processor, do the Intel manuals apply to those or AMD manuals need to be studied (I know AMD processors have a different architecture, so I'm assuming so).

By and large. AMD chips use the basic Intel instruction set. AMD also provides downloadable manuals for their chips. You can find all sorts of information at sandpile.org.

#### Share this post

##### Share on other sites
Quote:
 Original post by LessBreadBy and large. AMD chips use the basic Intel instruction set. AMD also provides downloadable manuals for their chips. You can find all sorts of information at sandpile.org.

the instruction set is close to identical (intels EM64T is pretty much compatible with the AMD64), however they don't work in the same way so if you are trying to write "perfectly" optimized code you'll need to study both. AMD has a guide on their website that covers some important parts.

#### Share this post

##### Share on other sites
Cool, again, thanks for all the help guys.

#### Share this post

##### Share on other sites

• Advertisement