我最近开始在NASM汇编中进行编码,我的问题是我不知道如何正确地访问struct元素。我已经在该网站和google上搜索了解决方案,但是到处都是人们说不同的话。我的程序崩溃了,我感到问题出在访问结构上。
查看示例代码时:
STRUC Test
.normalValue RESD 1
.address RESD 1
ENDSTRUC
TestStruct:
istruc Test
at Test.normalValue dd ffff0000h
at Test.address dd 01234567h
iend
;Example:
mov eax, TestStruct ; moves pointer to first element to eax
mov eax, [TestStruct] ; moves content of the dereferenced pointer to eax (same as mov eax, ffff0000h)
mov eax, TestStruct
add eax, 4
mov ebx, eax ; moves pointer to the second element (4 because RESD 1)
mov eax, [TestStruct+4] ; moves content of the dereferenced pointer to eax (same as mov eax, 01234567h)
mov ebx, [eax] ; moves content at the address 01234567h to ebx
对吗?
感谢您的帮助
答案 0 :(得分:0)
我不知道您是否知道,但是这是我们的代码,做了一些小的修改即可。除了最后一个try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Pipe pipe = new Pipe(image.getInputStream(), outputStream);
convertCmd.setInputProvider( pipe );
convertCmd.setOutputConsumer( pipe );
return outputStream.toByteArray();
}
以外,所有指令都是正确的,这是您试图访问地址mov ebx, [eax]
导致内容0x1234567
SIGSEGV
使用section .bss
struc Test
normalValue RESD 1
address RESD 1
endstruc
section .data
TestStruct:
istruc Test
at normalValue, dd 0xffff0000
at address, dd 0x01234567
iend
section .text
global _start
_start:
mov eax, TestStruct ; moves pointer to first element to eax
mov eax, [TestStruct] ; moves content of the dereferenced pointer to eax same as mov eax, ffff0000h
mov eax, TestStruct
add eax, 4
mov ebx, eax ; moves pointer to the second element 4 because RESD 1
mov eax, [TestStruct+4] ; moves content of the dereferenced pointer to eax same as mov eax, 01234567h
mov ebx, [eax] ; moves content at the address 01234567h to ebx
编译,链接和逐步运行