2014-04-28 33 views
-1

我有2個功能。一個是撥打CountCharDisplayResult如下。我如何將charInput數組作爲參考從CountChar函數傳遞給DisplayResult函數?任何幫助將非常感激。謝謝。如何在彙編語言中引用數組?

CountChar PROC 
    pushad 

    xor eax, eax 
    xor ebx, ebx 
    xor edx, edx 
    mov esi, 0 
    mov ecx, bufSize 
L1: 
    mov al, buffer[esi] 
    mov dl, charInput[eax] 
    inc dl 

    mov charInput[eax], dl   ; How to pass charInput as reference ???? 

    inc esi 
    loop L1    ; end loop 

     popad 
     ret 
CountChar ENDP 



DisplayResult PROC 
     pushad 
     ; somehow retrieve the charInput from above for display ??? 
     popad 
     ret 
DisplayResult ENDP 

回答

1

指針是一個指針,是一個指針。指向數據的指針與指向代碼的指針具有相同的位數。這些位無論是函數向量還是數據向量都沒有獨特的屬性。

你可以做這幾方面的方法

首先,

DisplayResult PROC,the_vector:DWORD

mov eax, the_vector ; Moves the passed value "the_vector" into eax 
call eax 
ret 

DisplayResult ENDP

DisplayResult PROC 流行edx; POP返回矢量 pop eax; POP的功能矢量 push edx;保存將由[eax] jmp eax完成的'ret'的返回向量;跳轉到eax,這將返回給誰打電話給我們 DisplayResult endp

擺脫所有的pushad/popad的東西,它浪費了時間。只推送所需的寄存器並嘗試僅使用預計會被銷燬的寄存器。

彙編語言的要點是利用次要的東西,以便它最終幫助你;否則,使用C.

的C原型DisplayResult應該是這樣的:

的extern空隙DisplayResult(無效*);

當你調用它時,將函數名稱作爲void *。像這樣:

DisplayResult((void *)my_function);