我在ASM上的代码是一个检查' array2'是数组1的排列。我在C上的代码有一些函数,这些函数在我的ASM程序中编码。我使用的模式是' Model LARGE'。 (我已经用' Model SMALL'完成了它)一切都很好。
我在发布之前搜索过SOF,但我找不到有用的答案。
错误:'转发参考需要覆盖' (第41行)在线' CALL _biti'
它确实打印了代码的输出,但仍显示错误。
解决方案: 我只是将函数_biti的代码放在asm文件中作为第一个而不是第二个。它以某种方式解决了它。
' cproc.c'
#include <stdio.h>
#include <stdlib.h>
extern int biti(unsigned int n, int i);
extern int compare_i_subset( int arr1[], int arr2[], int n,
unsigned int i);
extern int compute_subsets( int arr1[], int arr2[], unsigned
int results[],int n, unsigned int p);
int main() {
int i, n=5, k, arr1[5] = {11, 1, 2, 12, 3}, arr2[5] = {1, 1, 2, 11, 3};
unsigned int results[32];
k = compute_subsets(arr1, arr2, results, n, 32);
printf("arr1 in reverse order:\n");
for(i=n-1; i >=0; i--)
printf("%8d", arr1[i]);
printf("\narr2 in reverse order:\n");
for(i=n-1; i >=0; i--)
printf("%8d", arr2[i]);
printf("\nSolutions:\n");
for(i=0; i < k; i++)
printf("%8d", results[i]);
return 0;
}// main
&#39; q2large.asm&#39;
.MODEL LARGE
.STACK 100H
.DATA
NamMask DW 1
number DW 1
index DW 0
counter DW 0
k DW 0
.CODE
PUBLIC _compare_i_subset
_compare_i_subset PROC FAR
PUSH BP
MOV BP,SP
PUSH DI
PUSH SI
PUSH DX
PUSH BX
PUSH ES
MOV DI, WORD PTR[BP + 6] ;Array1 in DI
MOV SI, WORD PTR[BP + 10] ;Array2 in SI
MOV BX, [BP + 14] ;Assign index
MOV index, BX
MOV DX, [BP + 16] ;Assign number
MOV number, DX
checkOnBitAg:
PUSH index ; index = 0,1,...,4
PUSH number ; number = 1,2,...,31
; We assign index,counter into function _biti
CALL _biti
ADD SP,4 ; POP index,number
CMP AX,1
JNE checkAgain
;If we get AX=1, lets check arr1[j] <= arr2[j]
MOV ES, WORD PTR[BP+8]
MOV AX, ES:[DI] ;Arr1[0],...,ARR1[4] move into AX
MOV ES, WORD PTR[BP+12]
MOV BX, ES:[SI] ;Arr2[0],...,ARR2[4] move into BX
CMP AX, BX
;If we failed once! EXIT! (return zero, AX = 0)
JA failureNums ; Check next number
;Lets check next 'bit' that is 'ON'
checkAgain:
INC index ;index++
ADD SI,2 ; Because SI is stores INTEGERS!
ADD DI,2 ; Because DI is stores INTEGERS!
CMP index,5
JE finishedAllNums
JMP checkOnBitAg ;Go push again! and check with next index.
finishedAllNums:
MOV AX, 1
JMP FinishFunc2
failureNums:
MOV AX,0
FinishFunc2:
POP ES
POP BX
POP DX
POP SI
POP DI
POP BP
RET
_compare_i_subset ENDP
PUBLIC _biti
_biti PROC FAR
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX
MOV CX, WORD PTR[BP + 8]
SHL NamMask, CL ;Made a mask
MOV BX,NamMask
AND BX,WORD PTR[BP+6] ;Nam*Mask
CMP BX,0
JE BitNotOn
MOV AX,1
JMP Finish
BitNotOn:
MOV AX,0
Finish:
MOV NamMask,1
POP BX
POP CX
POP BP
RET
_biti ENDP
PUBLIC _compute_subsets
_compute_subsets PROC FAR
PUSH BP
MOV BP,SP
PUSH DI
PUSH ES
MOV DI, WORD PTR [BP + 14] ; Results in DI
mov ES, WORD PTR [BP + 16]
checkAgain2:
CMP number,31
JG finishedFunc3
PUSH number ; first number will be 1, until 31.
PUSH index ; Initialize index = 0
PUSH DWORD PTR[BP + 10] ; Push address of Arr2
PUSH DWORD PTR[BP + 6] ;Push address of Arr1
CALL _compare_i_subset
ADD SP,12
CMP AX,1
JNE checkAgain4 ; Returned zero (AX = 0)
;else returned AX = 1:
MOV BX,number
MOV ES:[DI], BX ;Input number into [DI]
ADD DI,2 ; DI hold integers
INC k
JMP checkAgain4
checkAgain4:
INC number ; number++
MOV index, 0
JMP checkAgain2
finishedFunc3:
MOV AX, k
POP ES
POP DI
POP BP
RET
_compute_subsets ENDP
END
解决方案代码:
.MODEL LARGE
.STACK 100H
.DATA
NamMask DW 1
number DW 1
index DW 0
counter DW 0
k DW 0
.CODE
_biti PROC FAR
PUBLIC _biti
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX
MOV CX, WORD PTR[BP + 8]
SHL NamMask, CL ;Made a mask
MOV BX,NamMask
AND BX,WORD PTR[BP+6] ;Nam*Mask
CMP BX,0
JE BitNotOn
MOV AX,1
JMP Finish
BitNotOn:
MOV AX,0
Finish:
MOV NamMask,1
POP BX
POP CX
POP BP
RET
_biti ENDP
;;
_compare_i_subset PROC FAR
PUBLIC _compare_i_subset
PUSH BP
MOV BP,SP
PUSH DI
PUSH SI
PUSH DX
PUSH BX
PUSH ES
MOV DI, WORD PTR[BP + 6] ;Array1 in DI
MOV SI, WORD PTR[BP + 10] ;Array2 in SI
MOV BX, [BP + 14] ;Assign index
MOV index, BX
MOV DX, [BP + 16] ;Assign number
MOV number, DX
checkOnBitAg:
PUSH index ; index = 0,1,...,4
PUSH number ; number = 1,2,...,31
; We assign index,counter into function _biti
CALL _biti
ADD SP,4 ; POP index,number
CMP AX,1
JNE checkAgain
;If we get AX=1, lets check arr1[j] <= arr2[j]
MOV ES, WORD PTR[BP+8]
MOV AX, ES:[DI] ;Arr1[0],...,ARR1[4] move into AX
MOV ES, WORD PTR[BP+12]
MOV BX, ES:[SI] ;Arr2[0],...,ARR2[4] move into BX
CMP AX, BX
;If we failed once! EXIT! (return zero, AX = 0)
JA failureNums ; Check next number
;Lets check next 'bit' that is 'ON'
checkAgain:
INC index ;index++
ADD SI,2 ; Because SI is stores INTEGERS!
ADD DI,2 ; Because DI is stores INTEGERS!
CMP index,5
JE finishedAllNums
JMP checkOnBitAg ;Go push again! and check with next index.
finishedAllNums:
MOV AX, 1
JMP FinishFunc2
failureNums:
MOV AX,0
FinishFunc2:
POP ES
POP BX
POP DX
POP SI
POP DI
POP BP
RET
_compare_i_subset ENDP
_compute_subsets PROC FAR
PUBLIC _compute_subsets
PUSH BP
MOV BP,SP
PUSH DI
PUSH ES
MOV DI, WORD PTR [BP + 14] ; Results in DI
mov ES, WORD PTR [BP + 16]
checkAgain2:
CMP number,31
JG finishedFunc3
PUSH number ; first number will be 1, until 31.
PUSH index ; Initialize index = 0
PUSH DWORD PTR[BP + 10] ; Push address of Arr2
PUSH DWORD PTR[BP + 6] ;Push address of Arr1
CALL _compare_i_subset
ADD SP,12
CMP AX,1
JNE checkAgain4 ; Returned zero (AX = 0)
;else returned AX = 1:
MOV BX,number
MOV ES:[DI], BX ;Input number into [DI]
ADD DI,2 ; DI hold integers
INC k
JMP checkAgain4
checkAgain4:
INC number ; number++
MOV index, 0
JMP checkAgain2
finishedFunc3:
MOV AX, k
POP ES
POP DI
POP BP
RET
_compute_subsets ENDP
END