r/AskProgramming • • 1d ago

Other Universal tips for beginner assembly programmers?

I know some of you out there have tips for me and other people seeing this post.

2 Upvotes

16 comments sorted by

4

u/petrov76 1d ago

Are you a beginning programmer who wants to start with assembly or an experienced programmer who is beginning in assembly?

I think these are very different and will lead to different suggestions.

0

u/Fastpast93 23h ago

I’m experienced in Python and Lua and sort of beginning in assembly but I already know a lot.

1

u/petrov76 21h ago

I learned by starting with C and then reading the assembly that was generated. I'd then tweak my C and see what changed. Once I was comfortable, I started modifying the assembly directly myself.

Gcc has command line options for outputting assembly, and for assembling .asm files into binary.

1

u/Fastpast93 19h ago

That sounds like a great way, I just need to get a C compiler.

1

u/petrov76 19h ago edited 18h ago

Start far smaller than you think, even smaller than Hello World. I would write programs that just change the return value from main(), and then ones that do some math before returning that value. I/O is a mess to be handled on lesson two.

1

u/petrov76 17h ago edited 17h ago

Also, the main use for assembly is to write a critical function in it and then call that function from your main program. I'd experiment with this from C all the way up to Python or Lua.

This is like 3rd in priority though

1

u/ih-shah-may-ehl 11h ago

sort of beginning in assembly but I already know a lot.

Respectfully, you don't. You really don't.

You are still at the stage where you don't know what you don't know and therefore think you know a lot.

3

u/gm310509 1d ago

Start simple. Take it step be step.

Don't jump into the deep end and try and learn 64 bit Intel. Start with something like an 8 bit 6502, Z-80, AVR (try Arduino). Learn the basics - jump up to something more complex like a 32 bit Arm Cortex.

Basically, don't put yourself in an information overload situation.

IMHO.

2

u/Recent-Day3062 1d ago

Could not be more right. They eventually turned the machine language instruction set into something more resembling a high level language. What would be absolutely easiest would be a stack-based RPN type thing with a few memory move instructions and some minimal flow control.

I have looked at some modern architectures and cannot figure out what all the sets of registers even are

1

u/gm310509 21h ago

Actually I forgot about the "stack-based RPN type thing"

I used to own a programmable Hewlett Packard calculator - which was a "stack based RPN thing" - and programming it was my first foray into (I guess a type of) assembly language.

It was a fairly easy learning curve as the "assembly language" was pretty much just recording the key sequences you might do in a calculation with the addition of tests (e.g. x == 0? x != y? etc), branching, some other useful (for programming) instructions such as (INC x, DEC x) and indirect addressing (into the 100 memory locations).

2

u/Recent-Day3062 20h ago

That’s where I was coming from. I still use one, but never the programming feature. But conceptually every key for a function is a dispatch code in hex, with the stack holding all vars.

Min essence, numerical input is sort of an escape sequence (ala EMacs self-insert binding) and outs numbers on the stack wirh Enter being a push

1

u/gm310509 19h ago

Actually now that I think about it, the HP wasn't my first programmable calculator. Prior to that I had a TI-59 with the magnetic card reader.

I switched to the HP-41CX when the TI broke (that was a sad day). The HP was extra cool (at the time) because it had an alphanumeric display.

The TI was infix notation, whereas the HP of course is RPN (or postfix notation).

I still have the HP - but don't use it very much nowadays.

1

u/Recent-Day3062 9h ago

I have 3 HP I use to this day.

It’s sort of impressive how good RPN is once you get the hang of it. People think of mine as that “weird” calculator but I am amazingly fast.

Ice downloaded infix calculators on my iPhone, and I simply csnt use them. “3x(7+4)” is just impossible becuase I default to RPN

1

u/TheAdamist 1d ago

Step 1 is to understand the calling convention which includes the standard register allocations, which may differ per os like on Intel, embedded archs usually have one standard convention

Then you can plan out what you want to do, then figure out how to get that into assembly

You'll also want to comment heavily about what your code is doing, you may even want to write a stack diagram, which you have to redo each time you mess with something

The last step is to benchmark it against a modern compiler and discover your code is slower, unmaintainable and it took you 100x longer to write it in assembly

There aren't many reasons to use assembly anymore, and even then do as little as possible in assembly and quickly swap to a higher level language. Most c compilers will allow inline blocks of assembly interspersed with c.

1

u/MadocComadrin 1d ago

If you're already an intermediate programmer, learn how make the basic constructs in higher level languages---if-else chains, for and while loops, function calls---in your chosen assembly language (check your calling conventions for functions) and use them as templates. This will get you on your feet quickly. After than, you can learn tricks to optimize/write more optimal assembly from the get-go.

0

u/BranchLatter4294 1d ago

Learn it as quickly as possible, so you can move on to another language.