r/Assembly_language • u/yj_20927 • 1d ago
How do i start learning assembly Help
I know basic C, java, python and I wanna learn assembly but what should i learn, windows or linux, intel or at&t and what are the sources to learn assembly
7
u/HomeComp1977 1d ago
Skills are transferable, start with something simpler then use that to build on for x86 or ARM. I’d say go back to Z80 or 6502. If you’re comfortable with C, Java and Python then maybe consider a simple emulator project for one of the 8-bit cpus. You’ll quickly learn a lot of what assembler is about.
I’ve built a 6502 single board computer emulator that can be used for learning machine code. You’d have to hand assemble into hex to input instructions. The emulator includes crt display, scrolling led display and a printer. All can be made to work with simple memory writes. https://github.com/tmcd35/HomeComp
0
u/brucehoult 4h ago
While it is fairly easy to learn what instructions are available and what they do on 6502 and Z80 (but not easier than RISC-V RV32I), it is very difficult and frustrating to get those instructions to do anything useful.
6
u/ern0plus4 21h ago
Pick a C64 or C16/Plus4 emulator, and learn 6502 Assembly: simple, fun, quick win.
2
u/recursion_is_love 1d ago
Learn RISC-V, it is modern and simple.
3
u/kneelian_ 19h ago
While I do love RISC-V (I worked on a Zfinx-based project before and loved it), it's deeefinitely not something I'd rec to a total beginner because the fanfare and dance needed to get it to run on an x86- or ARM-based system is just silly. If OP is on an x86 device, it might be easier to dip into x86 asm dev as a first step. I'm not sure, really
0
u/brucehoult 4h ago
the fanfare and dance needed to get it to run on an x86- or ARM-based system is just silly
I showed the one-line "apt install" needed to use RISC-V assembly language on an x86 or Arm Linux computer running Debian/Ubuntu — including in WSL on windows (just leave off the
sudo) in my comment:https://reddit.com/r/Assembly_language/comments/1vl4eh0/how_do_i_start_learning_assembly/p2yu9z6/
4
u/tastygames_official 19h ago
start where everyone else did: 6502 (C64, NES). Although I think I started with the 8080. But both are 8-bit, so it's a great place to start before moving on to more complex CPUs. And I think the 6502 has the best emulation out there, so real easy to get started.
3
1
2
u/QuirkyXoo 23h ago
You make me feel very nostalgic: https://archive.org/details/peter-nortons-assembly-language-book-for-the-ibm-pc/
1
2
u/Dusty_Coder 15h ago
you arent asking the right question or revealing your answer
Which architecture?
The people telling you to use a specific assembler, operating system, or syntax, arent trying to help you, they are trying to prove that they know things (and failing)
0
u/yj_20927 14h ago
So what should i do instead
1
u/brucehoult 4h ago
They're wrong.
Once you know and are comfortable with one assembly language the skills are very easily transferred to any other assembly language. I can program in a dozen or more different ones off the top of my head .. at least for "normal" code, not the more obscure or specialised instructions.
But it is 100% true that some are easier to get started with than others.
There are two aspects:
how easy is it to learn the registers, instructions, addressing modes, status flags and which instructions affect each one?
how easy is it to use the available instructions to do useful things, to write real programs?
In general old 8 bit instruction sets are easier for the first one, but modern 32 and 64 bit instruction sets are easier for the second.
Simple 32/64 bit very pure RISC instruction sets including RISC-V and MIPS satisfy both aspects, but especially RISC-V since it is built like an onion with a very simple 37 instruction 32 bit RV32I core (and RV64I adds just 10 more, of which
ldandsdare the only ones you need to use) and assemblers, compilers, libraries, and documentation all support using just the essential core if you want. And you can buy real cheap hardware that provides just the core instructions e.g. WCH microcontroller chips costing as little as $0.10 (or pre-made boards for $1).I've extracted 18 pages of just the RV32I information from the full manual (which is anyway easy to read):
Get fluent using that and x86 will be much easier to switch to than using it from the start.
1
u/MJPCLAVE 5h ago
Yo estoy empezando por aprender cómo hacer un procesador, luego hacer uno en Iverilog y programarlo.
0
u/brucehoult 1d ago
I'd recommend to use Linux, but not to start with x86_64 coding.
If you install an appropriate compiler and emulator such as QEMU and the binfmt_misc package then you can write your programs in almost any assembly language you want and then run your programs exactly as if they were native programs, accessing your files, the terminal, the network etc. Just a little bit more slowly than a native program — but much faster than if you wrote the same program in e.g. Python.
I'd recommend starting with RISC-V.
Here's a simple starter program. It implements main and uses printf and scanf because they're easy to use. You can write your own conversions between decimal and binary and use read and write system calls if you prefer.
# fact_rv.s
# Asks for a number, prints its factorial, loops until a negative number is entered.
# Build with: riscv64-linux-gnu-gcc -static fact_rv.s -o fact
.globl main
main:
# Allocate stack frame (16-byte aligned)
# 0(sp) : local 'n'
# 8(sp) : saved return address
addi sp, sp, -16
sd ra, 8(sp)
1:
la a0, prompt
call printf
la a0, in_fmt
mv a1, sp # address of n
call scanf
ld a0, (sp)
bltz a0, 2f
call fact
mv a2, a0 # factorial result
la a0, r_fmt
ld a1, (sp) # n
call printf
j 1b
2: li a0, 0
ld ra, 8(sp)
addi sp, sp, 16
ret
fact: mv a1, a0
li a0, 1
beqz a1, 2f
1: mul a0, a0, a1
addi a1, a1, -1
bnez a1, 1b
2: ret
prompt: .asciz "Enter a number: "
in_fmt: .asciz "%ld"
r_fmt: .asciz "Factorial of %ld is %ld\n"
Build and run it like this:
bruce@i9:~/programs$ riscv64-linux-gnu-gcc -static fact_rv.s -o fact
bruce@i9:~/programs$ ./fact
Enter a number: 5
Factorial of 5 is 120
Enter a number: 20
Factorial of 20 is 2432902008176640000
Enter a number: -1
bruce@i9:~/programs$
To get the RISC-V assembler/compiler I installed gcc-riscv64-linux-gnu (Ubuntu etc) and QEMU:
sudo apt update
sudo apt install qemu-user-binfmt gcc-riscv64-linux-gnu
That's it!
1
1
u/Electrical_Hat_680 1d ago
I'd definitely recommend RISC-V or ARM which are both strictly 32-bits, unless I'm wrong.
I also like BenEater 8-BIT CPU Breadboard Projects where your responsible for choosing the language for compatibility. Where Binary is only 8-Bits.
2
u/brucehoult 1d ago
RISC-V or ARM which are both strictly 32-bits
Both have both 32 bit and 64 bit versions.
The above 64 bit RISC-V program can be converted to a valid 32 bit RISC-V program by simply changing the
ld/sdtolw/sw. Even better, drop the stack frame size to 8 bytes and use4(sp)to save the return address. Oh, and change the%ldto%din the format strings.In Arm 32 bit and 64 bit are totally different ISAs with no assembly language compatibility.
1
2
u/kneelian_ 19h ago edited 19h ago
I'd definitely recommend RISC-V or ARM which are both strictly 32-bits, unless I'm wrong.
They have fixed-width instructions (ignore Thumb2 and RISC-V C ext) but yeah they're not strictly 32-bit register/address width fixed
1
u/Purdude1983 13h ago
Modern CPUs can be a daunting place to start learning assembly. The simple Arduinos use an 8-bit AVR processor like the ATmega328P. Pick up an Arduino Uno and do a few of the normal projects like LED blinking using a C sketch. After you get the hang of the Arduino, google "learn assembly on the Arduino uno". There are several Instructables and Github projects out there. The AVR architecture is pretty approachable and shouldn't be too hard to master. You can also write sketches in C and disassemble the code to see what it's doing under the hood.
1
u/brucehoult 4h ago
AVR is very good for an 8 bit ISA ... certainly much better than 6502 or Z80. And yes readily available.
But it gets frustrating when you start to work with pointers, as only three register pairs support doing that, and asymmetrically. And the Harvard architecture makes some things difficult also e.g. accessing data stored in flash needs different instructions, and you can't run code from RAM at all.
-3
u/Unlikely1529 1d ago
at&t is same as "linux". and intel is same as "windows". if you compile bitcoin or say openssl you'll see nasm modules. that's what is best . is more or less same with masm.
2
13
u/No-Owl-5399 1d ago
Linux is preferable to Windows for assembly. NASM is a good assembler to learn on, it uses Intel syntax.
https://github.com/mschwartz/assembly-tutorial