Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; lab8.asm - a function that checks if an array is a premutation of the other
- ;
- .MODEL SMALL
- .STACK 100h
- .DATA
- Count DB 10 DUP(0)
- .CODE
- PUBLIC _PermutationArray
- _PermutationArray PROC NEAR
- PUSH BP
- MOV BP,SP
- PUSH DI
- PUSH SI
- XOR CX,CX ; CX = 0
- MOV DI,[BP+4] ; DI = int array1[]
- MOV SI,[BP+6] ; SI = int array2[]
- MOV CX,[BP+8] ; CX = int size
- DEC CX ; i--
- CounterLoop:
- CMP CX,0 ; i >= 0
- JL ExitCounterLoop ; i < 0
- ADD Count[DI],1 ; count[array1[i]]++
- SUB Count[SI],1 ; count[array2[i]]--
- INC DI
- INC SI
- DEC CX ; i--
- JMP CheckLoop
- ExitCounterLoop:
- MOV DI,[BP+8] ; CX = int size
- DEC CX ; i--
- CheckLoop:
- CMP CX,0 ; size >= i
- JL ReturnTrue ; return 1
- CMP Count[DI],0 ; if(count[i])
- JG ReturnFalse ; return 0
- DEC CX ; i--
- JMP CheckLoop
- ReturnTrue:
- MOV AX,1
- JMP Exit
- ReturnFalse:
- XOR AX,AX
- Exit:
- POP SI
- POP DI
- POP BP
- RET
- _PermutationArray ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement