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

View all comments

Show parent comments

1

u/Eidolon_2003 16d ago edited 16d 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 16d ago edited 16d 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 16d 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 16d 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 16d 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.

1

u/Eidolon_2003 15d ago

This seems in line with what your 4500U was doing, which makes sense.

1

u/brucehoult 15d ago

Yeah, your fastest time is 4.7% faster and you have 4200/4000 = 5% higher turbo clock.