Hey Princess: 8086 Programs
Hey Princess: 8086 Programs
8086 Programs
AX BX CX
BX holds the address of the starting element of the array of elements CX is the count register again to store the total number of elements AX is used for doing all the comparisons etc.
Program Code
Line 1: moves 0003H to CX register Line 2: moves 1100 to BX register Line 3: moves the data stored at 1100 to AX register Line4 and Line 5: increment BX to point to next memory address Line 6: compare AX and the value stored in the memory address present in BX which means now it compares 7 and 9 what cmp actually does is it just subtracts 7 from 9.. ie. 7 - 9 and if the answer is negative Carry ag (CF) is set to 1 which means 7 is less than 9
1100
0003H
now if we did cmp 9, 7 then since the answer wouldnt have been negatve CF would be 0 only
AX BX CX
1100 1102
7 9
Program Code
which means the next instruction jc (jump if carry) wouldnt do the jumping... instead it would just move 7 into the AX register as given in line 8. remember we have to nd the smallest element and we keep the smallest elemnt in AX so now since we have carry jc jumps to NEXT line 9: here we jut decrement CX and go back to loop 1
1100
0003H
AX BX CX
1100 1102
7 9
Program Code
once the smallest elemnt has been found it is moved to 1200 in line 11 in our example the smallest is 7 so now 7 is in memory location 1200 :)
1100
0003H
1100 1102
AX BX CX
7 9