flat assembler
Message board for the users of flat assembler.

Index > Main > How to get into assembly programming

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Hello Community,

I'm new here and wanted to introduce myself:
I'm a software developer and I'm programming for over a decade. Languages im using at work are mostly C#, Python and a little bit of C++.

I've always wanted to learn assembly for my hobby projects outside of work and had many attempts to get into assembly. I've chosen fasm over other assemblers mostly because of it's clean syntax, and it's portability. I've tried masm and gas already and looked also a bit into nasm. Masm is just for windows, gas syntax is horror and nasm.. don't know.. just doesn't feel right... Fasm just feels "good", dunno how to explain.

However, when I start up fasmw and look at the blank document I feel really lost as I don't know what to type. Feels a bit like 15 years ago when I started to learn programming. It's really hard to get into assembly and create something that goes beyond the scope of a hello world programm for an absolute beginner.
I get stuck on very simple tasks very quickly, simple string manipulation, creating simple arrays and process them and all that basic stuff.
It's also hard to find any helpful resources on the net. For example when I type "Python string manipulation" into Google, I get hundreds of good results that I could learn from. If I type the same for fasm or asm I literally get no helpful result. Same goes for msdn, all examples are for c. And I'm having a hard time converting them into assembly.
I wouldn't call my self I pro in programming but I'm not a newb either. Though getting into assembly is pretty hard for a newb in assembly.

How did you guys started to learn assembly? Did you feel the same when you started with assembly? What did you do against it? How did you manage to get into assembly and don't end up loosing interest due to the big hurdle to overcome to get at least a bit fluent in assembly.
Post 03 Nov 2019, 10:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
When you download fasm you also get a few example sources. They might help you to get started. Have you seen them? Try to assemble and run them. As least then you can check that you have set everything up correctly.
Post 03 Nov 2019, 11:27
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 702
Location: Belarus
DimonSoft
Getting into assembly after C# and Python is like trying to dive with large helium balloons tied to your feet. These languages hide a lot of stuff that goes under the hood and most books just pretend it’s OK for people using these languages to know close to nothing about that stuff (spoiler: they’re absolutely wrong, that’s why most software these days is slow and bloated). C++ doesn’t help much as well.

I’d suggest you to recall every piece of generic information you should have known about computer internals, memory, about how integers, floats and strings are represented in memory, about what actually happens when you build your program. The next step is to know your execution environment and OS: it’s quite hard for a beginner to write something useful absolutely from scratch, and even for an advanced programmer it always makes sense to reuse the things you already have anyway like OS API. After that you’ll have a better feeling of what you can do and more specific questions on how to do particular things. BTW, if you target, say, Windows, writing WinAPI-programs in some HLL for a while might make is easier. Delphi used to make this even easier, but plain C might do the thing as well, except for the thousands of hidden traps of undefined behaviour and language inconsistencies, that are easily understandable but only after you’re OK with low-level programming.

Actually, that’s exactly the reason why starting with Python-like languages is generally a one-way road in programming: such languages hide the platform-specific stuff and encourage a newbie to stay completely agnostic of it, which later makes them write inefficient code for no valid reason and generally makes them unable to move “backwards”, back to the basics.
Post 03 Nov 2019, 11:44
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Hello,

thanks for the helpful answers.

Yes I've seen the examples and played with them a little bit. Tried to extend them and so on.

Yes, that's exactly where I'm at: I've never had to look behind the scenes to see what's going on there. Therefore I'm really stuck now.
Seems like that I have to really start from scratch again and learn the very basics of how a computer works.
But finding good up to date lectures about this in combination with the low level programming language of your choice (fasm) is hard, as it seems no one is really interested in this anymore.
As I played around with the examples, they crashed without any error message. I've set up ollydbg as jit debugger, but this doesn't help that much as I'm still not really understand what caused the crash. Therefore it's really hard to learn from the mistakes when one not really understands what's going on.
For example: at work when I'm stuck because of a crash or whatever, I'm stepping through the code with the debugger (visual studio) and it totally makes sense. If not, I just google it, and 95% I find a solution to the problem. Or i ask a college for help, like they ask me when they are stuck.
In assembly, the debugging makes no sense and in addition to that I find no good resources online that helps. This is one of the reasons that makes starting assembly programming so hard.

At work I have a workflow and I do exactly know what to do when I'm stuck.

In assembly however it feels like I have nothing. And posting every little problem that I have here in the forum, so proffesionals in assembly could tell me what is causing the error so I can learn from it does not sound like a good solution as it spams the forum.


Last edited by rc on 03 Nov 2019, 12:32; edited 1 time in total
Post 03 Nov 2019, 12:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
Post your code. We can help you to find the problem.
Post 03 Nov 2019, 12:31
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
I have no problem in particular at the moment. I would like to know how would you go for finding a problems cause besides debugging. What are your resources, as just typing the problem in google does not really help.
Kind of a guideline of how to structure a project in assembly. Where to learn the basics beyond the type of tutorials: "what are registers, what is the stack" and so on.
Kind of a route that I can take to improve.
I mean I know what registers are and there purpose and what's the stack. I know how to push/pop stuff from and to the stack, how to use registers and so on. Still I don't really know how to program in assembly. A bit hard to explain.


Last edited by rc on 03 Nov 2019, 13:33; edited 1 time in total
Post 03 Nov 2019, 12:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
I use a debugger as my primary tool when I have trouble. It gets right down to the precise problem quite quickly. The only time it fails is for logic errors where the code itself is fine but the algorithm (or the implementation of the algorithm) is flawed and I need to look at the higher abstract level to find where things have gone haywire.

However if a debugger is not for you, then another way to follow the progress of the code is to print lots of information to the console. But that is kind of like a poor implementation of a debugger, and it is quite a tedious method.
Post 03 Nov 2019, 13:02
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
What debugger do you use? In general, I prefer debuggers over print debugging. What is confusing though is, that unlike in high level languages you don't exactly step through the lines of code you have written. So you end up stepping through the code that the assembler has written out of your code. That's pretty confusing. I mean, that makes sense since you can't step through your macros and stuff line by line as they get converted into assembly as well, but that's confusing: what line in the debugger corresponds to the the line in my code. And also plain assembly code you have written is changed by the assembler due to optimization I guess.
Stepping through the debugger is a bit like: "hum, that's not what I have written, where am I right now.. and what is it doing.. "
That might sound pretty silly, but I guess that comes from working with visual studio 10 years, where you can step exactly through every line you have written and how you have written them.
Post 03 Nov 2019, 13:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
You can write assembly without any macros. That way in the debugger you will see every line you wrote in the source. For example this simple .com program demo has four lines of code, no macros:
Code:
; fasm example of writing 16-bit COM program

        org     100h                    ; code starts at offset 100h
        use16                           ; use 16-bit code

display_text = 9

        mov     ah,display_text
        mov     dx,hello
        int     21h

        int     20h

hello db 'Hello world!',24h    
In a debugger you would see the four instructions, followed by the text. Although the debugger might try to disassemble the text and show what looks like nonsense instructions following the int 20h.
Post 03 Nov 2019, 13:30
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Yeah that was what I was thinking too: would it make sense to start learning 16 bit assembly on DOS first? I have set up freeDOS on a vm, although I could probably use dosbox as well. Would you suggest me learning 16 bit first?
Post 03 Nov 2019, 13:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
If you are comfortable in DOS then .com programs are probably the most basic you can get. For a debugger in DOS the "Turbo debugger" is good IMO.
Post 03 Nov 2019, 13:48
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
I grew up during the end phase of dos where win 95 was coming. So I used dos in my childhood. Then I will probably start with fasm on DOS first. I will try the Turbo debugger. Thanks a lot for the help. Although this might not be the last time here me asking for help. Smile
Post 03 Nov 2019, 14:04
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
Hello rc and Welcome to the forum!
You raise good questions. There is not much information on FASM coding if you Google for it. As already mentioned, you can try the code samples provided in FASM download, but these are limited. You are asking about using registers and arrays - I believe the FASM manual, which you can find at same page as where FASM download is, can provide a bit of the register manipulation as well, but I think no arrays there. Also, please take a look at this tutorial:

https://blog.brakmic.com/intro-to-x86-assembly-with-fasm/

It is a start, but I think if you want arrays - you need to dig deeper.
By the way: (I am going to get self-promotional here) I had a web site once where you can find the IDE for FASM. It is not bad, even has a Help system, when you create a new project - it writes the startup code for you, so no blank page there. The site is gone now, but I can probably make a ZIP file with the IDE and post it.

Also, I would advise to start with Win32 coding - DOS is way old.
And use OllyDbg debugger - I find it even better than Microsoft debuggers from Visual Studio of today even. OllyDbg has a context information at the point where CPU is stopped, tells you all the parameters of Windows API, etc. Awesome debugger!
Post 03 Nov 2019, 16:04
View user's profile Send private message Send e-mail Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Thanks AsmGuru62.

Quote:
I had a web site once where you can find the IDE for FASM. It is not bad, even has a Help system, when you create a new project - it writes the startup code for you, so no blank page there. The site is gone now, but I can probably make a ZIP file with the IDE and post it.

This would be really nice of you.

Yes, i allready got a bit familiar with ollydbg.

Thanks for the tutorial link, this looks really informative.
Post 03 Nov 2019, 17:45
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7709
Location: Kraków, Poland
Tomasz Grysztar
If you don't mind some video tutorials, I have recently started making them myself. You can find links in the dedicated thread in the "Examples and Tutorials" forum.

Note that I only just started (and I'm in a middle of digression with the 2-adic mini-series, which is technically not a part of the basic tutorial) so only quite elementary things are shown so far.
Post 03 Nov 2019, 21:22
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 702
Location: Belarus
DimonSoft
rc wrote:
Yeah that was what I was thinking too: would it make sense to start learning 16 bit assembly on DOS first? I have set up freeDOS on a vm, although I could probably use dosbox as well. Would you suggest me learning 16 bit first?

Starting from MS-DOS programs is a good idea, just not very popular because most people think it is out-of-date, thus “not worth spending time”. In fact, it is absolutely good way to start since you get the simplest x86 environment possible which helps getting the feeling of the platform. You can always reuse the knowledge gained moving to Windows and protected mode.

But I’d suggest using a virtual machine with Windows XP for MS-DOS development and debugging these days. Much more comfortable compared to plain DOS or modern Windows + DOSBox. And the experience in using virtual machines is also quite useful anyway.
Post 03 Nov 2019, 21:55
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Hello Tomasz Grysztar,
nice to talk to the creator of fasm.
This tutorial series would exactly be what a beginner in (f)asm (like myself) would like to have when beginning. Starting slow with the very basics, and slowly go into more advanced topics like the winapi maybe.
Really appreciate your effort. Thanks a lot for these turorials! I like that you dont rush through the commands and take the time to show what exactly they are doing in the debugger!
Please don't stop making them, as they are probably the best resource on assembly on the net, especially for beginners with fasm.

@DimonSoft: Yes, i only do programming in VMs. I have a windows 10 host running a win10 developer vm. And also win7 testing enviroments. I never develop on host machines. I have set up qemu and freedos and already played around with fasmd. I really like dos i have to admit. To bad it is pretty outdated by now and nobody is using it anymore. But luckily i still have several WinXP copies lying around somewhere.


Last edited by rc on 03 Nov 2019, 22:22; edited 5 times in total
Post 03 Nov 2019, 21:59
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
Hi rc,
So, I attached the IDE to this post. No installer there, just unzip it.
First thing is to go to Help folder and open HTML file and read it.
This document is slightly outdated - I added few features to IDE after it was written, but never bothered to update HTML.


Description:
Download
Filename: FASMW32.zip
Filesize: 626.51 KB
Downloaded: 77 Time(s)

Post 03 Nov 2019, 22:01
View user's profile Send private message Send e-mail Reply with quote
rc



Joined: 03 Nov 2019
Posts: 38
Location: Germany
rc
Hi AsmGuru62,

thank you a lot for the upload. The ide is really nice! Such a project in assembly.. quite impressive!
Post 04 Nov 2019, 12:51
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
The best way to learn is by example and documentation, download the fasm manuals/examples and cpu manuals, then play with the examples, make changes, break them then fix it, then you will understand how it works.
Post 04 Nov 2019, 13:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.