Skip to main content
93 votes

Why do we still grow the stack backwards?

Does this mean the base pointer or the stack pointer are actually moving down the memory addresses instead of going up? Why is that? Yes, the push instructions decrement the stack pointer and write ...
Erik Eidt's user avatar
  • 34.2k
22 votes

"Write an Assembler in C." Why writing a machine code translator for a low level language in a higher level language?

You are seeing connections that don't exist. "Write an assembler" is a programming task just like any other programming task. You use the tools to handle that task that are best for that task. There ...
gnasher729's user avatar
  • 45.9k
21 votes
Accepted

"Write an Assembler in C." Why writing a machine code translator for a low level language in a higher level language?

People have written assemblers in machine code. They've also written then in assembly language--often a subset of the language they translate themselves, so they start with a simple "bootstrap" ...
Jerry Coffin's user avatar
  • 44.6k
18 votes
Accepted

Apollo-11: Using inclusion instead of a linker

They seem to mean simple textual concatenation / insertion. In other words, even though the source text was split into individual files, the program wasn't split into modules.
Jörg W Mittag's user avatar
13 votes

How does a compiler know the machine language of targeted processor to which the source code has to be converted?

Essentially, through configuration options. A compiler that understands multiple back-ends will usually assume that source code should be compiled to the platform (os + processor type) on which the ...
Kilian Foth's user avatar
12 votes

Difference between direct and indirect function() calls

The main difference between the direct and the indirect call, is that: the direct call uses an instruction call with a fixed address as argument. After the linker has done its job, this address will ...
Christophe's user avatar
  • 78.4k
11 votes
Accepted

How to make compiler portable?

You cannot make a portable compiler (not in the sense you dream of). You could make a compiler for a particular target machine -or language- (and that machine might even be something like LLVM or ...
Basile Starynkevitch's user avatar
10 votes

"Write an Assembler in C." Why writing a machine code translator for a low level language in a higher level language?

What were they doing in the past while the absence of C language? Were they writing Assembler in Machine Code? Assembly is essentially a mnemonic for machine code; each opcode in the machine ...
esoterik's user avatar
  • 3,909
10 votes

How do we go from assembly to machine code(code generation)

The first thing you need is something like this file. This is the instruction database for x86 processors as used by the NASM assembler (which I helped write, although not the parts that actually ...
Jules's user avatar
  • 17.8k
10 votes

How does a CPU load multiple bytes at once if memory is byte addressed?

Because the width of the data bus and the size of the smallest addressable unit are two separate things. Just because you can specify addresses at the byte level, does not mean you have to have an 8 ...
8bittree's user avatar
  • 5,656
10 votes

How to optimize a mixed stack/register bytecode with control flow and side effects?

There's a huge body of research on this topic, so I really recommend reading a compiler book. Muchnik's book can work well as a reference. I really like Modern Compiler Implementation but I think it's ...
Iulian Dragos's user avatar
10 votes
Accepted

Why is Assembly Language called "Assembly"?

The Name Derives from the Program/Process Created to Read it The most interesting answer I found on the subject suggest that the name of the language came as a result of the name of the program ...
katzbatz's user avatar
  • 327
9 votes
Accepted

How is x86 assembly different from Windows assembly, and does that let me circumvent Windows?

An instruction set is CPU-specific, not OS specific. An assembly language for a instruction set is just an abstraction for that instruction set, and is not inherently OS-specific either. However, a ...
amon's user avatar
  • 135k
9 votes
Accepted

How does a JIT compiler actually emit and then call the emitted native code?

If I was writing a normal compiler, I couldsimply write the desired binary to a file, to be run later by the system in whatever manner it usually would be, but how would a JIT compiler do that during ...
Jörg W Mittag's user avatar
8 votes

Why data alignment is used exactly?

Essentially, yes. It is possible for the CPU to read memory at non-aligned addresses, but it takes longer. This is probably a simplification, but it works something like this: There are generally a ...
user1118321's user avatar
  • 4,991
8 votes
Accepted

How to evaluate efficiency of assembler code?

As others have pointed out, just counting clock cycles of assembler instructions will not give you a decent result for most modern CPU architectures. The execution time of a fixed piece of machine ...
Doc Brown's user avatar
  • 209k
8 votes

Why do we still grow the stack backwards?

In your specific system the stack starts from high memory address and "grow" downwards to low memory addresses. (the symmetric case from low to high also exists) And since you changed from -4 and +...
nadir's user avatar
  • 773
8 votes

Debugging miscompile

Anyone figured out compiler bugs would share their experience? In my 30+ years of programming, the only compiler bugs I’ve ever encountered were when I was working on the compiler. What you’re ...
Telastyn's user avatar
  • 109k
7 votes
Accepted

What are microcontrollers programmed in most in industry? C or Assembly?

Most end-user applications are written in C or a close derivative of C, or another language, like Lua or BASIC or something. However, a lot of the really interesting jobs with microcontrollers ...
Karl Bielefeldt's user avatar
7 votes

How many bytes is a long in a 64 bit machine

How many bytes is a long in a 64 bit machine? Ultimately it is the language implementation that decides these matters, not the CPU instruction set.  For example, for a standards compliant ...
Erik Eidt's user avatar
  • 34.2k
7 votes
Accepted

Do differences between ATT and Intel formats of assembly languages come from differences between their underlying machine languages?

Considering that both AT&T syntax and Intel syntax are used for x86 assemblers, the difference cannot possibly be related to the underlying machine language, because there is only one underlying ...
Jörg W Mittag's user avatar
6 votes

Is C is a portable language for new architectures or it is specific to ISAs?

How C language is portable to any instruction set (I mean for new architecture). It is not, but C is portable to most reasonable instruction sets close to existing ones. As an hypothetical counter-...
Basile Starynkevitch's user avatar
6 votes
Accepted

Is C is a portable language for new architectures or it is specific to ISAs?

in general, every new architecture needs a new port of the C compiler (along with the rest of the C tool chain) Usually this starts with the development of a 'cross compiler' on a known ...
user3629249's user avatar
6 votes

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?

I personally wouldn't put such an instruction in my ISA. Here's why: ISAs should be economical; that is, they should provide their functionality using as few instructions and as few permutations of ...
Robert Harvey's user avatar
6 votes
Accepted

What is the difference between writing in assembly vs converting high level language into assembly using compiler?

High level languages like C do not expose all functionality of the CPU's instruction set. Sometimes the compiler is smart enough to use those features without being told to, but sometimes hoping for ...
amon's user avatar
  • 135k
6 votes

Why will it take approximately 2 years for Apple to transition Mac to ARM?

There are two aspects to this: hardware and software. Hardware You are assuming that the second Apple recompiles all the code, everybody will throw away their computers, and buy new ones. That will ...
Jörg W Mittag's user avatar
6 votes

Does the assembler perform the same tasks as the translator from C to assembly?

Yes, on a high level there is some similarity. It's just that translating from assembly to machine code is much much simpler than translating C code to assembly. It is better to understand the ...
amon's user avatar
  • 135k
6 votes

How do these two ways of enforcing alignment work together?

Computer memory does not care about types, but does care about word size. A word consists of multiple bytes. The CPU's instruction set has instructions for reading or writing (or atomically modifying) ...
amon's user avatar
  • 135k
5 votes

How does one structure an assembly-language project?

A book could be written on this topic. I bet some have . . . It's hard to answer because each tool-chain has its own strengths, shortcomings and quirks. I must have structured different projects a ...
Mark's user avatar
  • 226
5 votes
Accepted

How assembler converts to machine code 1 and 0

Short answer: the same way any other compiler works. Long answer: A program that takes programming code input in one language and transforms it to output in a different language is called a compiler. ...
Mason Wheeler's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible