Questions tagged [machine-code]

Machine code is data that is directly fed into a microprocessor, being the only form that the processor is able to execute. It is the lowest possible level of abstraction, wherein all data is a raw binary stream. Machine code is barely readable by humans, which is why assembly is usually utilized instead.

Every processor or processor family has its own instruction set. This is a set of instructions the processor has been designed to execute. These instructions are binary codes and in general are not human readable, one would have to memorize the bit patterns. Assembly language is a human readable representation of the machine code where the assembly language mnemonics and following syntax attempt a one to one assembly language instruction to machine code instruction relationship. But assembly language has a fair amount of additional syntax that is not directly related to machine code or machine language.

https://en.wikipedia.org/wiki/Machine_code

The tag is used for questions related to machine code. Additional tags like and and others may also be used.

A tag specifying the architecture , , , , (and many others), is needed as the machine code for different architectures is not compatible, and the question will be difficult to answer without knowing the architecture.

766 questions
27
votes
4 answers

How to generate machine code with llvm

I'm currently working on a compiler project using llvm. I have followed various tutorials to the point where I have a parser to create a syntax tree and then the tree is converted into an llvm Module using the provided IRBuilder. My goal is to…
David Mason
  • 1,545
  • 2
  • 14
  • 14
23
votes
4 answers

AMD64 -- nopw assembly instruction?

In this compiler output, I'm trying to understand how machine-code encoding of the nopw instruction works: 00000000004004d0
: 4004d0: eb fe jmp 4004d0
4004d2: 66 66 66 66 66 2e 0f nopw …
Jeff Ferland
  • 17,832
  • 7
  • 46
  • 76
23
votes
3 answers

RISC-V: Immediate Encoding Variants

In the RISC-V Instruction Set Manual, User-Level ISA, I couldn't understand section 2.3 Immediate Encoding Variants page 11. There is four types of instruction formats R, I, S, and U, then there is a variants of S and U types which are SB and UJ…
22
votes
8 answers

assembly to compare two numbers

What is the assembler syntax to determine which of two numbers is greater? What is the lower level (machine code) for it? Can we go even lower? Once we get to the bit level, what happens? How is it represented in 0's and 1's?
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
21
votes
7 answers

6502 CPU Emulation

It's the weekend, so I relax from spending all week programming by writing a hobby project. I wrote the framework of a MOS 6502 CPU emulator yesterday, the registers, stack, memory and all the opcodes are implemented. (Link to source below) I can…
FlySwat
  • 172,459
  • 74
  • 246
  • 311
18
votes
3 answers

How was the first computer program created?

Possible Duplicate: How was the first compiler written? This question has always been bothering me. To compile a program, you need a compiler, which is also a type of program, so what compiled the compiler? Somebody told me that the first…
user577304
18
votes
2 answers

How do I translate assembly to binary?

For example: .text .align 2 .global main .equ val,0x4712 # 16-bit binary code for 0x4712: 0100 0111 0001 0010 # Program code starts now main: # This…
JustinBieber
  • 355
  • 3
  • 5
  • 23
18
votes
2 answers

How to make gcc generate only machine code that can be loaded directly into memory and executed?

I would like to produce a file that I can load into memory (for example with mmap) and then jump to the start of that memory to run the code. Ideally, I'd like the option of either making the code relocatable (which might be inefficient) or…
David X
  • 3,998
  • 3
  • 29
  • 32
18
votes
7 answers

How can ARM's MOV instruction work with a large number as the second operand?

I just begin to study ARM assembly language, and am not clear about how to use MOV to transfer an immediate number into a register. From both the ARM reference manual and my textbook, it's said that range of immediate number following MOV…
17
votes
4 answers

How does machine code communicate with processor?

Let's take Python as an example. If I am not mistaken, when you program in it, the computer first "translates" the code to C. Then again, from C to assembly. Assembly is written in machine code. (This is just a vague idea that I have about this so…
JoeSlotsky
  • 783
  • 2
  • 7
  • 8
17
votes
13 answers

Can someone tell me the very basics of how computer programming works?

What makes all the words of a programming language actually do anything? I mean, what's actually happening to make the computer know what all of those words mean? If I verbally tell my my computer to do something, it doesn't do it, because it…
user35661
  • 237
  • 1
  • 6
16
votes
3 answers

x64 instruction encoding and the ModRM byte

The encoding of call qword ptr [rax] call qword ptr [rcx] is FF 10 FF 11 I can see where the last digit (0/1) comes from (the register number), but I'm trying to figure out where the second last digit (1) comes from. According to AMD64…
rwallace
  • 31,405
  • 40
  • 123
  • 242
15
votes
2 answers

JMP instruction - Hex code

Have a doubt regarding the hex code conversion of JMP machine instruction. I have the absolute address I want to jump to, say "JMP 0x400835". First of all, is this allowed? If yes, what would be the corresponding hex code? If not, can I first store…
Deepanjan Mazumdar
  • 1,447
  • 3
  • 13
  • 20
14
votes
2 answers

Why are RISC-V S-B and U-J instruction types encoded in this way?

I am reading a book "Computer Organization and Design RISC-V Edition", and I came across the encoding for S-B and U-J instruction types. Those types I have mentioned above has strange encoded immediate field. S-B types separate the immediate field…
jwkoo
  • 2,393
  • 5
  • 22
  • 35
14
votes
5 answers

Most portable library for dynamic code generation?

I'm looking for the most portable assembler library, like asmjit or jitasm. When I say 'most portable' I mean, that has the most support for a wide verity of architectures. Language doesn't matter so much, but C++ would be the best solution,…
LiraNuna
  • 64,916
  • 15
  • 117
  • 140
1
2
3
51 52