DEV Community

Wassim bd
Wassim bd

Posted on

What I Learned Writing Assembly After Only Knowing Java and JavaScript

Before this semester, the lowest-level language I'd written was Java, with some JavaScript on top. Then my computer architecture course threw RISC-V assembly at me, and it completely changed how I think about what's actually happening when my code runs. Here's what stood out to me.

No more "just call a function"

In Java or JavaScript, you write something like:

function add(a, b) {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

You don't think about what happens underneath — you just call add(2, 3) and move on. In RISC-V assembly, there's no add() function waiting for you. You work directly with registers (small storage slots inside the CPU) and explicit instructions:

li a0, 2      # load value 2 into register a0
li a1, 3      # load value 3 into register a1
add a0, a0, a1  # a0 = a0 + a1
Enter fullscreen mode Exit fullscreen mode

Every single step is spelled out. There's no hidden machinery doing work for you — you are the machinery, in a sense.

Variables aren't really "variables" anymore

In JavaScript, a variable is a name that holds a value, and you don't worry about where that value physically lives. In assembly, you're constantly aware of where things are: which register holds which value, or where in memory something's stored. You run out of registers fast, so you have to be deliberate about what you keep close (in a register) versus what you push to memory.

This made me appreciate something I never thought about before: every time I write let x = 5; in JavaScript, the language is quietly handling register allocation and memory management for me. In assembly, that's my job.

There's actually a lot more to registers alone than I can fit here — what each one is typically used for, how many you actually get to work with, which ones are "yours" to use freely versus reserved for specific purposes. That's probably worth its own post at some point.

Functions calls are a whole production

Calling a function in a high-level language feels free. In RISC-V, a function call means manually:

  • Saving the values in registers you care about (so the function you're calling doesn't overwrite them)
  • Setting up the arguments in specific registers
  • Jumping to the function's instructions
  • Making sure the function knows where to return to
  • Restoring everything once it's back

Seeing this made me understand why function calls have a performance cost — something that's usually invisible in JS or Java, where it just feels instant.

Control flow without if/else

There's no if statement in RISC-V. Instead, you use branch instructions that jump to different parts of the code based on a comparison:

bge a0, a1, label   # if a0 >= a1, jump to "label"
Enter fullscreen mode Exit fullscreen mode

Writing an if/else block or a loop in JavaScript suddenly felt like a small miracle once I saw how many branch instructions and labels it takes to build the same logic manually.

Why this actually helped me as a web dev

I'm not planning to write assembly for my career, but this course changed how I think about high-level code:

  • I have a much better sense of why certain operations are "cheap" and others are "expensive" — it's less abstract once you've seen the actual instructions behind them.
  • Debugging feels different now. When something breaks in JavaScript, I have a mental model of what's happening underneath, instead of just treating it as a black box.
  • I have a lot more respect for what languages like Java and JavaScript are doing for me automatically — memory management, function call overhead, type handling — all of that is work I used to take for granted.

My takeaway

Assembly stripped away every convenience I didn't know I was relying on. It's slower to write and a lot less forgiving, but it made the "magic" of high-level languages a lot less mysterious. If you've only ever worked in high-level languages, I'd genuinely recommend trying even a small assembly exercise — it changes how you read your own code afterward.


Final-year software engineering student, writing about what I'm learning in my courses.

Top comments (0)