我需要了解汇编语言中struct的语法。另外我还需要知道如何制作结构体数组,该结构体将包含4个变量,每个变量将携带一个整数。.我该怎么做?
新更新:
您能告诉我这段代码有什么问题吗,请在mov arr [edx] .x1,[ebx]行上,它给我一个错误,指出无效的指令操作数,这就是整个代码 包含Irvine32.inc 包含macros.inc
.DATA
line struct
x1 byte ?
x2 byte ?
x3 byte ?
x4 byte ?
line ends
arr2 byte 16 DUP (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
arr line 4 DUP (<0,0,0,0>)
.CODE
main PROC
mov ebx,offset arr2
mov edx ,type arr
mov ecx,4
l:
mov arr[edx].x1 , [ebx]
inc ebx
mov arr[edx].x2 , [ebx]
inc ebx
mov arr[edx].x3 , [ebx]
inc ebx
mov arr[edx].x4 , [ebx]
inc ebx
inc edx
loop l
mov edx ,offset arr
mov ecx,4
l1:
movzx eax, byte PTR arr[edx].x1
call writeint
movzx eax, byte PTR arr[edx].x2
call writeint
movzx eax, byte PTR arr[edx].x3
call writeint
movzx eax, byte PTR arr[edx].x4
call writeint
inc edx
loop l1
exit
main ENDP
END main
答案 0 :(得分:0)
示例源文件(Visual Studio 2015)
title xmpl
.586p
.model FLAT
; include C libraries
includelib msvcrtd
includelib oldnames
includelib legacy_stdio_definitions.lib ;for scanf, printf, ...
xmpl struct ;delcare structure (nothing initialized)
x0 dword ?
x1 dword ?
x2 dword ?
x3 dword ?
xmpl ends
.data
axmpl xmpl 30 dup ({0,0,0,0}) ;array of 30 structs (init to zeroes)
.code
_main proc near
lea ebx,axmpl ;ebx points to first instance in array
mov eax,(xmpl ptr [ebx]).x0 ;eax = axmpl[0].x0
; ...
xor eax,eax ;exit from main
ret
_main endp
end
更新的示例:
line struct
x1 byte ?
x2 byte ?
x3 byte ?
x4 byte ?
line ends
.DATA
arr2 byte 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
arr line 4 DUP ({0,0,0,0})
.CODE
main PROC
mov ebx,offset arr2
mov edx,offset arr
mov ecx,4
l:
mov al,[ebx]
mov [edx].line.x1,al
inc ebx
mov al,[ebx]
mov [edx].line.x2,al
inc ebx
mov al,[ebx]
mov [edx].line.x3,al
inc ebx
mov al,[ebx]
mov [edx].line.x4,al
inc ebx
add edx,sizeof line
loop l
mov edx ,offset arr
mov ecx,4
l1:
movzx eax,[edx].line.x1
call writeint
movzx eax,[edx].line.x2
call writeint
movzx eax,[edx].line.x3
call writeint
movzx eax,[edx].line.x4
call writeint
add edx,sizeof line
loop l1
; ...
更新之前使用的替代语法:
mov (line ptr [edx]).x1,al
使用假设:
assume edx:ptr line
; ...
mov [edx].x1,al
; ...
loop l1
assume edx:nothing