Author Topic: Some starter questions about assembly language  (Read 1689 times)

coinop

  • Guest
Some starter questions about assembly language
« on: July 23, 2013, 08:03:03 AM »
Can someone with experience give me their opinion on this learning plan. The most important question is about the book of choice, if you have used it before.

I'm looking to learn Intel assembly language. My choice as a beginner is this book -> Assembly Language for x86 Processors (6th Edition) by Kip R. Irvine. I'm not new to programming, but I am new to asm.

I looked through the table of contents of several books including that one on Amazon. Many books refer to using Visual Studio. I'm not interested in Visual Studio at all, but would like to use NASM. Of course, I would not be here if I did not consider MASM, but my question mostly is not about which assembler is better. My question is about adaptation if you are starting out. The book recommends Visual Studio and uses MASM, but notes NASM also.

How complex is it to adapt to NASM from a MASM perspective. This might be a broad question, but I'm more concerned about the complexity of this book as a single lesson plan. Should I get this book? or is there another approach to this.

As a side note, after NASM, I would like to try to work with Flat Assembler. These assemblers are available for Linux as well, which is important to me. I don't want to tackle the GNU assembler, because from looking at various references, it is the most "different" of the main stream assemblers.

Anyone with advice or recommendation based on experience with this book, is much appreciated. I'm just starting out.

Gunther

  • Member
  • *****
  • Posts: 2854
  • Forgive your enemies, but never forget their names
Re: Some starter questions about assembly language
« Reply #1 on: July 23, 2013, 08:56:45 AM »
Hi coinop,

first things first: Welcome to the forum.

To your questions:

Can someone with experience give me their opinion on this learning plan. The most important question is about the book of choice, if you have used it before.

I'm looking to learn Intel assembly language. My choice as a beginner is this book -> Assembly Language for x86 Processors (6th Edition) by Kip R. Irvine. I'm not new to programming, but I am new to asm.

I wouldn't prefer that book to learn assembly language. There are better alternatives.

I looked through the table of contents of several books including that one on Amazon. Many books refer to using Visual Studio. I'm not interested in Visual Studio at all, but would like to use NASM. Of course, I would not be here if I did not consider MASM, but my question mostly is not about which assembler is better. My question is about adaptation if you are starting out. The book recommends Visual Studio and uses MASM, but notes NASM also.

If you prefer NASM or YASM you should check Paul Carter's site. It's a good starting point for 32 bit programming under Windows or Linux. You'll need NASM and GCC.

For the 64 bit programming you should check Ray Seyfarth's site.

As a side note, after NASM, I would like to try to work with Flat Assembler. These assemblers are available for Linux as well, which is important to me. I don't want to tackle the GNU assembler, because from looking at various references, it is the most "different" of the main stream assemblers.

Yes, NASM and YASM are available under Linux, BSD, and MacOS too. I've no experiencees with Flat assembler. NASM and YASM have a slidely other syntax compared with MASM. That has advantages but also disadvantages. You could try to install the MASM32 package; it's worth a try and has a broad set of tutorials and examples for your needs. Most of the material is useable with jWasm, which is a nearly 100% MASM clone, which you can use under Linux, too. Another alternative would be SolAsm.

I hope that helps a bit for the first steps.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 3437
    • MasmBasic
Re: Some starter questions about assembly language
« Reply #2 on: July 23, 2013, 09:24:47 AM »
Hi coinop,
Welcome to the forum :icon14:

New to asm but not new to programming: What has been your favourite programming language till now, and how much experience do you have? What are your objectives?

Adding to Gunther's advice: Have a look at Tips, Tricks and Traps (you can safely ignore the green text).

dedndave

  • Member
  • *****
  • Posts: 6795
  • Still using Abacus 2.0
Re: Some starter questions about assembly language
« Reply #3 on: July 23, 2013, 10:03:51 AM »
personally, i would suggest saving yourself the cost of any book

if you install the masm32 package,
there are help files, tutorials, and numerous examples
any questions - pop into the forum :P

japheth

  • Member
  • ***
  • Posts: 359
Re: Some starter questions about assembly language
« Reply #4 on: July 23, 2013, 05:09:18 PM »
Hello,

How complex is it to adapt to NASM from a MASM perspective.

It is fairly complex. It's usually no problem ... if you are familiar with both Nasm and Masm  :bgrin: ( but even then, there are not just differences in syntax, but differences in capabilities, which sometimes makes it very hard  to find the equivalent code for the "other" assembler ).

Quote
As a side note, after NASM, I would like to try to work with Flat Assembler. These assemblers are available for Linux as well, which is important to me. I don't want to tackle the GNU assembler, because from looking at various references, it is the most "different" of the main stream assemblers.

For Linux, NASM is the better choice - because it has full support for position-independent code ( at least in theory - I haven't seen a good example in Nasm yet! ).


Was fällt, das soll man auch noch stoßen!

Zen

  • Member
  • ***
  • Posts: 433
  • slightly red-shifted
Re: Some starter questions about assembly language
« Reply #5 on: July 24, 2013, 03:41:42 AM »
COINOP,   
Hi. We get alot of questions about Kip Irvine's, "Assembly Language for x86 Processors". I bought the Fifth Edition myself and used it as a reference while learning Assembly Language programming. Large portions of his book are obsolete (all the 16-bit stuff, which won't run on any Windows operating system above XP). Also, he creates a library of routines that is mostly incompatible with the libraries and code examples that come with the MASM package. His code examples are overly simplistic to the point of being almost useless,...and, it is generally quite confusing for beginners when they try to integrate code examples derived from the more stable and reliable MASM package. It is best avoided.
« Last Edit: July 25, 2013, 03:15:05 AM by Zen »
Zen

coinop

  • Guest
Re: Some starter questions about assembly language
« Reply #6 on: July 24, 2013, 04:21:29 AM »
Thanks for the great responses.

I have some experience in C, but I have not yet done system level programming.

I did try http://www.drpaulcarter.com and the pc assembly tutorial last night, and I have to say, it's an excellent introduction so I will try to complete it. I'm glad that the last response was about the book I was interested in. I decided to skip the book.

I came up with a couple of new questions -

Is there a good text, that is up to date that I can use as a reference with the paul carter tutorial?

Also, I understand the Intel manuals are available as well as the AMD manuals. Which volumes should I have in my library at a minimum.

Vortex

  • Member
  • *****
  • Posts: 1205
Re: Some starter questions about assembly language
« Reply #7 on: July 24, 2013, 06:07:42 AM »
Hi coinop,

Welcome to the forum.

Quote
I don't want to tackle the GNU assembler, because from looking at various references, it is the most "different" of the main stream assemblers.

While GAS supports the Intel syntax, it lacks HLL constructs making easier programming :

Code: [Select]
.intel_syntax noprefix
.global _start

.include "invoke.inc"
.include "Dlgbox.inc"

.globl _start

.data

DlgName:
.asciz "MyDialog"

.bss

hInstance:
    .long 0

hCursor:
    .long 0

.text

_start:

    invoke  GetModuleHandle,0
    mov     hInstance,eax
   
    invoke  DialogBoxParam,hInstance,"OFFSET DlgName",0,"OFFSET DlgProc",0
           
    invoke  ExitProcess,eax


// DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

DlgProc:

    push    ebp
    mov     ebp,esp

    cmp     dword ptr [ebp+uMsg], WM_CLOSE
            jne     initdlg
            invoke  EndDialog,[ebp+hWnd],0
            jmp     true

initdlg:

    cmp     dword ptr [ebp+uMsg], WM_INITDIALOG
            jne     setcursor
            invoke  LoadCursor,0,IDC_CROSS
            mov     hCursor,eax
            jmp     true

setcursor:

    cmp     dword ptr [ebp+uMsg], WM_SETCURSOR

jne       false
invoke    SetCursor,hCursor
jmp       true

false:

    xor     eax,eax
    pop     ebp
    ret     4*4

true:

    mov     eax,1
    pop     ebp
    ret     4*4

// DlgProc ENDP

// END start

Gunther

  • Member
  • *****
  • Posts: 2854
  • Forgive your enemies, but never forget their names
Re: Some starter questions about assembly language
« Reply #8 on: July 24, 2013, 06:51:35 AM »
Hi coinop,

I did try http://www.drpaulcarter.com and the pc assembly tutorial last night, and I have to say, it's an excellent introduction so I will try to complete it. I'm glad that the last response was about the book I was interested in. I decided to skip the book.

yes, Paul Carter's book is an excellent introduction; I'm using it to teach my students. There are some missing points, for example the SIMD programming technique, but that's okay for starters.

I came up with a couple of new questions -

Is there a good text, that is up to date that I can use as a reference with the paul carter tutorial?

Also, I understand the Intel manuals are available as well as the AMD manuals. Which volumes should I have in my library at a minimum.

Carter has a lot of text and explanations in the book. But the vendor manuals from Intel and AMD are a good supplement. You should download all for instruction reference. That's enough for a few months, I think.

Gunther
Get your facts first, and then you can distort them.

coinop

  • Guest
Re: Some starter questions about assembly language
« Reply #9 on: July 24, 2013, 01:42:02 PM »
Vortex, I think I will stay away from gas for now.

Gunther, I think that's the best route for now. Paul Carters book and the Intel manuals.

btw Gunther - you mentioned you had students. What level of school are you teaching at? Since you mentioned a SIMD programming technique (I'm not familiar with this yet); is this something current that is very important to schools? or as you mentioned maybe not critical for starters.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 1902
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Some starter questions about assembly language
« Reply #10 on: July 24, 2013, 02:50:03 PM »
coinop,

The OS you wish to work on will be the main decider of what tools you use to develop with, if you are aiming at Linux then NASM, JWASM or GAS using Intel notation are probably the best choices. If you are targetting a Windows platform, you have the choices of MASM and compatibles (JWASM), FASM and NASM. TASM is just too old. Of this choice the best support and range of code examples is in MASM and compatible assemblers, FASM is an excellent assembler and very powerful once you know how to use it but it does not have the support base of MASM. NASM is also a well written powerful assembler but it is more pointed at cross platform compatibility that ease of use.

As far as instructions to learn, always start with the basic components, MOV, ADD, SUB, CMP, TEST, ROL/R, etc .... as these common instructions do the lion share of the work. SIMD instructions are specialised and targetted at streaming multimedia data and while they are often used for other purposes, you really need to know the basic stuff first. Get used to the complex addressing modes "mov eax, [ecx+edx*4+64]" style notation and the instruction component order "mov eax, 1234" means move the immediate value of 1234 into the EAX register.

It is a lot to learn but its a ton of fun once you get the swing of it and there is real pace and power in mastering this style of code.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Gunther

  • Member
  • *****
  • Posts: 2854
  • Forgive your enemies, but never forget their names
Re: Some starter questions about assembly language
« Reply #11 on: July 24, 2013, 11:05:26 PM »
Hi coinop,

Gunther, I think that's the best route for now. Paul Carters book and the Intel manuals.

Yes, go that way. It's a good plan.

btw Gunther - you mentioned you had students. What level of school are you teaching at?

I've two jobs since 4 years. First I'm teaching mathematics, physics and computer science at a university in Berlin. My second job is a real teacher job at a high school in the Brandenburg area (mostly mathematics for scholars of the last school grade).

Since you mentioned a SIMD programming technique (I'm not familiar with this yet); is this something current that is very important to schools? or as you mentioned maybe not critical for starters.

SIMD stands for Single Instruction Multiple Data. It comes from the main frame vector computers and was introduced first with Apple's AltiVec followed by Intel's MMX technology. But I stay with Hutch: first things first. You'll have to learn the basic components, the different addressing schemes, how to program an alternative, loop etc. etc. That's all described well by Paul Carter. Moreover, he shows the usage of the old floating point unit and how to combine high level languages, like C, with assembly language. If that's done, you can go forward to the fancy SIMD instructions.

If you should have any questions (and I'm sure you will), post your code here and a lot of skilled programmers will help you. That's for sure.

Gunther
Get your facts first, and then you can distort them.

coinop

  • Guest
Re: Some starter questions about assembly language
« Reply #12 on: July 25, 2013, 02:41:55 AM »
Great, thanks everyone. That takes care of my questions. After this I will be asking specific asm questions.

Gunther

  • Member
  • *****
  • Posts: 2854
  • Forgive your enemies, but never forget their names
Re: Some starter questions about assembly language
« Reply #13 on: July 25, 2013, 04:17:51 AM »
Hi coinop,

Great, thanks everyone. That takes care of my questions. After this I will be asking specific asm questions.

you're welcome. Go forward and post some interesting questions. We're curious.

Gunther
Get your facts first, and then you can distort them.

Vortex

  • Member
  • *****
  • Posts: 1205
Re: Some starter questions about assembly language
« Reply #14 on: July 25, 2013, 06:14:33 AM »
Hi coinop,

Quote
Vortex, I think I will stay away from gas for now.

You are right. Macro assemblers like Masm,Poasm and JWasm are much more easy to use.