61 votes
Accepted

Decide if the sum of three numbers is even or odd

First off, you have nice, clean, well-formatted, easy-to-read code. You have even included comments that explain the goal of each instruction. Too much of the time I review assembly-language code, ...
Cody Gray - on strike's user avatar
45 votes
Accepted

Brainfuck Interpreter written in x86 Assembly

The comment ; *argv should be ; argv, since you are not yet dereferencing the pointer. After a ...
Roland Illig's user avatar
  • 21.3k
27 votes
Accepted

Checking if a number is prime in NASM Win64 Assembly

Style: Indent your operands to a consistent column, so mnemonics of different length don't make your code look so ragged. And use local .label labels inside ...
Peter Cordes's user avatar
  • 3,346
18 votes
Accepted

Euler's Totient Function in x86 assembly (MASM)

You're not using cdq properly. cdq sign extends EAX into ...
1201ProgramAlarm's user avatar
18 votes

Checking if a number is prime in NASM Win64 Assembly

There are numerous small things. You don't have to keep subtracting and adding 32 from rsp. Allocate the space once at the start of the function (...
1201ProgramAlarm's user avatar
16 votes

x86-64 Assembly - Sum of multiples of 3 or 5

if01 and if0 are not the greatest names. Instead of reloading r9, use two registers. Let <...
vnp's user avatar
  • 56.4k
15 votes
Accepted

Minimal `printf` for integer types in x86 assembly

If, for the sake of this exercise, codesize is the only thing that you care about, then I would dare suggest the following: For divq10, not having to reload the constant will save 5 bytes, and using <...
Sep Roland's user avatar
  • 4,408
13 votes

Decide if the sum of three numbers is even or odd

The beginning of your program obviously should be following the "HINT" and using xor instead of add. This is some really wacky ...
Quuxplusone's user avatar
  • 19.3k
13 votes
Accepted

x86-64 Assembly - Sum of multiples of 3 or 5

Here are some things that may help you improve your code. The other review made some good points, but here are some not covered there. Decide whether you're using stdlib or not The ...
Edward's user avatar
  • 66.4k
12 votes

Checking if CPU supports rdrand

Let's look at the inline assembly code that you have: You were correct to use the __volatile__ specifier here. That's a common mistake when writing inline asm, so ...
Cody Gray - on strike's user avatar
12 votes

string length in x64 assembly (fasm)

Saving rcx is usually not necessary, it is not callee-save in common calling conventions. On Linux (and similar) rdi also does ...
harold's user avatar
  • 9,474
12 votes
Accepted

Decoding assembly instructions in a Game Boy disassembler

I have some ideas about how you might be able to improve your program. Avoid problems Rather than trying to deal with the problem for every instruction, one approach is avoiding it entirely. One ...
Edward's user avatar
  • 66.4k
12 votes
Accepted

part of a c++ program which mods a game using code injection

It isn't clear why file_helper.h makes an attempt to be portable since code_injection.cpp is not portable. If you want most of ...
pacmaninbw's user avatar
  • 23.8k
11 votes
Accepted

ToyVM - a small and simple virtual machine in C - follow-up

I see some things that may help you improve your code. Don't leak memory The code for InitializeVM allocate memory for the ...
Edward's user avatar
  • 66.4k
11 votes
Accepted

ToyVM - a small and simple virtual machine in C + FizzBuzz demonstration

I see a number of things that may help you improve your code. Don't use const where it is forbidden Normally, I'd prefer to use ...
Edward's user avatar
  • 66.4k
11 votes

Assembly beginner exercise: Calculate the square numbers from 1 to n

The biggest problem here—and generally with assembly—is the use of registers in the code without explicit documentation of what those registers contain, e.g., in the form of comments. Certain ...
Cody Gray - on strike's user avatar
11 votes
Accepted

SSE loop to walk likely primes

Let's review this code purely from a performance angle, without a focus on style or anything else (in addition to optimization suggestions, Peter already mentioned several things in areas other than ...
BeeOnRope's user avatar
  • 228
11 votes

Measuring the clock rate of an Intel CPU in C++

There are a number of things that you might employ to improve your program. Accuracy Is there any reason the strategy used and described below won't produce accurate results? Yes! There are many ...
Edward's user avatar
  • 66.4k
11 votes

x86-64 Assembly - Sum of multiples of 3 or 5

A few quick notes on your implementation choices, and how I'd approach it: You don't need 64-bit operand-size for div when your numbers only go up to 1000, that's ...
Peter Cordes's user avatar
  • 3,346
10 votes
Accepted

Assembly beginner exercise: Calculate the square numbers from 1 to n

cmp eax, 1000000 ; When the number received is smaller the upper limit ... jle createSquareNumbers ; ... then you do not have to override it. mov ecx, ebp ; I ...
Sep Roland's user avatar
  • 4,408
10 votes
Accepted

Assembly program which detects all numbers with two integral divisors

mov ecx, 0 ; Counts how many division have This begs for an optimization in the form xor ecx, ecx. This will clear ...
Sep Roland's user avatar
  • 4,408
9 votes
Accepted

NASM tutorial (Linux syscalls, 64 bit) code with CI-build and test

When the function has finished it's logic, these registers should have their previous values The normal x86-64 System V calling convention allows functions to clobber RAX, RCX, RDX, RSI, RDI, and R8-...
Peter Cordes's user avatar
  • 3,346
9 votes

Minimal `printf` for integer types in x86 assembly

Make Your Function Modular and Re-Usable Let’s say you want to call fprintf( stderr, "Error opening file: s.\n", errMsg ); Your function can’t do that, ...
Davislor's user avatar
  • 7,371
8 votes
Accepted

Dijkstra's algorithm for computing the GCD of two integers, translated from C to x86 assembly

My thoughts (in no particular order): Short on comments. Assembler in particular benefits from comments. Uses a very conservative style (params passed on stack, all regs preserved, maintain stack ...
David Wohlferd's user avatar
8 votes
Accepted

Fast bitswap in assembly

I'm still a bit fuzzy on how to compute latency, but using iaca v2.2, it reports your code as: ...
David Wohlferd's user avatar
8 votes

Disassembler for intel 8080

C++ is not Java. While there is a valid use-case for classes treated as namespaces with a type-name, that's only for traits-classes used with templates, and not for general consumption. I don't know ...
Deduplicator's user avatar
  • 19.1k
8 votes
Accepted

Brainfreeze: A Brainfuck compiler in C

I'm mostly reviewing the code-gen choices, not the style / implementation of the compiler itself. The compiler itself mostly looks fine in the parts I've skimmed over (looking for how it uses the ...
Peter Cordes's user avatar
  • 3,346
8 votes

Remove leading zeroes from the beginning of a string

C doesn't match assembly for (size_t i = 0; i < strlen(number); i++) { You don't seem to actually be doing this. Your actual assembly is more like ...
mdfst13's user avatar
  • 21.6k
7 votes

ToyVM - a small and simple virtual machine in C + FizzBuzz demonstration

FizzBuzz When you write the string constants to memory using memcpy(), you need to copy the NUL terminator too. There is an odd gap in the program between offsets ...
200_success's user avatar
7 votes
Accepted

Sum up all odd numbers between 1 and 2n + 1

Random thoughts: A comment that indicates what/where read_hex returns might be useful. mov ebx, 2; mul ebx could probably be replaced with ...
David Wohlferd's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible