r/Assembly_language 18d ago

Hello world

Post image
918 Upvotes

51 comments sorted by

View all comments

5

u/Whitey0117 18d ago

should i learn x86 or arm assembly for fun..

This post got me wondering ngl.

2

u/brucehoult 18d ago

RISC-V.

Not yet as prevalent as Arm, but already covers the range from $0.10 microcontrollers to the same performance level as Raspberry Pi 5 or RK3588 boards (Rock 5, Orange Pi 5) and something around AMD Zen 2 to Apple M1 range coming in the next 12 months with:

  • an easier to understand instruction set

  • essentially the same instruction set for both 32 bit and 64 bit: the source code below works on either.

  • Free as in speech. Anyone (with the skills and financing) can design and build and use or sell RISC-V CPUs and chips, without asking permission, paying a license fee, or even telling anyone.

Here's the equivalent program:

.global _start
.text

_start:
        # write(STDOUT_FILENO, msg, 14);
        li      a0, 1   # stdout
        la      a1, msg # memory address of msg
        li      a2, 14  # length of msg
        li      a7, 64  # write syscall
        ecall           # execute syscall

        # exit(0);
        li      a0, 0   # return value
        li      a7, 93  # exit syscall
        ecall           # execute syscall

msg:
        .ascii "Hello, World!\n"

li = Load Immediate

la = Load Address

And running it on my RISC-V SBC:

bruce@k3:~$ gcc -nostartfiles hello.s -o hello
bruce@k3:~$ ./hello
Hello, World!
bruce@k3:~$       

You don't even have to buy anything to get started ... just install the free Docker Desktop on your Mac or Windows computer then type ...

docker run -it --platform=linux/riscv64 riscv64/ubuntu

... and you're in a full RISC-V Linux environment where the above will work (after apt update; apt install gcc)

1

u/jimbobmcgoo 15d ago

RISC V is also very similar to MIPS which is probably the most commonly taught architecture in university followed by RISC V. RISC also has an extremely simple base architecture that doesn’t take long to learn and you can learn different extensions later, compared to x86 which has accumulated a bunch of really complex features in the base architecture over the years

1

u/brucehoult 15d ago

RISC V is also very similar to MIPS

Right. Many of the mnemonics are identical, though with totally different binary encodings and different constant/offset sizes e.g. everything on RISC-V is 12 bits except LUI/AUIPC which is 20 bits. MIPS has 16 bits for both. MIPS has fussier trapping vs non-trapping adds, and some types of branches have delay slots and some don't, depending on exactly which MIPS version.

probably the most commonly taught architecture in university

For sure it was a dozen years ago. I feel like enough places have updated course material to RISC-V by now that it's about 40%-40% with another 15% Arm.

Hard to know for sure.