Sep Roland
  • Member for 7 years
  • Last seen more than a month ago
Assembly program which detects all numbers with two integral divisors
Accepted answer
10 votes

mov ecx, 0 ; Counts how many division have This begs for an optimization in the form xor ecx, ecx. This will clear ECX just the same, is shorter and faster. cmp edx, 0 jne prepareInnerIteration ...

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

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 suspect that the upper limit is in ...

View answer
x / 2 + 100 * (a + b) - 3 / (c + d) + e * e in assembly
Accepted answer
6 votes

write an algorithm for: x / 2 + 100 * (a + b) - 3 / (c + d) + e * e a, c - word, b, d - byte, e - doubleword, x - qword Because your biggest number is 64 bits (x is a qword), your final result will ...

View answer
Loading a file from a FAT32 filesystem in 16 bit real mode on x86 (Intel syntax assembly)
Accepted answer
6 votes

Style feedback on how clear my comments were and how easy the code was to follow I'm not a big fan of line comments. I think they make the code a bit harder to follow. That's why I prefer tail ...

View answer
A 8086 assembly hexdump program
Accepted answer
6 votes

I'm not familiar with Concurrent CP/M 86 but I do know my 8086. ... dseg org 100h ... I found it remarkable to see the org 100h directive so far down in your program. I would have expected this ...

View answer
x86 assembly [fasm] code which takes a number and adds 155 then shifts right
Accepted answer
6 votes

push number push frmspec call [scanf] sub esp, 8 ; clean stack Cleaning up the stack is done by adding to esp. Because the stack on X86 grows downward, cleaning implies going upwards. You make this ...

View answer
Assembly Nasm Bootloader x86
Accepted answer
6 votes

First correct some bugs. start: mov si, 7F00h ;; set stack pointer after our bootloader mov ax, 0h mov ds, ax ;; set DS to 0; mov di, 7C00h ;; set Data pointer to memory location ...

View answer
Very simple OS in Assembly
Accepted answer
5 votes

Can I make this code shorter? If you use the ORG 7C00h directive, then loading the segment registers will be shorter code. You can choose to setup the stack below the bootloader and shave off that ...

View answer
Find all the digits in a string
Accepted answer
5 votes

Did I make it unnecessarily complicated? You can replace find: scasb jz found loop find jmp next by the simpler repne scasb jne next The use of the SCASB instruction here ...

View answer
Criticism on x86_64 nasm assembly strToInt and printInt implementation
5 votes

Warming up A good thing that I see missing from your program is writing comments about the function numbers and more. mov rdi, 0 ; STDIN mov rax, 0 ; SYS_READ syscall ... mov rdi, 1 ; STDOUT ...

View answer
Cat program in x86 NASM
Accepted answer
5 votes

I was thinking if I should add labels like write even if I wouldn't jmp to them, so code would be cleaner. Writing labels that aren't jumped to is fine. Provided they have meaningful names, it can ...

View answer
Caesar cipher in i686 assembly + MMX
Accepted answer
5 votes

A big danger. When the len parameter happens to be a muliple of 8 and all of the full qwords have been processed, there will be no remaining bytes to process. Your code calculates the number of ...

View answer
8086 ASM Bresenham's Line Algorithm Pt2
Accepted answer
5 votes

Analysis (in random order) mov ah, 00h mov al, 03h int 10h mov ah,04ch mov al,00h int 21h We always strive to get the smallest code without loosing readability. I think next snippet does a good job (...

View answer
GNU assembly (AT&T syntax) bootloader load the next sector from floppy
Accepted answer
4 votes

Improvements When BIOS starts your bootloader (after it got loaded at linear address 7C00h), the only register that has a defined meaning is the %dl register. It contains the bootdrive code. From ...

View answer
Assembler. Algorithm for incrementing a decimal number
Accepted answer
4 votes

This code obviously uses recursion. That's not the case. For recursion your INCREMENT routine would have to call itself which it doesn't. The INCREMENT subroutine simply iterates over the characters ...

View answer
Transposing a square matrix (n x n)
Accepted answer
4 votes

20+ percent faster using the stack for the extra buffer. Matrix Question Answer(1) Faster ------------------------------------------- 16 x 16 3.62 µsec 2.62 µsec 27.6 % 13 x 13 ...

View answer
x64 Assembly zeroing an array (8 bytes at a time)
Accepted answer
4 votes

Shave off a byte cmp edx, 0 jle Finished ; Check if count is 0 Using cmp is certainly not wrong, but the optimal way to check for any inappropriate counter value would be to ...

View answer
x86 assembly function that determines whether an array is continuous
Accepted answer
4 votes

1.The algorithm itself ...if an array with length n that starts with the value k, all the subsequent entries in the array are k+1, k+2, ... k+n. What you're saying here is not entirely true! The ...

View answer
X86 Legacy boot loader error trapping
4 votes

This code is fairly weighty (105 bytes) Given all the things you want to do, and all the devices you want to interface from within this 512 bytes bootloader, you should take more steps to reduce the ...

View answer
Brainf*ck interpreter written in x86 assembly
Accepted answer
4 votes

mov eax,0 ; eax is BF data pointer mov ebx,0 ; ebx is BF source pointer mov ecx,0 ; ecx is loop depth If you used the EDI register for the BF data pointer and the ESI register for the BF source ...

View answer
x86_64 nasm criticism on malloc and free implementation
Accepted answer
3 votes

If I did any major mistakes. Depends on whether you want to follow the Linux 64-bit calling conventions or not. Currently you are using the stack for parameter passing between your functions, where ...

View answer
Print a list of strings in assembly
Accepted answer
3 votes

Are there easier ways to print something like a linebreak after each string rather than hardcoding the \n into the string itself? Embedded newlines are certainly the easiest way to do this, but ...

View answer
Project Euler #1 AT&T Assembly
Accepted answer
3 votes

Sorry for the poor code formatting, looks like 8-width tabs didn't carry over so well. A well known problem on StackExchange... I looked at your text in a separate editor and can vouch that your ...

View answer
HybridSort of QuickSort and MergeSort
3 votes

The generated assembly code is very inefficient! First example. Ley's look at this small part right at the top: If gornja_granica-donja_granica<2 AsmStart ret AsmEnd EndIf This is its assembly ...

View answer
Pascal's Triangle in AEC
Accepted answer
3 votes

I find it very confusing that you consider all of this assembly as inline assembly. I see the start and exit of a regular FASM assembly program, 2 things I don't expect to find in inline assembly. Am ...

View answer
Key-scanning macro in NASM Win16 against DOSBOX (Intel 8086)
Accepted answer
3 votes

It's fine to write this scan macro for educational purposes, but I think that considering its length a subroutine would have been more appropriate. The macro's bytes are inserted everywhere the macro ...

View answer
String helper functions in NASM Win16 Assembly
3 votes

There's plenty to optimize here! In NASM you get the address simply by writing mov di, prompt. This has a shorter encoding than lea di, [prompt]. (In MASM this would be mov di, offset prompt giving ...

View answer
X86 Feature detection in preparation for Long Mode
Accepted answer
3 votes

Documentation for this flag reads: If a software procedure can set and clear this flag, the processor executing the procedure supports the CPUID instruction This clearly means that the flag does ...

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

strlen We generally prefer smaller instructions. To zero the EBX register we normally use xor ebx, ebx. This is a 2-byte instruction where mov ebx, 0 is a 5-byte instruction. Loops get faster if ...

View answer
Dynamic Fibonacci algorithm in x86 (MASM)
Accepted answer
3 votes

I'm wondering how this is normally done Yours is as good a solution as anyone else's. That said, a solution that pushes the elements would not need to address these elements relative to EBP at all. ;...

View answer