【发布时间】:2020-12-17 04:28:29
【问题描述】:
%include "asm_io.inc"
;
; initialized data is put in the .data segment
;
segment .data
array: dd 180,32,455,499,388,480,239,346,257,84
fmt: dd ",%d",0
; uninitialized data is put in the .bss segment
;
segment .bss
resd 10
;
; code is put in the .text segment
;
segment .text
extern printf
global asm_main
asm_main:
enter 0,0 ; setup routine
pusha
; The following is just example of how to print an array
push dword 10
push dword array
call print_array
add esp,8 ; clean up stack
; don't delete anything following this comment
popa
mov eax, 0 ; return back to C
leave
ret
segment .data
ListFormat db ",%u", 0
segment .text
global print_array
print_array:
enter 0,0
push esi
push ebx
xor esi, esi ; esi = 0
mov ecx, [ebp+12] ; ecx = n
mov ebx, [ebp+8]
xor edx, edx
mov dl, [ebx + esi] ; ebx = address of array
mov eax,edx
call print_int
dec ecx
inc esi
print_loop:
xor edx,edx
mov dl,[ebx + esi]
push ecx ; printf might change ecx!
push edx ; push array value
push dword ListFormat
call printf
add esp, 8 ; remove parameters (leave ecx!)
inc esi
pop ecx
loop print_loop
call print_nl
pop ebx
pop esi
leave
ret
所以当我想打印出 180,32,455,499,388,480,239,346,257,84 时,这段代码会打印出 180,0,0,0,32,0,0,0,199,1。我认为这是因为这是为打印字节字而设计的。我正在尝试用双字打印,我猜 print_array 中的某些内容需要更改。我尝试了 mov dl, [ebx+esi*4] 但它仍然没有打印我想要打印的数组。还是需要更改其他内容才能打印双字数组?
【问题讨论】:
-
dl是一个字节大小的寄存器。你想要mov edx, [ebx + esi*4](假设print_int将使用edx中的所有位,而不仅仅是dl)。