小编Cra*_*aig的帖子

为什么汇编程序仅在与crt1.o crti.o和crtn.o链接时才有效?

我想知道程序是如何工作的,以便尽可能地让它成为一块骨头.

我刚刚发现了如何使用wprintf函数为x86_64汇编代码(发现宽字符是32位).我所要做的只是链接到libc(-lc).

我正在尝试为32位代码组装代码做同样的事情,但我偶然发现了一点.最终我使用gcc进行链接(并将_start:更改为main :).所以我用ld自己做了连接,包括crt1.o crti.o和crtn.o. 然后我的程序工作(之前不打印任何东西)所以我的问题是,我可以在我的代码中做些什么来消除对这些其他3个目标文件的需要(当然还原为_start:而不是main :) ?

test_lib.S

.section .data
locale:
  .string ""
  .align 4
printformat:
  .long '%','l','c',0

.section .text
.global main
main:

pushl   $locale
pushl   $6
call    setlocale
pushl   $12414
pushl   $printformat
call    wprintf
pushl   $2
call    exit
Run Code Online (Sandbox Code Playgroud)

并运行以下

as --32 test_lib.S -o test_lib.o
ld -m elf_i386 -L/lib/ -L/usr/lib/ -I/lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o -lc /usr/lib/crtn.o test_lib.o -o test_lib
./test_lib
Run Code Online (Sandbox Code Playgroud)

哦,输出只是日本平假名(ma)ま(注意没有换行符,所以它在提示之前打印)

x86 assembly linker 32-bit

7
推荐指数
1
解决办法
1515
查看次数

如何通过%errorlevel%获取退出代码,它不再适用于汇编程序

我想得到我的教程汇编程序的退出代码(使用masm32和链接).它工作正常,我会输入echo %errorlevel%,它会显示我输入的退出代码invoke ExitProcess.现在它不再起作用了.我在OpenSuse 12.1主机和Windows Vista Home Premium上使用VirtualBox作为访客.我已经找到了答案,但已经缩短了.大多数抱怨是关于使用批处理文件,这不是我想要做的.这是一个简单的程序

hello_world.asm

.586
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data
HelloWorld  db  "Hello World!", 0
.code
start:
invoke MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK
invoke ExitProcess, 2

end start
Run Code Online (Sandbox Code Playgroud)

我希望它返回2,但echo %errorlevel%返回0.有什么我想念的吗?谢谢,我道歉这个问题已经被解决了.我找不到答案.

编辑:实际上,我找到了部分答案.它只适用于我链接使用/SUBSYSTEM:CONSOLE.使用/SUBSYSTEM:WINDOWS始终返回0.我不知道该怎么做.带有Windows程序的退出代码在哪里?任何信息非常感谢.

windows assembly masm errorlevel masm32

0
推荐指数
1
解决办法
527
查看次数

标签 统计

assembly ×2

32-bit ×1

errorlevel ×1

linker ×1

masm ×1

masm32 ×1

windows ×1

x86 ×1