Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com Assembly Language Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com.

Similar presentations


Presentation on theme: "Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com Assembly Language Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com."— Presentation transcript:

1 Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com
Assembly Language Lecture 05-07 By SHERY KHAN

2 Agenda Direct Addressing Size Mismatch ERROR Indirect Addressing LOOPS
Register offset Addressing HOW MANY WAYS TO ACCESS MEM Segment Association ASSEMBLY LANGUAGE

3 Addressing Example ; a program to add three numbers using memory variables [org 0x0100] mov ax, [num1] ; load first number in ax mov bx, [num2] ; load second number in bx add ax, bx ; accumulate sum in ax mov bx, [num3] ; load third number in bx add ax, bx ; accumulate sum in ax mov [num4], ax ; store sum in num4 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5 num2: dw 10 num3: dw 15 num4: dw 0 Data if Given to Program ka sath constant cannot be placed in Destination/ & Changed Mov 5 ,ax is Incorrect DB DW 8 bit ,16 bit DB fit 1 byte DW 2 byte reserved Memory Defined 5,10,15 Every thing is Symbol but compiler/ assembler convert into num Adress Memory Location when Translated In ASL if we want to any particular loctaion to Reference it we attach a Symbol to it Readable Come HERE but Asm Covert it to Equivalent Adress 0100 sa start karo us na us ka baad byte Count kar liya when counting byte when reached to label it is Efective Location yeh label kitna offset pa waqi ha it is Adress of Label [] MEMORY OPERAND is num pa memory Access Karni Ha Illegal MEMORY TO MEMORY IS NOT ALLOWED Starting point sa hum next position la skta hain A1 offset is For MEMORY LOCATION B8 for Constant which Is =19 [] Memory Adresses

4 Size Mismatch ERROR: ; a program to add three numbers using byte variables [org 0x0100] mov al, [num1] ; load first number in al mov bl, [num1+1] ; load second number in bl add al, bl ; accumulate sum in al mov bl, [num1+2] ; load third number in bl add al, bl ; accumulate sum in al mov [num1+3], al ; store sum at num1+3 mov ax, 0x4c00 ; terminate program int 0x21 num1: db 5, 10, 15, 0 Source and Destination are same Byte AX------dw Al----db Mov Ax,bl illegal Size Nt Illegal 16 Bit MOVE mov ax,[num1] 8 bit Move mov al,[num1] Illegal mov ax,bl Illegal mov [num1] ,[num2] Tricky Illegal mov [num1],5 Ambigous ?? Mov byte [num1],5 or mov word [num1],5 Label is Memory Adress no Size is Attached size is Conveyed by us

5 Indirect Addressing: ; a program to add three numbers using indirect addressing [org 0x100] mov bx, num1 ; point bx to first number mov ax, [bx] ; load first number in ax add bx, 2 ; advance bx to second number add ax, [bx] ; add second number to ax add bx, 2 ; advance bx to third number add ax, [bx] ; add third number to ax add bx, 2 ; advance bx to result mov [bx], ax ; store sum at num1+6 mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 5, 10, 15, 0 Some Register Hold Data and Also Address from this Address we Access Data Immediate Direct Address Da do us Address jisa who utha la ga now the adress is fix so I cannot change I told that you can pick the content on compile time num1=0017 pa ha it is decided on compile time Now the way I can take the address and change it on run time Iapx88 4 register are used to access the Memory BX,BP,SI ,DI If [] are not used then the value of label itself which is address of label not the content The bx,si bp, di take the square brakets [bx] it mean that the content are accessed which are present in the BX HERE IN ABOVE bx will contain adresses 0117 [bx] mean that it contain content so content is Num1 which is 5 in memory Bx,2 we use word so 2 byte is added so it can point to the next word in memory …………………….. Bx=num1 Ax=[bx] Ax=num1=5 Bx=num1+2=second location Ax=ax+[bx] Ax=5+10=15 Bx=num1+4= third location Ax=15+15=30 …………………………………………the END Bx=num+6=4thlocation Ax=30+0=30

6 LOOP CONTROL [org 0x0100] mov bx, num1 ; point bx to first number
mov cx, 10 ; load count of numbers in cx mov ax, 0 ; initialize sum to zero l1: add ax, [bx] ; add number to ax add bx, 2 ; advance bx to next number sub cx, 1 ; numbers to be added reduced jnz l1 ; if numbers remain add next mov [total], ax ; write back sum in memory mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 Jump if NT Zero : Jump to the Location Li1 if the Zero flag is Not Set ZF: the Z flag is Set if the Last mathematical or logical has produced zero in its Destination Mov is nt mathematical or logical so zf is not set But ADD SUB is LOGICAL OR MATHEMATICAL AND OR XOR ETC if Zero in its destination then ZF is Set

7 Register + offset Addressing
a program to add ten numbers using register + offset addressing [org 0x0100] mov bx, 0 ; initialize array index to zero mov cx, 10 ; load count of numbers in cx mov ax, 0 ; initialize sum to zero l1: add ax, [num1+bx] ; add number to ax add bx, 2 ; advance bx to next index sub cx, 1 ; numbers to be added reduced jnz l1 ; if numbers remain add next mov [total], ax ; write back sum in memory mov ax, 0x4c00 ; terminate program int 0x21 num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50 total: dw 0 JNZ : Jump If the Zero flag is Not Set Cx=0 then zero flag is Set Bx is Increased by 2 and Cx is decreased by 1 according to the Command Conditional Jump is Decision maker in computer oFFSEt+ register= INDIRECT We use Bx,Bp which is Base register class When we use SI,DI INDEX FORMAT for Memory Access MIX MATCH (indirect +base) = Base +offset BX work like a Array Adress Function ka Sath adress ma 2 add karta gya INDEX CHANGED KARTA JAO aur Array ka jo base ha who constant raha & we can pick this from Index Lower BYTE on Lower Adress and Higher Byte In Higher Adress

8 How many ways we access Memory
Direct Mode: offset Addressing: Register Indirect: Register Indirect +offset Base +index Base+index+offset Mov ax,[num1] // Address is Fixed and on the Address the Content is Access Mov ax,[bx] //that Address is fit in Register & through this Register Memory is Access Mov ax,[bx+num1]: base +offset Mov ax,[si+Num1]: index+ offset Mov ax,[bx+si] the two adresses one in index and other in base. Both are added from the resultant adress we can pick the data Mov ax,[bx+si+num1]

9 Total Seven Adressing Modes
SEVEN WAYS TO ACCESS THE MEMORY OFFSET addressing Base Addressing INDEX Addressing Base +offset Index+offset Base+index Base+index+offset EFFECTIVE ADRESS: were our data is present

10 Segment Association Ip Associate by default CS(TIED)
SI,DI,BX By def DS BP with SS(TIED) Sp with SS(TIED) SEGMENT OVER RIDE Mov ax,[cs:bx] Every thing is in segment when we go in Data Window we Do DS: & Code window is CS: Segment are performing there function at there desire places every thing is Related to there Segment Every segment can calculate his her address Now we know about Effective Adresses generally if we use OFFSETS so as we tell you that No address is Complete until we can attach his Segment part. till no meaning Until we attach the segment part that in which segment the offset is . As Every Segment has its own Default Segment IP(instruction pointer) by Default Code Segment (CS) related or Associated & this Default segment cannot be separated and it cannot access any other segment IN data Case is different in direct addressing the OFFSET Form BY DEFAULT Access Data Segment (DS) we cannot Associate it as we can do .as we cannot do it standard goes to DS . And it see that DS relative that in this particular offset what is there SI,DI ,BX these Three REGISTER INDIRECT FORM by default DS Associated BP Cannot Associate By Default DS. It By Default SS Associated SP is also Tied with SS By Default: not Tied it can be used if we want Bx to Associate with ES then Segement overide is Done As Mov ax,[cs:bx] for this Instruction we say that bx is now Associated to Cs instead DS 2E num is called override Byte All the Segment value is Same so the offset from any segment the answer is Same COM File is Single Segment in which code ,data ,stack all are in it the standard in which all 4 segments are present on each other


Download ppt "Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com Assembly Language Lecture 05-07 By SHERY KHAN sherykhan186@gmail.com."

Similar presentations


Ads by Google