Questions tagged [assembly]
An assembly language is a low-level programming language for a computer, microcontroller, or other programmable device, in which each statement corresponds to a single machine code instruction.
170 questions
0
votes
0
answers
114
views
How To Share Code Between Assembly Files In A Modular Way
Recently, I started learning Arm64 assembly. The assembler I'm using is the GNU Assembler (GAS). The version of GAS I'm using is GNU assembler (GNU Binutils for Ubuntu) 2.42.
I want to make my code ...
0
votes
2
answers
286
views
Why does jl test for the second operand of cmp to be less than the first, instead of the other way around?
Something like this
cmp $0, %eax
jl exit
jumps to the exit: label if the content of register eax is less than 0.
So it's kind of jl applies the < operator to the operands of cmp, but in reverse ...
-1
votes
1
answer
113
views
Debugging miscompile [closed]
Recently I encountered an issue at work where a unit test written in C++ would crash only when being compiled with MSVC 2017 (MSVC 2019 and up are fine). I tried to debug this issue and it seems like ...
6
votes
3
answers
1k
views
How does a JIT compiler actually emit and then call the emitted native code?
Assuming that a VM runs a JIT compiler on otherwise "interpreted" code, such as a line by line interpreter or some form of bytecode/IL code and determines that it can create optimised native ...
-3
votes
1
answer
425
views
When making a compiler, what's the best way for compiling to machine code in the backend? [closed]
I know that a lot of compilers use an assembler to compile to machine code, to make an executable (compiled program).
Some people even made their own assemblers, or they just use an existing assembler,...
-5
votes
2
answers
149
views
Archival-quality future-proof pseudo-CPU architecture
Suppose we maintain a massive electronic library of texts/photos/videos etc., and want to ensure that these files are readable indefinitely long in the future. [Update] one of the major problems with ...
0
votes
2
answers
211
views
Where to put files (interfaces) that link two independent assemblies: Authentication and Main Program
I'm having an issue with dependencies in a C# app that I'm creating.
I have an assembly for my authentication process, and a separate assembly for starting up the main program once authentication is ...
2
votes
1
answer
385
views
How do these two ways of enforcing alignment work together?
In Computer Systems: a Programmer's Perspective,
Alignment is enforced by making sure that every data type is
organized and allocated in such a way that every object within the
type satisfies its ...
-1
votes
3
answers
246
views
Is an assembly program a procedure itself and does it occupy a stack frame?
If I am correct, an assembly language uses the program stack to store data.
Is it correct that the program stack is partitioned to frames, each of which is for a call to a procedure? So there is no ...
-1
votes
1
answer
96
views
What specifies the agreement (i.e. the convention) of which registers are used to pass which arguments and to return which values?
In Computer Systems: a Programmer's Perspective:
procedure calls may involve
passing data as arguments, and returning from a procedure may also
involve returning a value. With x86-64, most of these ...
0
votes
2
answers
381
views
Do differences between ATT and Intel formats of assembly languages come from differences between their underlying machine languages?
From Computer Systems: a Programmer's Perspective, about assembly languages:
We see that the Intel and ATT formats differ in the following ways:
The Intel code omits the size designation suffixes. We ...
0
votes
3
answers
194
views
Does the assembler perform the same tasks as the translator from C to assembly?
When compiling C programs to assembly programs and then to machine programs, does the assembler (e.g. the one used in GCC or other popular C compilers) perform the same tasks as the translator from C ...
-3
votes
2
answers
232
views
Why will it take approximately 2 years for Apple to transition Mac to ARM? [closed]
Why will it take that long to transition all Mac software to ARM according to Apple? I thought all they would need to do is to recompile the source code of their apps and rewrite SIMD code from intel ...
-2
votes
3
answers
183
views
If you're building an algorithm from the C stdlib in pure Assembly (with no help), what is the best workflow for debugging/iterating?
I am a JavaScript developer mainly, so I am familiar with object-oriented code and dealing with things you can see easily and interact with, like the GUI, even HTTP requests, etc. Plus you can put ...
11
votes
1
answer
3k
views
Why is Assembly Language called "Assembly"?
Why is assembly language called "assembly"?
I was just watching the 1st video in the "Crockford on JavaScript" series.
In it, Douglas says,
". . . the first program to make programming easier was ...
8
votes
1
answer
15k
views
Difference between direct and indirect function() calls
I am curious about the Difference between direct and indirect function() calls
Could anyone help in the diff analysis ?
The c source code could be found at subroutine_direct.c and ...
2
votes
1
answer
278
views
How are primitives stored in memory
In my searching although this question seems to get answered a lot, the answers don't really cover what I want to ask.
I'm learning assembly and my question is, in higher level languages e.g C data ...
2
votes
1
answer
848
views
How is x86 assembly different from Windows assembly, and does that let me circumvent Windows?
As I can understand, assembly language is just a symbolic representation of hardware instruction opcodes that a hardware manufacturer has offered/documented, based on the way they have designed their ...
0
votes
1
answer
146
views
What is meant by /0 in AMD64 specification?
The AMD64 specification talks about /0 with regards to instruction encoding but I don't have a clue what is meant by that. For example, in Volume 3 the ADD instruction has three forms:
ADD reg/mem16,...
-2
votes
5
answers
920
views
How is a first assembler assembled? (without cross-compiling)
I know there are a lot of threads regarding this topic, but I can't find the answer for this precise topic:
First of all, with the "first assembler" I mean the program that translates, let's say, the ...
51
votes
4
answers
16k
views
Why do we still grow the stack backwards?
When compiling C code and looking at assembly, it all has the stack grow backwards like this:
_main:
pushq %rbp
movl $5, -4(%rbp)
popq %rbp
ret
-4(%rbp) - does this mean the ...
1
vote
1
answer
617
views
How many bytes is a long in a 64 bit machine [closed]
I have compiled the following simple c++ code:
#include <iostream>
int main(){
int a = 5;
int b = 6;
long c = 7;
int d = 8;
return 0;
}
and here is the assembly:
pushq %rbp
....
0
votes
1
answer
1k
views
Opcodes vs Operands
In laymen's terms, what is the difference between opcodes and operands in assembly language programs? I understand that one involves where to get the data and one involves what is to be performed on ...
8
votes
3
answers
2k
views
How to optimize a mixed stack/register bytecode with control flow and side effects?
I'm trying to figure out a technique to optimize bytecode for the following virtual machine:
Bytecode is a flat list of instructions, with execution starting from the first instruction.
Stack ...
-4
votes
2
answers
265
views
Performance question - what are the defects of high level programming languages and compilers that makes assembly still a better choice today [closed]
What I want to know is, how can we still make use of assembly today, in productive manners?
When assembly outperform C, so it would seem practical to write a section of the project in assembly rather ...
0
votes
1
answer
3k
views
Registers and Stacks in NASM
So, I am more or less voluntarily learning NASM, and I have problems finding sources that really explain it. Unlike with Java or C# I can't just use google as well, since Assembly just isn't used by ...
-7
votes
1
answer
394
views
Why does the C compiler use memory for simple arithmetic operations
Assume the following C code:
#include <stdio.h>
int main()
{
int a = 5;
int b = 15;
return a + b;
}
Compiling it using gcc creates an assembly code which includes the following:
...
1
vote
1
answer
352
views
What is the difference between writing in assembly vs converting high level language into assembly using compiler?
So i heard that in modern operating systems and device drivers, some parts of them are still written in assembly for better memory optimisation and speed
but do developers actually write it in ...
1
vote
2
answers
2k
views
How can I test generated assembly?
I'm working on a C compiler for Linux for the purpose of personal curiosity/fun. How can I test the generated assembly before the compiler is complete enough to do anything useful?
For example, if I ...
1
vote
1
answer
89
views
Simulating Comparison Without Using Comparison Primitives
In the same way that you can simulate the if statement and functions, I am wondering if there is a way to simulate the comparison operators ==, !=, >, >=, <, <=.
For example, in ...
0
votes
3
answers
526
views
How to Simulate Control-Flow without using Control-Flow Primitives
Basically, I want to know how to simulate while and if if I'm handling the control flow myself through an array of instructions.
The while loop can be simulated by if, as seen with assembly branching ...
-6
votes
1
answer
176
views
Why do assembly languages often include symbols as a language feature? [closed]
I wonder why in assembly there are often included symbols as a language feature and what's the purpose of it?
0
votes
0
answers
248
views
How to manage dynamically generated variables in Assembly
Along the lines of How v8 JIT compiler manages dynamically changing variables, wondering how you would go about creating dynamically generated variables in assembly. Not necessarily looking for ...
-4
votes
1
answer
179
views
Assemblers Used During the Development of a Programming Language?
I am currently designing and developing a programming language from scratch. Mostly as a learning experience. Although it's not entirely related to the question, it's important that you know a little ...
-1
votes
1
answer
831
views
How to make compiler portable?
I am writing a simple compiler. I have written lexer and parser and it now generates assembly code from given code. Now I need to write an assembler which generates machine code. But the problem is ...
0
votes
2
answers
814
views
How does x86 deal with register pairs?
I’ve been reading about older processors (8080, 8086 and that) and i’ve seen that those older 8-bit processors had some 16-bit instructions through the use of register pairs. For example, on the 8080, ...
9
votes
2
answers
8k
views
How does a CPU load multiple bytes at once if memory is byte addressed?
I've been reading about CPUs and how they are implemented, and some big complex architectures (looking at you x86) have instructions that load from memory during one clock cycle. Since one address ...
6
votes
1
answer
2k
views
Why does GNU AS use different characters for single-line comments depending on the architecture?
The GNU Assembler as uses different characters depending on the architecture to specify single-line comments, such as # on x86, ; on 29k, or @ on ARM. Moreover, regardless of platform, C-style ...
-1
votes
1
answer
425
views
Help With Memory Mapped I/O and Hardware Interrupts for Virtual Machine
I've been working on a 24-bit virtual machine to help me learn more about computers and programming in general and was hoping to find a bit more information on memory mapped input/output and hardware ...
0
votes
5
answers
3k
views
How to evaluate efficiency of assembler code?
I was coding some functions in C++ and wondered how different versions of those functions would affect generated assembly code. I put different versions into the Godbolt Compiler Explorer Tool and ...
9
votes
1
answer
3k
views
Why data alignment is used exactly?
Each data type must be aligned to a multiple of some number of bytes, for example a short int must be aligned to a multiple of 2 bytes, and an int must be aligned to a multiple of 4 bytes.
But why ...
-3
votes
1
answer
344
views
What is Allison's Algorithm?
What is Allison's Algorithm and how does it aid in converting hex digits into ASCII characters?
;algorithm (found online)
ADD AL, 90h
DAA
ADC AL, 40h
DAA
http://computer-programming-forum.com/...
8
votes
1
answer
2k
views
Where are the stacks for the other threads located in a process virtual address space?
The following image shows where the sections of a process are laid out in the process's virtual address space:
You can see that there is only one stack section (since this process only has one thread ...
1
vote
3
answers
536
views
Does an ISA (Instruction Set Architecture) also specify the registers available in the CPU?
I am new to Assembly, and based on my understanding, an ISA (Instruction Set Architecture) specifies what instructions are available for a particular CPU.
But does an ISA also specify what registers ...
1
vote
1
answer
385
views
Intel Memory Addressing Form
I'm am trying to understand machine code memory addressing for x86, and I've encountered two opposing general forms for addressing (using the ModRM and SIB bytes).
Most unofficial resources I consult ...
3
votes
2
answers
406
views
When designing an ISA , is it a good design decision to permit a `pop` instruction that does not require an operand to receive the popped value?
A lot of ISAs including x86, x64, ARM, Itanium, have a pop instruction that requires an operand which is usually a register (or, in ARM's case, a register list). In fact, I can't think of an ISA off ...
-10
votes
1
answer
13k
views
Convert program in Java to Assembler? [closed]
I have to do a program to school in Assembler but we did just a few basic things. Is it possible to write code in Java and convert it to Assembler?
4
votes
2
answers
417
views
Criteria for a language (Terra as a tricky example) to be usable for operating system development, and how to meet missing criteria
For example, a language that I was looking at recently- Terra. You can address the question in the context of any language, I'm just most comfortable with Lua so I'm starting from there.
The Terra ...
1
vote
2
answers
2k
views
Difference between assembly code and disassembly listing
Is the disassembly listing generated by a disassembler exactly the same as the assembly code listing that is optionally generated by a compiler during the compilation of C code?
5
votes
2
answers
1k
views
How does a compiler know the machine language of targeted processor to which the source code has to be converted?
For ex: Two machines have the same compiler and the same operating system. But the two machines have different processors (different assembly instructions).As the compiler was downloaded with respect ...