嘗試從asm proc通過eax返回一個long int,然後通過dx:ax嘗試。兩者都不適用於我,因爲C printf打印的數字不是所需的320L。8086/386 asm with bcc5:從asm proc返回long int
x.asm:
.model SMALL
.stack 100h
.code
.386
; extern int get_buffered_long(long int **arr, int num_of_elements, int i);
; [BP+4] [BP+6] [BP+8]
PUBLIC _get_bufferred_long
_get_bufferred_long PROC NEAR
push BP
mov BP,SP
push SI
push DI
push BX
call locate_slot
;mov EAX, DWORD PTR [DI] ;something here doesn't work. the way i return a long int to borland C, or other issue.
mov ax,[DI]
mov dx,[DI+2]
pop BX
pop DI
pop SI
pop BP
ret
_get_bufferred_long ENDP
; extern void set_bufferred_long(long int *arr[], int buff_size, int i,long int value);
; [BP+4] [BP+6] [BP+8] [BP+10]
PUBLIC _set_bufferred_long
_set_bufferred_long PROC NEAR
push BP
mov BP,SP
pushad
call locate_slot
mov EAX,[BP+10]
mov DWORD PTR [DI],EAX
popad
pop BP
ret
_set_bufferred_long ENDP
; helper function that makes DI point to the slot wanted.
locate_slot PROC NEAR
calc_slot:
mov SI,[BP+4]
mov AX,[BP+8]
mov BX,[BP+6]
xor DX,DX
div BX
locate_slot_in_array:
shl AX,1
add SI,AX
mov DI,[SI]
shl DX,2
add DI,DX
ret
locate_slot ENDP
end
y.c:
#include "stdio.h"
#include "stdlib.h"
extern int get_bufferred_long(long int**,int,int);
extern void set_bufferred_long(long int**,int,int,long int);
int main(){
long int **arr;
int i,j,n,m;
n = 5;
m = 4;
arr=(long int**)malloc(n*sizeof(long int*));
for(i=0; i < n; i = i + 2) arr[i] = malloc(m*sizeof(long int));
for(i=1; i < n; i = i + 2) arr[i] = malloc(m*sizeof(long int));
for(i=0; i < n; i++)
for(j=0; j < m; j++)
set_bufferred_long(arr, m, i*m+j, i*100+j*10);
printf("get_bufferred_long(arr, %d, %d) = %ld\n", m, 14, get_bufferred_long(arr,m, 14));
return 0;
}
設定功能的工作原理(陣列長相酷似需要)。 get函數也起作用,它在asm中獲取320L,但是當傳遞給C時,出現了錯誤。
沒有編譯錯誤或警告。 borland C++ 5.02
你有沒有想過升級你的工具鏈到15年前剛發佈的東西? gcc既不含啤酒也不含言語,而Visual C++ Express至少不含啤酒。我希望你有一個充分的理由來發展死技術。 – paxdiablo
@paxdiablo:uni hw,overpowered。 – ckid