汇编语言和机器语言有什么关系?

发布于 2024-08-01 13:40:58 字数 47 浏览 12 评论 0原文

汇编语言和机器语言(对于同一个底层系统)真的一样吗? 这两个概念有什么区别吗?

Are assembly language and machine language (for the same underlying system) really the same? Are there any differences between these two concepts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

好多鱼好多余 2024-08-08 13:40:58

汇编语言是人类可以理解的操作码(操作码)的符号编码,仅用于指示计算机处理器(硬件操作)和机器人(机器人操作)执行特定任务。 这是人类可以理解的语言。 该语言仅用于指导硬件操作,绝对不能用于创建软件程序。 汇编器用于将操作码(操作码)的符号编码部分转换为机器语言。 操作码(Opcode)是机器语言的一部分。

Assembly Language is the symbolic encode of opcode (operation code) that is understand by humans and only use to instruct computer processor (hardware operation) and robot (robotic operation) to perform specific tasks. This is an understandable language to human. This language is only use to instruct hardware operation and definitely not use to create software programme. A assembler is use to convert this symbolic encode part of opcode (operation code) into machine language. Operation Code (Opcode) is a part of machine language.

风铃鹿 2024-08-08 13:40:58

汇编语言是一种比机器语言更方便的机制。 使用汇编语言,您可以使用助记符序列而不是数字操作代码,并且可以使用符号标签而不是手动计算偏移量。 它还可以保护您免受真正愚蠢的错误 - 例如输入格式错误的处理器指令。

否则,汇编语言就相当于机器语言。 有时,您的旧汇编器不支持较新处理器的某些指令的助记符 - 那么您仍然可以将操作代码直接插入程序中。

Assembly language is a convenience mechanism over the machine language. With assembly language you use mnemonic sequences instead of numeric operation codes and can use symbolic labels instead of manually calculating offsets. It also protects you from really dumb errors - like typing a malformed processor instruction.

Otherwise the assembly language is the equivalent of the machine language. Sometimes you will have an old assembler that will not support mnemonics for some instructions of the newer processors - then you can still insert operation codes directly into the program.

隔纱相望 2024-08-08 13:40:58

机器语言是 CPU 操作码的“位编码”。

汇编语言是 CPU 操作码的“符号编码”。

因此,例如象征性地:

loop:  dec R1    # Decrement register R1
       bnq loop  # Branch if not equal to zero to
                 # address "loop"

成为此位编码:

# Mythical CPU machine code 4 bits operation,
#                           4 bit "option"
0x41      # 4 is a "dec" and represents r1;
0x7E      # 7 is bnq and E means PC -2;

通常它是一对一的关系,但是某些汇编语言偶尔会具有额外的汇编指令,这些指令映射到多个机器代码指令或重用另一个操作码。 例如使用机器代码“xor R1,R1”作为“clr R1”或非常类似的东西。

此外,汇编语言将倾向于支持“宏编程”,这在汇编广泛使用的 80 年代使源代码具有更“高级”的外观。 我亲自编写了类似于“plot x,y”和“Hex Val”的汇编宏来简化常见操作。

例如:

# Mythical CPU macro
.macro spinSleep x,y
            ld #x,y
localLoop:  dec y
            brq localLoop
.endmacro
# Macro invocation
            spinSleep 100,R1
# Macro expansion
            ld #100,R1
localLoopM: dec R1
            brq localLoopM   # localLoopM is "mangled" for localization.

Machine language is the "bit encoding" of a CPU's opcodes.

Assembly language is the "symbolic encoding" of a CPU's opcodes.

So for example symbolically:

loop:  dec R1    # Decrement register R1
       bnq loop  # Branch if not equal to zero to
                 # address "loop"

Becomes this bit encoding:

# Mythical CPU machine code 4 bits operation,
#                           4 bit "option"
0x41      # 4 is a "dec" and represents r1;
0x7E      # 7 is bnq and E means PC -2;

Generally it's a one to one relationship, however some assembly languages will occasionally have extra assembly instructions that map to either multiple machine code instructions or reuse another opcode. Such as using machine code "xor R1,R1" as a "clr R1" or something very similar.

In addition, assembly languages will tend to support "macro programming" which, in the 80's when assembly was used extensively, gave the source code a more "high level" appearance. I've personally written assembly macros that looked like "plot x,y" and "Hex Val" to simplify common operations.

For example:

# Mythical CPU macro
.macro spinSleep x,y
            ld #x,y
localLoop:  dec y
            brq localLoop
.endmacro
# Macro invocation
            spinSleep 100,R1
# Macro expansion
            ld #100,R1
localLoopM: dec R1
            brq localLoopM   # localLoopM is "mangled" for localization.
相思故 2024-08-08 13:40:58

我找到了一个非常好的解释,想将其发布在这里,以便其他人可以阅读:

机器语言是实际的位
用于控制处理器中
计算机,通常被视为序列
十六进制数(通常是
字节)。 处理器读取这些位
从程序存储器中输入,以及位
代表关于做什么的“说明”
接下来做。 因此机器语言
提供了一种进入方式
指令输入计算机(无论
通过开关、打孔胶带或
二进制文件)。

汇编语言更人性化
机器语言的可读视图。
而不是代表机器
语言作为数字,指令
寄存器被赋予名称
(通常是缩写词,或
助记符,例如 ld 表示“加载”)。 不像
汇编语言是一种高级语言
非常接近机器语言。
主要抽象(除了
助记符)是标签的使用
而不是固定的内存地址,并且
评论。

汇编语言程序(即
文本文件)被翻译成机器
汇编语言。 A
反汇编程序执行相反的操作
功能(尽管评论和
标签的名称将是
在汇编程序过程中被丢弃)。

来源:机器语言和汇编语言有什么区别?

I found a really good explanation, thought to post it here, so that others could read it:

Machine language is the actual bits
used to control the processor in the
computer, usually viewed as a sequence
of hexadecimal numbers (typically
bytes). The processor reads these bits
in from program memory, and the bits
represent "instructions" as to what to
do next. Thus machine language
provides a way of entering
instructions into a computer (whether
through switches, punched tape, or a
binary file).

Assembly language is a more human
readable view of machine language.
Instead of representing the machine
language as numbers, the instructions
and registers are given names
(typically abbreviated words, or
mnemonics, eg ld means "load"). Unlike
a high level language, assembler is
very close to the machine language.
The main abstractions (apart from the
mnemonics) are the use of labels
instead of fixed memory addresses, and
comments.

An assembly language program (ie a
text file) is translated to machine
language by an assembler. A
disassembler performs the reverse
function (although the comments and
the names of labels will have been
discarded in the assembler process).

Source : What is difference between machine language and assembly language?

梦归所梦 2024-08-08 13:40:58

在汇编中,指令是 CPU 指令更容易理解的表示形式。

但是,汇编器还使寻址变得更容易:

  • 在机器语言中,您必须知道您所在位置与要跳转到的位置之间的距离(在地址空间中)。
  • 在汇编语言中,您将一个地址称为“iWantToJumpHere”,然后您可以可以说“jump iWantToJumpHere”

这使得汇编更容易维护,特别是当地址之间的距离发生变化时。

In Assembly, instructions are easier-to-understand representations of CPU instructions.

But the assembler also makes, for example, addressing easier:

  • In machine language you have to know the distance (in address space) between where you are and where you want to jump to
  • In Assembly language you call one address "iWantToJumpHere" and then you can say "jump iWantToJumpHere"

This makes assembly much easier to maintain, especially when the distance between the addresses changes.

自此以后,行同陌路 2024-08-08 13:40:58

机器语言是芯片能够理解的语言。 装配就是你所理解的。

每个汇编指令都有一个等效的机器语言指令。 x86 有一些单字节指令,但它们是可变长度的,最长可达 15 个字节(包括可选前缀)。

machine code bytes      | x86 assembly language
8D B0 00 36 65 C4         lea    esi, [eax - 1000000000]
BB 00 FC FF FF            mov    ebx, -1024
43                        inc    ebx
41                        inc    eax
3B CA                     cmp    ecx,edx
C3                        ret

C5 F5 72 D2 01            vpsrld ymm1,ymm2,0x1        ; AVX2
C5 F5 D4 6D 88            vpaddq ymm5,ymm1,YMMWORD PTR [ebp-0x78]
C5 CD D4 AD 68 ff ff ff   vpaddq ymm5,ymm6,YMMWORD PTR [ebp-0x98]

Machine language is what the chip understands. Assembly is what you understand.

Every assembly instruction has a machine language equivalent. x86 has a few single-byte instructions, but they're variable-length and can be up to 15 bytes long (including optional prefixes).

machine code bytes      | x86 assembly language
8D B0 00 36 65 C4         lea    esi, [eax - 1000000000]
BB 00 FC FF FF            mov    ebx, -1024
43                        inc    ebx
41                        inc    eax
3B CA                     cmp    ecx,edx
C3                        ret

C5 F5 72 D2 01            vpsrld ymm1,ymm2,0x1        ; AVX2
C5 F5 D4 6D 88            vpaddq ymm5,ymm1,YMMWORD PTR [ebp-0x78]
C5 CD D4 AD 68 ff ff ff   vpaddq ymm5,ymm6,YMMWORD PTR [ebp-0x98]
懒猫 2024-08-08 13:40:58

汇编级语言是通过允许程序员编写助记符而不是二进制代码(机器代码)来使编程变得简单的第一个有意识的步骤。

Assemble level language is the first conscious step towards making the programming simple by allowing the programmers to write mnemonics instead of binary code(machine code).

始于初秋 2024-08-08 13:40:58

汇编语言首先由汇编器转换为机器语言。 它存储在内存(RAM)中,处理器/cup将其取出并从内存中存储到寄存器中,并按照指令集一一执行。

Assembly language is first converted to machine language by the assembler. which is stored in memory (RAM) processor/cup fetch it and store in from memory to register and follow the instruction set one after one.

青丝拂面 2024-08-08 13:40:58

机器语言

机器语言由 1 和 0 组成。 所以光看它很难理解。 所以如果我们要修改代码,那将是一个很大的问题。 机器语言也是一种编程语言(第一代)。我们的计算机CPU可以直接执行机器代码,无需任何汇编程序。

汇编语言

汇编语言由语法、数字和字母组成。 修改现有代码很容易。 所以我们的机器无法理解该程序。 所以机器使用汇编器将汇编语言代码转换为机器代码。

Machine Language

Machine language consists of ones and zeros. so it's so hard to understand by looking at it. so if we want to modify the code , it will be a huge problem. Machine languages is also a programming language(1st Gen).our computer CPU can directly execute that machine code without any assembler.

Assembly Language

assembly language consists of syntax , number , and letter. it's easy to modify existing code. so our machine cannot understand that program. so machine using an assembler to convert that assembly language code into machine code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文