Questions tagged [assembly]

An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture's machine code instructions.

Filter by
Sorted by
Tagged with
4 votes
1 answer
88 views

Add two huge base-10 numbers

This is some assembly code I've written to add two base-10 numbers. The input and output are represented as null-terminated ASCII strings, with digits in big-endian order. I have also provided ...
  • 185
11 votes
3 answers
1k views

Remove leading zeroes from the beginning of a string

I want to remove leading zeroes (for a big integer library I'm currently making) in numbers represented as char arrays. I chose assembly for speed, but in order to simplify making the algorithm and ...
  • 185
2 votes
1 answer
81 views

Increment a binary number represented as a string

I'm an amateur at assembly, but am trying to get better at it. For fun, I decided to write code that takes in a char array and increments the number represented in binary. Here are a few input-output ...
  • 185
-2 votes
2 answers
88 views

Optimizing Netwide Assembler codes in Microsoft Windows

I am a novice in assembler programing, I will will appreciate if someone could review these NASM assembler code for me. Is about encoder decoder. The encoder performs the following: pads the ...
1 vote
1 answer
51 views

"Hello world" in x64 assembly for Windows - Shadow space / Stack alignment

I`m currently trying to delve into x64 assembly under windows using NASM, and created a minimalistic "Hello World" application. It is mainly meant as an educational resource for me and ...
  • 78
1 vote
0 answers
29 views

Test and set a bit atomically using inline aarch64 assembly

The code below has been a vehicle for learning the syntax of inline assembly for gcc/clang and that is the focus of my question. In addition to anything else that I've missed I would also like ...
2 votes
1 answer
78 views

Hack assembler/disassembler in x86_64 assembly language

Starting from this answer I thought I would show a fully worked example of how to create a data-driven version of the assembler for the Hack assembly language. As I noted in that answer, having ...
  • 64.6k
4 votes
1 answer
80 views

First assembly program: working with strings and integers

I started learning assembly some days ago and I wrote my first program today. Nothing exceptional here: some user inputs, strings manipulations, integer to string conversion etc... The only purpose ...
4 votes
1 answer
292 views

Assembler made in assembly

I made an assembler for the "hack" assembly language, here's an example of what it looks like: ...
1 vote
1 answer
34 views

File dump in assembly

This is a file dump program written in assembly that displays 320 bytes at a time in 20 lines. It shows the hex code for each character and also the string At the start of the program it asks for the ...
3 votes
2 answers
115 views

Sieve of Eratosthenes in x86 assembly

Hello I made a sieve of Eratosthenes algorithm on x86 assembly using NASM. The highest number it can take is about 2 million and it takes like 2 seconds to complete. Here's the code: ...
2 votes
1 answer
166 views

Sum two vectors in x86 assembly

I recently made a program with C++ and ASM. Can anyone help me make this code a more efficient one, in the ASM part or both. I would really appreciate it because I don't know every ASM instruction and ...
2 votes
1 answer
71 views

Base64 encoder in Assembly x86-64 Linux language

We were asked to create a Base64 encoder for Assembly x86-64 on Linux. Was wondering how my code below could be improved, be it notation or anything else. We only had Assembly for 3 months so I'm not ...
  • 123
3 votes
0 answers
83 views

Single-threaded coroutine in C (Linux x86-64)

Background Story I crafted a simple single-threaded coroutine in C, running on Linux x86-64. Short Technical Explanation 1) Task There are two types of tasks in this implementation. Main task. This ...
4 votes
1 answer
142 views

A Brainfuck compiler that creates a small x86_64 Linux executable from scratch

This program compiles Brainfuck source code to an x86_64 ELF executable. It doesn't rely on any backend, just raw binary stream to a functional executable. In the implementation, each cell holds an 8-...
  • 421
19 votes
4 answers
2k views

Minimal `printf` for integer types in x86 assembly

I'm writing a minimal C runtime targeting an old 32-bit Windows XP machine as a personal project. The C runtime provided by compilers is quite bloated. I wouldn't mind some library bloats up to ...
  • 421
3 votes
2 answers
117 views

Beating the compiler with a simple program finding the longest collatz sequence

I found this question in Stackoverflow asking why his/her assembly program isn't faster than the C++ program. In his/her assembly program I saw the lines ...
  • 421
4 votes
0 answers
58 views

RC4 stream cipher in ARM Assembly

Below is a complete implementation of RC4 in ARM assembly. Unit tests pass, including comparison to C implementation and to published test vectors. I'm appreciative of all feedback, comments (things ...
1 vote
0 answers
156 views

MIPS-32 assembly: Determine if n is prime

I'm new to assembly and I'm learning on my own, so I'd appreciate the feedback. My priorities are correctness (on all MIPS-32 with sllv) > speed > readability ...
  • 111
2 votes
1 answer
54 views

Project Euler 1 (sum of multiples of 3 or 5) in ARM Assembly

Project Euler #1 asks: Find the sum of all the multiples of 3 or 5 below 1000. In ARM Assembly; I did this in 3 loops, which avoids any MOD or DIV. Each loop is written out, without a common ...
4 votes
0 answers
105 views

Arm Assembly Tokenize String (strtok()), Load Move, Add Efficiency

Dabbling a bit more with arm assembly, I wrote a few functions to handle string splitting. The goal was to write a few reusable functions that could be combined to emulate (roughly) what C ...
2 votes
1 answer
108 views

Writing an x64 Code Emitter to eventually make a full fledged Assembler like NASM

As the title suggests, I'm writing an x64 Code Emitter. Right now I've only encoded 1 instruction (The add instruction). I want to know if this API can be improved at all. This is how you I use it. <...
4 votes
1 answer
169 views

GNU assembly (AT&T syntax) bootloader load the next sector from floppy

I'm playing with the Real mode and was trying to code something when suddenly I exceeded the 510 boundary (.org 510) of the <...
7 votes
2 answers
738 views

Hack machine language assembler as required for project 6 of Nand2Tetris

This is the implementation of the Assembler required to parse source code written in the Hack Machine Language and output it to a 16-bit binary file. After writing one go in Swift, I decided I wanted ...
1 vote
1 answer
97 views

Printing one to ten in (GAS/AT&T x86/x64) assembly

I've started my journey of learning assembly on my Mac. As a start, I've decided to write a program to print the numbers one through ten to the console, then a final string signifying the end of the ...
  • 9,652
4 votes
1 answer
830 views

4x4 double precision matrix multiply using AVX intrinsics (inc. benchmarks)

Benchmark An optimised 4x4 double precision matrix multiply using intel AVX intrinsics. Two different variations. Gist For quick benchmark (with a compatible system) copy paste the command below. Runs ...
  • 171
6 votes
1 answer
195 views

Assembler. Algorithm for incrementing a decimal number

I share an algorithm that I have written myself. It is useful for incrementing any digit of a decimal number. That way, a conversion to decimal is not necessary. Please excuse the mistakes. I am ...
  • 63
2 votes
1 answer
170 views

FizzBuzz in arm64

I made a FizzBuzz program in arm64; I print out the values in hex instead of decimal. This was the first arm64 program I made and I'm looking for advice on how I can improve it. The code to print out ...
1 vote
0 answers
39 views

81 variations of the rounded rectangle

If we apply outward curving, inward curving, and no curving at all, individually to each of the 4 corners of the rectangle, we get next 81 variations: The code implements next BASIC command: ...
  • 4,128
2 votes
0 answers
421 views

Binary to hex in ARM64 SIMD assembly

As an exercise in learning ARM64 assembly (aka AArch64), I wrote this function to convert 64-bit binary to hexadecimal with SIMD instructions. I'm most interested in feedback on the algorithm, ...
2 votes
1 answer
155 views

setjmp and longjmp implementation in mmix

I've written an implementation of setjmp and longjmp in MMIX (assuming no name mangling). I also hand-assembled it. Are there any mistakes anyone can spot? ...
1 vote
1 answer
271 views

MASM) assembly implementation of recursive Fibonacci

I'm trying to teach myself assembly via MASM, below is my first implementation of the recursive form of the fibonacci sequence. I timed it against an equivalent C implementation in release mode and ...
  • 111
4 votes
1 answer
975 views

Decimal to binary conversion in ARM assembly

I'm "playing" with ARM assembly on a Raspberry Pi, reading various tutorials and posts to help - no, it's not a college assignment, I'm too old for college! I'm pleased with getting the ...
  • 41
0 votes
1 answer
1k views

Writing a recursive factorial function in x86-64

The following assembly program works to print the factorial of a number: ...
  • 333
-4 votes
1 answer
234 views

Fork Bomb virus in Assembly

I made a fork bomb virus in Assembly. Now, I want to make my code better. Here is my code: ...
6 votes
3 answers
237 views

Fastest (in clock cycles) 16-bit x 16-bit unsigned integer division algorithm for ATMEGA1284?

I am trying to create an optimized 16-bit division algorithm for the AVR ATMEGA1284. The goal is to reduce the number of clock cycles as much as possible. AVR INSTRUCTION SET MANUAL: https://ww1....
  • 169
1 vote
1 answer
143 views

Converting decimal to binary in Assembly

The longest example program in my PicoBlaze Simulator in JavaScript is this decimal-to-binary converter: ...
25 votes
4 answers
3k views

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

I'm trying to learn some basic x86 assembly and so I've begun solving Project Euler problems. I was hoping for some critique of my code that, hopefully, includes either the efficiency of the ...
  • 557
1 vote
0 answers
47 views

C++ calculation of curling number in sequences (Assembly?)

I'm writing a program that creates curling sequences -- in short this means that we start with a given sequences, consisting of 2's and 3's (i.e. a mix of 22 of them), and look for repetition at the ...
3 votes
2 answers
196 views

Very simple OS in Assembly

I made a very simple OS in Assembly. But my code is too long. I want to make my code shorter. Here is my code: ...
  • 65
3 votes
1 answer
149 views

How do I optimize the bubble sort in Assembly8086?

I tried to implement bubble sort in Assembly 8086. ...
3 votes
0 answers
70 views

Assembly REPL in Python using ctypes

I created a assembly REPL using some ctypes hacks to run the assembly code. Any suggestions on how I could improve it? I am unconcerned about some of the "obvious" security issues such as ...
5 votes
1 answer
80 views

Find all the digits in a string

S is a given character string, then I have to find all the digits characters of S. Did I make it unnecessarily complicated? <...
6 votes
1 answer
81 views

Given a byte string S of length l, obtain the string D of length l-1 as D(i) = S(i) * S(i+1)

Given a byte string S of length l, obtain the string D of length l-1 as D(i) = S(i) * S(i+1) (each element of D is the product of two consecutive elements of S). ...
4 votes
2 answers
568 views

x86_64 nasm criticism on malloc and free implementation

I have made my own malloc implementation using this resource as a guide https://danluu.com/malloc-tutorial/ I was hoping to receive some feed back on how I can improve upon it, and If I did any major ...
  • 403
7 votes
1 answer
90 views

x / 2 + 100 * (a + b) - 3 / (c + d) + e * e in assembly

write an algorithm for: x / 2 + 100 * (a + b) - 3 / (c + d) + e * e knowing that: a, c - word, b, d - byte, e - doubleword, x - qword ...
4 votes
1 answer
72 views

Trivial string-reverser in MASM64

I've been learning MASM64 over the last few days and written a simple demo, so I can get feedback on my understanding of x64 assembly programming. It's really basic: it asks the user for their name, ...
  • 143
2 votes
1 answer
68 views

Debounce counter for PIC micro - Suggestions for improvement

I developed this code for a vertical debounce counter for the PIC micro (PIC16F57). The code is called every 512 microseconds. It takes 5 bits from PORTB and compares it to a last known debounced ...
  • 131
1 vote
1 answer
74 views

Criticism on x86_64 nasm printBigInt and bigPow implementation

The first "method" I have coded is _bigPow which can pow(x, y) on any number which is really big. And the _printBigInt prints a very big integer. Plus I have tried to comment most parts of ...
  • 403
6 votes
1 answer
260 views

CodeWars - Assembly Language - Check List For Value

I'm doing assembly language problems on CodeWars, a website with practice problems. Problem https://www.codewars.com/kata/545991b4cbae2a5fda000158/train/nasm Create a method that accepts a list and ...

1
2 3 4 5
7