Description: This code in assembly language is a program to
find first repeating element in an array. For example,
myArray: dw 5,6,1,4,3,2,8,4,8
then “result”
in memory should contain 4
[org 0x0100]
mov cx , [size]
add cx , [size]
sub word cx , 2
mov si , 0
mov di , 0
outerLoop:
cmp si , cx
jnl exit
mov di , si
add word di ,2
innerLoop:
mov ax , [arr+si]
mov dx , [arr+di]
cmp ax , dx
jz placeResult
return:
add di , 2
cmp di , cx
jl innerLoop
incSI:
inc si;
inc si
jmp outerLoop
placeResult:
mov ax , [arr+si]
mov [result] , ax
jmp exit
exit:
mov ax , 0x4c00
int 0x21
result: dw 0
size: dw 9
arr: dw 5,6,1,8,3,2,7,4,4
No comments
Post a Comment