45,179 questions
3
votes
1
answer
145
views
What's wrong with this minimal static ELF executable made by GNU ld with a linker script with only a .text section?
The ELF executable at the end of this question (base64'd) is the result of an experiment with trying to cut the program headers down to the absolute minimum. As far as I am aware, it should be ...
2
votes
0
answers
43
views
What's the purpose of the BootRAM address in a STM32 microcontroller [duplicate]
I recently started working with STM32 and ARM Assembly. Studying the boot process of the STM32F103C8T6 microcontroller, I came across this line in the startup file generated by STM32CubeMX:
.equ ...
Advice
1
vote
17
replies
92
views
Make this code shorter and more optimized? DL 3155E24 || I/0 03
I need to implement an X in the I/O module, and I have some code that worked for me, but I don't know how I could optimize it: make it shorter but maintain the same functionality.
I also wanted to ask ...
-3
votes
0
answers
113
views
How practice to call main application function from loaded dll? [closed]
I have old Delphi 7 application with lib FastScript. This application can compile runtime code from text and call imported methods from main application.
I need to create this functionality for my web ...
2
votes
2
answers
121
views
Disassembly of VCVTSD2USI in 16bit mode - can it write a 16-bit register?
Intel instruction VCVTSD2USI (and some similar AVG512 instruction with GPRs) is encoded as
EVEX.LLIG.F2.0F.W0 79 /r VCVTSD2USI r32, xmm1/m64{er},
for instance VCVTSD2USI EAX,XMM0 is assembled to 62 F1 ...
Advice
0
votes
2
replies
80
views
Windows stack frame structure ? x86-64
How does the stack look like during procedure calls with it's shadow space ( 32 Bytes ) look like?
let's say I've this :
main :
push rbp
mov rbp,rsp
sub rsp ,0x20 ; 32 Bytes shadow ...
5
votes
1
answer
121
views
How Do You Test a Bitfield in Assembly?
I am writing some tests for VBE resolution using x86_16 assembly. I need to test a bitfield for some attribute flags, but I'm not sure of the best way to do so. The best solution I currently have is ...
Advice
0
votes
2
replies
115
views
How to become a great (excellent) kernel engineer?
I am a beginner kernel engineer and I have tried creating an x86-64 Unix-like kernel from scratch using C and assembly for my real machine. I am also trying contributing to the Linux kernel. I am ...
2
votes
0
answers
159
views
Why can't I boot my multiboot header kernel in Grub if VM firmware is legacy BIOS?
I created a kernel with a multiboot header but GRUB fails to boot the if VM firmware is legacy BIOS.
Linker script:
ENTRY(_start) /* the name of the entry label */
SECTIONS {
. = 0x00100000; /* ...
2
votes
1
answer
111
views
Assembly x86_64 code in Windows for creating a window has jittering in the oposite edges of the left and top edges when re-scaling
I think this might be a already solved issue previously, but I still don't understand why this is happening and how to fix this in a clean and satisfactory way.
I am writing a simple, basic GUI window ...
2
votes
1
answer
100
views
Alignment issue on context switch on a custom kernel
I'm writing a kernel in rust and assembly for embedded system in RISC-V 32 bits for several month now. I just notice today that when I run some task, after a certain amount of time, my kernel panic ...
Advice
1
vote
2
replies
97
views
Does x86-64 MFENCE's global visibility imply other cores's load that happen chronologically later must observe the store?
Consider the following program, where X = Y = 0 initially:
T1: T2:
STORE X = 1 STORE Y = 1
MFENCE MFENCE
LOAD Y LOAD X
My understanding ...
Advice
0
votes
13
replies
86
views
ARM Literal Pool definition in a mixed C and assembly function
STMicro ARM M0+ micro using STM32CubeIDE.
I'm attempting to write a function to test some registers in assembly and use the local vars on the stack(or even global variables) to help tie the assembler ...
2
votes
1
answer
105
views
How Do You Retrieve a Video Output's Preferred Resolution? (BIOS Bootloader)
I am building an operating system for the x86_64 ISA. I am at the point in my development where I want to begin display things for the user graphically, and therefore wish to retrieve the monitor/...
Advice
0
votes
9
replies
84
views
How Do You Retrieve a Video Output's Preferred Resolution?
Re-asked as a normal question (not opinion-based / discussion) as
How Does One Retrieve a Video Output's Preferred Resolution?
This version should be deleted.
1
vote
1
answer
139
views
Windows blocks my Assembly .exe's from running [closed]
I have recently started assembly programming and I have encountered an issue when assembling into an .exe file and then trying to run the program.
For context, I use the FASM assembler, and I use ...
1
vote
2
answers
96
views
When to use forwarding and when to use stalls to handle data hazards in pipelining (RISC V architecture)
I was trying to understand the cases in which forwarding is better than stall and vice-versa to handle data hazards (like RAW) in pipelining (RISC V architecture), I referred several sources to ...
2
votes
1
answer
120
views
How can I do arbitrary calculations on assembly language labels?
There are several examples in which we want to calculate something based on assembly language labels, but the object format and linker do not offer an operation needed for this particular calculation.
...
0
votes
0
answers
175
views
How to generate an executable file in the Portable Executable file format?
Dear Fellow Developers,
I am interested in learning how the Portable Executable format works. So far, I have written files in the com-format, which are executable in DosBox. However, I would like to ...
2
votes
1
answer
131
views
Strange behavior of the EAX register being truncated to 16-bit when single-stepping with CodeViewer debugger? [duplicate]
DOS 6.22. Virtual Machine.
Simple code:
.model small, stdcall
.386
.stack 1024
.code
Main proc
mov AX, @data
mov DS, AX
mov EBX, 00F00140h ; ebx contain 00F00140h
mov EAX,...
4
votes
1
answer
153
views
Why usually the return address's value is stored in the stack pointer with offset 12 ? Why can't we simply store it in the first 4 bytes of the stack?
I was trying to make a RISC V program that was calling a function from another function. I understood that since when we were calling the second function the return address for the first function was ...
Advice
1
vote
3
replies
104
views
Assembly x86 32-Bits Write Character
I'm currently working on a DOS Kernel 32 Bits on x86 Assembly
I'm looking for help, i want to print out the letter E on the screen to check if my code jump 16-Bits to 32-Bits is working correctly.
...
3
votes
1
answer
89
views
Is there any way to automatically %undef what was earlier %define'd?
I have a macro that %defines a bunch of variables. I need them only for the duration of a single function, then they need to be %undefed at the end of the function. This, for example, doesn't work:
%...
3
votes
1
answer
101
views
ASM x86 (Intel syntax) calculator, why doesn't subtraction work?
I am learning x86 assembly (Intel syntax) and writing a simple calculator as a .COM program in FreeDOS. The program reads two digits and an operator from the keyboard and performs the operation.
...
Best practices
1
vote
2
replies
75
views
Providing stubs to a static library
Environment:
Windows, Visual Studio, low level.
A bit of context:
One of my project is a static library with C functions that export functionalities. Some of those C functions make use of C functions ...
3
votes
1
answer
115
views
My SVC (Supervisor Call) code isn’t working and I’m not sure why
#include "hardware/regs/addressmap.h"
#include "hardware/regs/m0plus.h"
.syntax unified @ Specify unified assembly syntax
.cpu cortex-m0plus @ Specify CPU ...
Advice
1
vote
7
replies
181
views
(Newbie) Where does the Stack Pointer actually point? Does it point to the last used byte or to the first free byte?
I just learnt that you can implement C (or any compiled language) functions in asm. Maybe to optimize them or to access CPU functionality that is not accessible otherways.
I know some MIPS asm from ...
4
votes
2
answers
120
views
Replacing movemem() with inline assembly for vga graphics
I am writing simple animation in Turbo C (for VGA, on a NuXT 2, an IBM PC/XT clone). I write the graphics to a buffer and then every frame, I clear the buffer, write the updated objects, then copy ...
2
votes
1
answer
86
views
Why does ARM GCC push / pop scratch register R3 in a tiny function? [duplicate]
Context is bare-metal development on STM32H7 (Cortex M7) using arm-none-eabi_gcc v 10.2.1
I'm looking to the assembly code of a basic function
void my_function(void)
{
my_sub_function();
}
...
4
votes
3
answers
294
views
Efficient Cross-Correlation of 128-bit bit-strings with x86-64 CPUs
This question is about binary cross-correlation of 128-bit value (the Haystack) with another 1-128-bit value (the Needle) with the goal of maximizing the throughput of this operation on INTEL/AMD x86 ...
Advice
1
vote
3
replies
138
views
C Compiler Optimization MUL 0x70078071?
I've been looking at the zlib1.dll that comes with Win 11 Pro and I was hoping for some assistance with the following passage:
56b: b8 71 80 07 80 mov eax,0x80078071
[570: 41 0f 42 ...
Advice
1
vote
10
replies
140
views
Understanding x86 calling conventions from a book to generated code
I am working my way through Douglas Comer's Xinu book and in Chapter 3 (Sec. 3.9.1), there happens to be a stack diagram for when a function is called under x86. It looks like:
Intel Processor Stack ...
Advice
3
votes
9
replies
158
views
Assembly language EOR usage to change two 1 bits to 0s
I'm an A-level computer science student (AQA). We had a question on assembly code, and the task was to change 0011abcd (abcd are 1s or 0s, just placeholders) to 0000abcd.
I wrote the following:
EOR R1,...
3
votes
2
answers
102
views
Why Bits declare instruction in nasm x86 assembly languages have no effect When I write code to use big unreal mode?
I am a beginner in x86 assembly language. I heard that Bios have a technology called big mode for executing or accessing other BIOS code or data in the range exceeding 64KB and far beyond the 0-1M ...
2
votes
0
answers
67
views
GDB examine command shows different value than value loaded from the same address
I tried to make a function that finds all existing PCIe device's functions and saves the physical address of their config space to an allocated memory for my os, but I noticed that I got WAY too much ...
Advice
1
vote
2
replies
126
views
where can i find detailed documentation of linux syscalls?
There is a C interface for linux syscalls defined in libc and described in man pages. There are also resources like this https://www.chromium.org/chromium-os/developer-library/reference/linux-...
3
votes
1
answer
89
views
Trying to write a code that gets an array of random temperature readings for 14 days. Then outputs the high/low temps and averages on those days
I am trying to write a code that generates a random array of 14 day temperature readings; 11 readings per day. Then calculate the daily high/low temperatures for each day and calculate the average ...
3
votes
1
answer
90
views
ARM64 printing a float obtained via scanf
I'm trying to read a float value from the console and print it out. I'm running this on a Raspberry Pi running Debian Bullseye.
I started with this code. It has the float value hard coded and prints ...
Advice
4
votes
6
replies
101
views
How to render transparent custom bitmap text in VGA Mode 13h (x86 16-bit Real Mode) without BIOS interrupts?
I am developing a monolithic 16-bit OS in x86 Real Mode using NASM. I have successfully set up a basic GUI using VGA Mode 13h (320x200, 256 colors) by writing directly to the video memory segment at ...
6
votes
1
answer
270
views
What is the optimal strategy for extending this string search to 256 bytes
The following C function is limited to 16 byte strings and it detects whether one string is contained in another string and if it is not then determines the maximum length of the first string's prefix ...
4
votes
3
answers
275
views
Why does changing the return-type of this C function from 'bool' to 'int' add an additional assembler instruction?
I have this simple function which indirectly tests for NaN, and x86-64 gcc 15.2 with -O2
bool self_eq(float num) {
return num == num;
}
Compiled as both C and C++, this produces:
self_eq:
...
1
vote
1
answer
69
views
EFI calling convention on RISC-V (illegal-instruction)
I wan create a simple EFI application in assembly for RISC-V for the purpose of education. Have want to port a working x86_64 example in assembly to RISC-V, but struggling with the correct calling ...
1
vote
0
answers
82
views
x64 Bootloader with C-Kernel
I'm currently working on an x64 Bootloader for a school project, but can't get it to run my Kernel.
Bootloader.asm
;###################################
; Real Mode
;##########################...
1
vote
1
answer
84
views
Custom x64 Windows PE Not Running
I was trying to manually craft my own windows pe and for some reason cant seem to find out why my program isnt running, ive crossed checked all my alignments, file alignments, section alignments and ...
4
votes
2
answers
89
views
How to replace NASM -f bin nobits section when using -f obj with WarpLink
I'm trying to extend the public domain 86-DOS linker, WarpLink. A difficult task I'm considering is to change my debugger, lDebug, from building as a single (NASM) assembly language file (using many %...
0
votes
0
answers
90
views
Floppy disk read from stage 2 bootloader is failing consistently
Maybe this question has already been answered before, but I couldn't find one with my exact issue.
I am consistently running into issues when trying to read my kernel from my stage2 bootloader which ...
2
votes
1
answer
90
views
idiv does not perform signed division [duplicate]
The idiv amd64 instruction is not working as I expect. When the dividend is negative, it produces a large positive number.
xor rdx, rdx
mov rax, -10
mov rbx, 5
idiv rbx
push rax ; expected -2, got ...
5
votes
0
answers
233
views
How to correctly return from a x64 assembly procedure when .PARAMS is used?
Suppose I have a procedure like this:
procedure DoSomething;
asm
.PARAMS 11 // This will auto-generate "push rbp + sub rsp,$60 + mov rbp,rsp"
// ...
end;
Suppose I need to return from ...
Advice
2
votes
8
replies
115
views
How is a switch statement created in 64-bit assembly?
I have searched all over the internet and I'm beginning to wonder if this is even possible if not incredibly impractical. For using a jump table it looks like you have to hard-code the memory ...
Best practices
2
votes
8
replies
122
views
What is the fastest way to multiply even-indexed integers of a ymmword with odd-indexed integers of a ymmword vector of 32-bit integers
I have been reading the amd64 architecture manual available here, especially through integer vector instructions. I don't quite understand the (v)pshufd instruction, though I wonder if this could be ...