shorting dec ending
TRANSCRIPT
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 1/13
Hey Princess8086 Programs
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 2/13
Shorting (Descending Order)
9 8 7 6 5 4 3 2 1
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 3/13
AX BX CX SI
Registers Used in this program
AX and BX Registers are used to do the arithmatic operations
CX is the count register ( to keep count of how many numbers are there totally )
SI is the register which holds the address of the memory locations where we are giving the data as
input
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 4/13
Program Code Lets Start with Lines 1 and 2 and 4Line 1 initializes the value 0 in AX Register
Line 2 Puts the value 0003H which is hexadecimal for 3 in the BX register
this value is used as a count value, in this program we’re going to sort 3elements hence we save 3 in BX
In line 4 we are putting the value 3 into the CX register also,
because in 8086 the loop instruction depends on the CX
register... if the value of CX is not 0 then the loop instruction
will jump to whatever part of the code that is assigned to it
For Example
loop START
this means jump to the part of the program that is labelled START
which in this case is line no. 6
this jump will only happen if the value of CX is not 0... if the value of
CX is 0 then the line loop START doesnt do anything
We use this to our advantage... so now since CX = 3 we can assume that
all the loop instructions will be performed 3 times at least...
the loop instruction is a combination of 2 instructions
1. decrement CX
2. jump to other part of code
AX BX CX
0000H 0003H 0003H
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 5/13
Program Code
AX BX CX
74 0003H 0003H
Line 5 moves the value 1200H to SI .... now 1200H is the starting address of the data in
the memory location.
Line 6 moves the data stored in 1200H to the AX Register
SI
1200H
1200H
1202H
74
FF
And sweetie lets assume we have entered
the values 74 and FF in the memory
location 1200H and 1202H
notice we dont store anything in 1201H
because the data we are handling is 16 bit
and 1200H is an 8bit memory location so
the processor automatically uses both
1200H and 1201H to store the 16bit data
1200H(8bit) + 1201H(8bit)
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 6/13
Program Code
AX BX CX
74 0003H 0003H
Line 7 is going to compare AX, and [SI + 2]
In the previous slide we moved SI value to AX that means AX now has 74
then we compare the value of AX with [SI + 2] since SI is 1200H that means SI + 2 =1202H which basically corresponds to the next memory location and the data there is FF
SI
1200H
1200H
1202H
74
FFcomparing
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 7/13
Program Code
AX BX CX
74 0003H 0003H
Line 8 JNG -> Jump if not greater
this line simply see’s the result of the previous step and if the value stored in [SI + 2] is
not greater than the vaulue stored in AX then jump to LOOP1
In our example FF stands for 255 ok in decimal.. so we’re comparing FF with 74 and as we
can see FF is definitely greater than 74 so the jump does not take place
SI
1200H
1200H
1202H
74
FFcomparing
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 8/13
Program Code
AX BX CX
74 0003H 0003H
Line 9 and 10
This is very simple... XCHG is the instruction for Exchange basically it swaps the value of
the 2 operands given to it.
Ex:
Lets say AX has 27 and BX has 58
XCHG AX, BX
so this will put what ever value is there in BX to AX
and the value of AX to BX
So now AX will have 58 and BX will have 27
SI
1200H
1200H
1202H
74
FFcomparing
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 9/13
Program Code
AX BX CX
0003H 0003H
Line 9 and 10
So now in line 9 the value of AX is put in SI +2and the value of SI + 2 is in AX
As shown in below diagram
SI
1200H
1200H
1202H74
FF
74
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 10/13
Program Code
AX BX CX
0003H 0003H
Line 9 and 10
And in line 10 the value of AX and SI are exchanged so..
AX will have 74 now
and SI will have FF
SI
1200H
1200H
1202H
74
FF
74
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 11/13
Program Code
AX BX CX
0003H 0003H
Line 11
Now we go to line 11 where 0002H (hex for 2) is added to SI.. which means SI now
points to 1202H
SI
1202H
1200H
1202H
74
FF
74
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 12/13
Program Code
AX BX CX
0003H 0003H
Line 12 and 13
line 12 loop start.. this instruction decrements the value of CX and jumps to the program
location START
line 13 this instrution decrements BX
SI
1202H
1200H
1202H
74
FF
74
Sunday 9 October 2011
8/3/2019 Shorting Dec Ending
http://slidepdf.com/reader/full/shorting-dec-ending 13/13
Program Code
AX BX CX
0003H 0003H
Line 12 and 13
line 12 loop start.. this instruction decrements the value of CX and jumps to the program
location START
line 13 this instrution decrements BX
line 14 jump if not zero jnz to STOP
life 15 hlt
SI
1202H
1200H
1202H
74
FF
74
Sunday 9 October 2011