Cody Gray
  • Member for 5 years, 2 months
  • Last seen this week
Reading all file contents via x64 assembly
Accepted answer
2 votes

General/Style Line up instructions and operands in vertical columns to improve readability (like you've done with the comments); e.g.: mov var6, WINDOWS_NULL ; put pointer to ...

View answer
HSL->RGB and vice versa, plus Harmony and Tint, Tone, Shade, Saturate
5 votes

Specifics (Line-by-Line) struct color_RGB { float R; float G; float B; float a; }; Inconsistent capitalization of members: A should be capitalized here, just like R, G, and B. You ...

View answer
A simple shellcode that will kill all your processes GNU/Linux x86_64
2 votes

Line-by-line: xor rax, rax The only time you should ever explicitly clear a 64-bit register by XORing it with itself is when you want the extra code size for alignment reasons. Otherwise, just write ...

View answer
strlen and strcmp implementation in x86 FASM assembly
6 votes

strlen Correctness (Return Value): You are violating the convention for the strlen function, which is documented as returning the number of characters between the beginning of the string and the ...

View answer
C# RGBA to ARGB using shifts
Accepted answer
5 votes

When I see this question, I immediately understand what you are trying to do as a bitwise rotation (also known as a circular shift). You need to either rotate the bits in the value left by 24 or right ...

View answer
Decide if the sum of three numbers is even or odd
Accepted answer
60 votes

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, ...

View answer
Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors
7 votes

Lots of bad practices exhibited here… First of all, you probably shouldn't be using exception handling here at all, as Incomputable already pointed out in a comment. Exceptions should be for truly ...

View answer
Assembly beginner exercise: Calculate the square numbers from 1 to n
9 votes

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 ...

View answer
Find cells with specific formatting
7 votes

The basic construct you're looking for is a loop. This is what you should reach for any time you find yourself writing the same code (performing the same operation) over and over again, but in a ...

View answer
Safely handling memory allocation across DLL boundaries in Windows
3 votes

The standard (and recommended) way to solve this is for each module to provide its own exported AllocMem and FreeMem functions (or whatever you want to call them—the names are not important). This is ...

View answer
Find and print all numbers in a comma-delimited string using sscanf
Accepted answer
2 votes

Some general comments about your current code: You just dumped everything in the main method. This makes your code difficult to read, and more importantly, prevents it from being re-used. You should ...

View answer
Counting number of eights
3 votes

If you absolutely have to write this method recursively (see below), then the clearest, most readable, and most efficient way of doing so is the following: public int count8_worker(int n, boolean ...

View answer
Bisection method
5 votes

Although the other answers made some good stylistic observations and suggestions for improvement, many have missed a critical bug lurking in this code. Here's the offending line—see if you can spot it:...

View answer
Variations on binary searching an ordered list
Accepted answer
2 votes

There is one obvious reason to prefer method 2, and that is the possibility of overflow when calculating the midpoint in method 1. Adding the left and right widths together first, before ...

View answer
Navigating to a view
4 votes

One thing that might help is switching to a "fail-fast" approach, where you test error conditions first and handle them immediately if one is detected. Execution in the method only continues if there ...

View answer
Changing a pixel based on a keypress
Accepted answer
2 votes

The Fundamentals: Style & Readability Before we get into optimizing, there are a couple of glaring problems with your coding style—that is, the way the code is written and the way it looks. The ...

View answer
What's wrong with this FizzBuzz?
Accepted answer
16 votes

The for loop seems fine to me; it isn't abusing any semantics. The semantics of the for loop are quite clear: for (initialization; loop condition; increment) Anyone who doesn't know this off the top ...

View answer
Integer Log2 implemented using binary search
Accepted answer
8 votes

I was initially skeptical of your benchmarking results because of your testing methodology: I test both of the method by sending 1 << n, n from 0 to 31 to them, and repeat for 1000000 times, ...

View answer
Simple string operations in C++
Accepted answer
3 votes

Some thoughts: It is good that you explicitly annotated the function's definition with its required calling convention. Make sure that you do the same thing for the declaration in the public C++ ...

View answer
Endianness conversion in C
Accepted answer
18 votes

First off, Jean-François is absolutely right: you cannot assume any particular bit widths for the built-in types, short, int, long, etc. Use the types defined in stdint.h that have explicit bit widths ...

View answer
Implementing realloc in C
Accepted answer
67 votes

The code leaves a bad first impression because of how it is formatted. In particular, the extra whitespace between the return type and the function name, and that between the variable's type and its ...

View answer
Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle
9 votes

General In many places, your formatting and alignment are inconsistent. You also have typos in your comments and even a couple of typos in the #endif portion of the header include guards. All of this ...

View answer
Checking if CPU supports rdrand
11 votes

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 that's a good start. The CPUID ...

View answer
Format RGB Long as hex string in VB6
Accepted answer
14 votes

The code you have works, and is very nicely-formatted. There are only two things I would change, stylistically speaking: Explicitly pass input parameters by value. This should have been the default, ...

View answer