Beruflich Dokumente
Kultur Dokumente
8086 Programs
AX BX CX
SI
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
Program Code
0000H
0003H
0003H
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
Program Code
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
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)
74
0003H
0003H
1200H
AX BX CX
SI
Program Code
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
1200H 1202H
comparing
74 FF
74
0003H
0003H
1200H
AX BX CX
SI
Program Code
Line 8 JNG -> Jump if not greater this line simply sees 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 were comparing FF with 74 and as we can see FF is denitely greater than 74 so the jump does not take place
1200H 1202H
comparing
74 FF
74
0003H
0003H
1200H
AX BX CX
Sunday 9 October 2011
SI
Program Code
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
1200H 1202H
comparing
74 FF
74
0003H
0003H
1200H
AX BX CX
Sunday 9 October 2011
SI
Program Code
Line 9 and 10 So now in line 9 the value of AX is put in SI +2 and the value of SI + 2 is in AX As shown in below diagram
1200H 1202H
74 74
FF
0003H
0003H
1200H
AX BX CX
SI
Program Code
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
1200H 1202H
FF 74
74
0003H
0003H
1200H
AX BX CX
SI
Program Code
Line 11 Now we go to line 11 where 0002H (hex for 2) is added to SI.. which means SI now points to 1202H
1200H 1202H
FF 74
74
0003H
0003H
1202H
AX BX CX
SI
Program Code
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
1200H 1202H
FF 74
74
0003H
0003H
1202H
AX BX CX
SI
Program Code
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
1200H 1202H
FF 74
74
0003H
0003H
1202H
AX BX CX
SI