我对为什么在以下说明中imul设置感到困惑OF
mov al, 48
mov bl, 4
imul bl ; AX = 00C0h, OF = 1
Run Code Online (Sandbox Code Playgroud)
但不在以下说明中
mov ax, 48
mov bx, 4
imul bx ; DX:AX = 000000C0h, OF = 0
Run Code Online (Sandbox Code Playgroud) 在我的引导加载程序代码中有一个部分,我们通过加载 GDT 并启用控制寄存器位来将 cpu 切换到保护模式。
这是引导加载程序代码的部分:
init_pm:
...
cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
; far jump
jmp CODE_SEG:start_protected_mode
[bits 32]
start_protected_mode:
...
Run Code Online (Sandbox Code Playgroud)
这些是常数:
CODE_SEG equ code_descriptor - GDT_start
DATA_SEG equ data_descriptor - GDT_start
Run Code Online (Sandbox Code Playgroud)
所以我的问题如下:
什么是远跳?
进入保护模式到底对CPU有什么影响?
什么是CODE_SEG以及为什么我们将它与偏移量
start_protected_mode一起使用?我们不能像这样进行正常的跳跃吗jmp start_protected_mode?我知道它是 GDT 中代码描述符的位置,但这是否会自动被 cpu 识别为引导加载程序代码的位置?
假设我更改了一个单词中的一位并添加了另外两个单词。
更改字中的一位是否比更改整个字消耗更少的 CPU 周期?
如果它消耗更少的 CPU 周期,它会快多少?
引用gnu:
实际上,您可以假设 int 是原子的。您还可以假设指针类型是原子的;非常方便。这两个假设在 GNU C 库支持的所有机器上以及我们所知的所有 POSIX 系统上都是成立的。
这怎么可能?我见过的与锁相关的所有示例都是用int计数器制作的,例如https://www.delftstack.com/howto/c/mutex-in-c/。
我正在使用 MASM 和 Irvine32 编写基本的 ASM 代码。该代码按字符输入,用户输入他们想要输入的字符数,然后循环运行那么多次。
该程序仅接受字母。如果按下 num 或其他内容,则显示“拒绝”消息。
如果 ECX == 0(用户输入的数字),则返回 Main(调用函数)。
现在我的问题是ret指令将控制权交还给同一过程(称为过程)的开始,而不是返回到主程序(调用者)。
include Irvine32.inc
.data
Input_Prompt BYTE "Enter String:", 0
Max_Length_input BYTE "Enter max length to read:", 0
Rejected_mess BYTE "Rejected !", 0
ret_mess BYTE "returing mess !", 0
USER_STR BYTE ?
.code
main PROC
mov edx, offset Max_Length_input ;ask for max length
call WriteString
call Readint
mov ecx, eax
mov esi, offset USER_STR ;passing offset of storage
call String_Input
main endp
String_Input PROC …Run Code Online (Sandbox Code Playgroud) 这些是MOV来自Intel\xc2\xae 64 和 IA-32 架构软件开发人员手册的指令操作码:
B8+ rd id MOV r32, imm32 OI Valid Valid Move imm32 to r32。
C7 /0 id MOV r/m32, imm32 MI Valid Valid Move imm32 to r/m32。
我拆解如下:
\n0: b8 44 33 22 11 mov eax, 0x11223344\nRun Code Online (Sandbox Code Playgroud)\n0: 67 c7 00 44 33 22 11 mov DWORD PTR[eax], 0x11223344\nRun Code Online (Sandbox Code Playgroud)\n我想问的问题是:
\n为什么C7操作码是寄存器/内存(r/m32, imm32)而不是仅内存(m32, imm32)?
是否有任何时候我们使用 …
该问题与用伽马序列加密字符串的函数有关。
函数调用:
cout << "\ncipher with code: ";
for (register int i = 0; i < str.length(); i++) {
str[i] = fun_cipher_gamma(str[i], gamma[i]);
cout << str[i];
}
cout << endl;
Run Code Online (Sandbox Code Playgroud)
函数本身:
char fun_cipher_gamma(register char simbol, register char gamma)
{
char result = ' ';
funct();
return result;
}
Run Code Online (Sandbox Code Playgroud)
汇编代码:
.MODEL FLAT, C
.STACK 256
.DATA
.CODE
EXTRN gamma : BYTE
EXTRN simbol : BYTE
EXTRN result : BYTE
PUBLIC funct
funct PROC far
mov al, simbol
mov bl, gamma
xor …Run Code Online (Sandbox Code Playgroud) 这是 C 代码:
int baz(int a, int b)
{
return a * 11;
}
Run Code Online (Sandbox Code Playgroud)
它被编译为以下一组汇编指令(带有 -O2 标志):
baz(int, int):
lea eax, [rdi+rdi*4]
lea eax, [rdi+rax*2]
ret
Run Code Online (Sandbox Code Playgroud)
该lea指令计算第二个操作数(源操作数)的有效地址并将其存储在第一个操作数中。对我来说,第一条指令似乎应该将地址加载到 EAX 寄存器,但是,如果是这样,在第二条指令中将 RAX 乘以 2 没有意义lea,所以我推断这两lea条指令不会做完全相同的事情。
我想知道是否有人可以澄清这里到底发生了什么。
I would like a practical example of the cli and sti instructions in x86 16-bit assembly, i.e. an example in code written in this language which allows me to know what these instructions are for by practice and to go further than theory.
I know the documentation says that cli disables the interrupt flag and sti enables it and the interrupt flag does not affect
not handling non-maskable interrupts (NMI) or software interrupts generated by the int instruction.
In the …
.asciix86 汇编中的指令如何工作?什么时候将 ASCII 码放入内存?我假设文本是放置在主内存中的机器代码的一部分,但是这里机器代码的yourText部分到底做了什么?
在 40100e 中, yourText代码部分的开头被放入 write 系统调用的缓冲区参数中。在 CI 中,会将其解释为将指针传递给字符串文字的第一个字符,但我不完全明白为什么它会转到更多代码,而不是在内存中找到文字的位置。
hwa.out: file format elf64-x86-64
Disassembly of section .text:
0000000000401000 <_start>:
401000: 48 c7 c0 01 00 00 00 mov $0x1,%rax
401007: 48 c7 c7 01 00 00 00 mov $0x1,%rdi
40100e: 48 c7 c6 2a 10 40 00 mov $0x40102a,%rsi
401015: 48 c7 c2 0d 00 00 00 mov $0xd,%rdx
40101c: 0f 05 syscall
40101e: 48 c7 c0 3c 00 00 00 mov $0x3c,%rax
401025: …Run Code Online (Sandbox Code Playgroud) assembly ×8
x86 ×5
x86-64 ×3
c ×2
atomic ×1
bit ×1
bootloader ×1
c++ ×1
concurrency ×1
cpu ×1
cpu-cycles ×1
disassembly ×1
eflags ×1
energy ×1
gcc ×1
gnu ×1
interrupt ×1
irvine32 ×1
machine-code ×1
masm ×1
opcode ×1
x86-16 ×1
xor ×1