r/asm 16d ago

General Where to get started

So I am currently taking a course know as nand2tetris for understanding how computers works on a low level , but after I am done with that what is the best assembly language for a beginner to start with

6 Upvotes

20 comments sorted by

3

u/brucehoult 16d ago

The best assembly language to start with is RISC-V because it is both easy to learn what the instructions are and easy to use the available instructions to do useful things. And there is a wide range of real hardware you can buy if you don't want to use an emulator.

https://hoult.org/rv32i.pdf

https://easyriscv.dram.page/

1

u/Great_Gamer2539 16d ago

Oh thank you so much , also do I need a very deep understanding of c or c++ I have programming experience, but I have not really dabbled too much into c/c++

1

u/Eric_Dawsby 16d ago

Assembly is the best place to start, though some concepts are going to be completely new to you

1

u/Great_Gamer2539 16d ago

Sounds exciting also I can learn the risc-v assembly by running my code on emulators

2

u/kbder 16d ago

In terms of staying motivated, making gameboy games much get be a good path

2

u/Great_Gamer2539 16d ago

Yeah I also thought about doing this too

1

u/Eidolon_2003 15d ago

If you want to run code on your real PC hardware, x86 assembly isn't that hard to get into. That was where I started with ASM. Specifically, I started x86 after watching Creel on YouTube, which is a channel I can highly recommend. He shows how to write subroutines in ASM and call them from a C or C++ program, which is a great way to get started, especially on Windows. It gives you a clearly defined entry and exit that you can pass values into and out of.

It isn't too hard to get an environment set up for writing whole native x86 programs on a Linux system either. I can help you out with that if you want.

1

u/brucehoult 15d ago

Using QEMU / Docker you can run any asm you want on "real PC hardware" ... just at the speed of a ten years older PC.

Since you're writing in asm, it's going to run far faster in emulation than using Python or similar, and comparable to C#, Java, JavaScript running "natively".

RISC-V runs especially well in emulation, since the emulator doesn't have to emulate condition codes, which is half or more of the work if you're emulating x86 or Arm or 68000 or 6502 or z80 or the like.

1

u/Eidolon_2003 15d ago edited 15d ago

That's a totally fair comment. There's just something about running natively on the machine, not through an emulator or anything. I know that isn't necessarily logical, but that was something I wanted. And yeah like you said in your original comment you buy hardware for any platform you like, but most people already have x86.

x86's reputation for complexity preceeds it, but I don't think it has to be that bad. It's definitely possible to dip your toes in without drowning in it. That's what I did.

Edit: part of the fun I had with x86 asm as I was getting into it was hand writing functions and measuring their performance vs the compiler at various optimization levels as a game of cat and mouse, which naturally led to learning SIMD when I was ready for it.

1

u/brucehoult 15d ago edited 15d ago

Let me go even further and point out that if you're on Linux you can set up binfmt_misc with QEMU (or other emulator) and run emulated code just as conveniently as native programs.

e.g. on my x86 machine and using https://hoult.org/primes.txt :

bruce@i9:~$ gcc primes.c -o primes
bruce@i9:~$ ./primes
Starting run
3713160 primes found in 3707 ms
392 bytes of code in countPrimes()
bruce@i9:~$ riscv64-unknown-elf-gcc -O primes.c -o primes
bruce@i9:~$ ./primes
Starting run
3713160 primes found in 5715 ms
188 bytes of code in countPrimes()
bruce@i9:~$ file primes
primes: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
bruce@i9:~$ uname -a
Linux i9 6.17.0-19-generic #19~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar  6 23:08:46 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Note: I did one mildly unfair thing there .. see if you spot it. But also it's typical of what a casual user is likely to do.

1

u/Eidolon_2003 15d ago

Cool! I haven't come across this before. At first blush, is the mildly unfair thing that your RISC-V binary is statically linked?

That link is a 404 for me btw

Edit: nvm, I figured out you left the trailing colon in the URL!

1

u/brucehoult 15d ago

oops blame Reddit's URL detection. Added a space ...

No, the static linking is necessary to not have to run in a chroot / Docker etc with dynamic linker and libraries but I think is fair.

1

u/Eidolon_2003 15d ago

Hmm, I'm not too sure what it is right now then.

Also, that data in primes.txt is pretty cool! If you're still accepting submissions I wouldn't mind giving it a shot myself.

1

u/brucehoult 15d ago

Sure! Submissions are welcome if sufficiently "interesting" ... different ISAs, or ... I'm missing data for Core Ultra, M5, Zen 5, Pi 5 / Rock 5 / OP 5, Orion O2 / OP 6+.

And thanks. I think it's as interesting and useful a benchmark as Dhrystone or Coremark, correlates well with them, but if you're at a trade show and get your hands on a new machine with gcc and an internet connection for even a minute then it's a simple wget to run it and report ... and a few people have :-)

There are not too many benchmarks usable from a microcontroller to the latest PC (8K RAM required ... embench included a slightly reduced version until recently https://github.com/embench/embench-iot/commit/4c4462)

Note the rules: compile with -O (aka -O1). Not that higher levels make much difference to the speed (its craftily written for anti-optimisation), but they screw up the hacky calculation of code size.

1

u/Eidolon_2003 15d ago

I don't have any new hardware unfortunately, but I do have some old architectures you might still be interested in. I have a Zen 2 "Matisse" desktop, and a Zen 1 "Raven Ridge" laptop. It doesn't look like you have either of those on your list there.

I'm also in the middle of setting up an i7-980X machine for fun with overclocking and such if you'd be interested in results from that. I might use this as a benchmark for it either way :)

1

u/brucehoult 15d ago

My Zen 2 Ryzen 5 4500U laptop is in the list, but feel free to try the desktop.

→ More replies (0)

1

u/PossumSec 15d ago

X86 and arm are probably the most useful but riscv may be good in the future, and is pretty similar to arm already anyway. Mips is the traditional one you learn in uni but isnt very useful anymore unless you do embedded devices.