汇编程序中打印数字的偏移量

问题描述 投票:2回答:1

我在Assemler上编写了一个代码,在这里我通过使用offset的printf打印char数组。它工作正常。

#include <iostream>
using namespace std;
char FORMAT[] = "%s %s %s %s, %s\n";
char SURNAME[] = "Ponomarenko";
char NAME[] = "Maria";
char DESIGN[] = "Design";
char BY[] = "by";
char YEAR[] = "2020";
int YEAR1 = 2020;
void main() {
__asm { 
    mov eax, offset YEAR
    push eax
    mov eax, offset SURNAME
    push eax
    mov eax, offset NAME
    push eax
    mov eax, offset BY
    push eax
    mov eax, offset DESIGN
    push eax
    mov eax, offset FORMAT
    push eax
    mov edi, printf
    call edi

    pop ebx
    pop ebx
    pop ebx
    pop ebx
    pop ebx
} 
system("pause");
} 

比起尝试打印数字YEAR1,我尝试了此操作

mov eax, offset YEAR1
    push eax

结果很奇怪,然后我写上没有偏移的字样,就可以了! (当然,在两种情况下,我都更改了FORMAT数组)

mov eax, YEAR1
    push eax

您能解释为什么用这种方法胶印效果会影响打印数字吗?

c++ assembly printf visual-studio-2019 offset
1个回答
0
投票

在Visual Studio中,使用Microsoft汇编程序(MASM),其中offset

© www.soinside.com 2019 - 2024. All rights reserved.