1 / 17

Program Logic and Control

Program Logic and Control. Mart 2006. Introduction. Instructions do not follow straight line Transfer control forward or backward Change IP content by special instructions Compare CMP, TEST Transfer CALL, JMP, Jnnn, LOOP, RET Logical AND, NOT, OR, XOR Shift and Rotate

zuzela
Download Presentation

Program Logic and Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Program Logic and Control Mart 2006

  2. Introduction • Instructions do not follow straight line • Transfer control forward or backward • Change IP content by special instructions • Compare • CMP, TEST • Transfer • CALL, JMP, Jnnn, LOOP, RET • Logical • AND, NOT, OR, XOR • Shift and Rotate • SAR/SHR, SAL/SHL, RCR/ROR, RCL/ROL

  3. Short, Near, Far • Three type of address that are disguished by their distance from the current address. Distance is between • Short: -128 and +128 (one byte) • Near: -32K and +32K (one or two word) • Far: distance is greater than +-32K (means pass another segment , use CALL)

  4. Transfer Control and Limits • JMP => short, near, far • Jnnn => short, near(+80386) • Loop => short • Call => (short), near, far Simple example JMP L10 …. L10: INC CX

  5. JMP • Commanly used • Uniconditional • Flushes prefetched intruction queue • Format: • [label:] JMP short/near/far address • short JMP => EB (1byte) + address (1byte) adds the address to IP, means it is an offset • near JMP => E9(1byte) + 2 byte(80286) or 4 Byte (+80386) • Far JMP=> we will pass now

  6. JMP • Forward JMP JMP L10; …. L10: … • Backward JMP L20: …. ….. JMP L20

  7. Sample Program .MODE SMALL .CODE ORG 100H A10MAIN PROC NEAR MOV AX, 00 MOV, BX, 00 MOV CX, 01 A20: ADD AX, 01 ; 3 byte ADD BX, AX ; 2 byte SHL CX,1 ; 2 byte JMP A20 ; 2 byte A10MAIN ENDP END A10MAIN AX = 1,2,3,4….. BX = 1,3,6,10…. CX = 1,2,4,8…. No end Backward jmp with – 9 offset Hex representation of -9 is FFF7 Jmp addres = IP + jmp operand = 0112h + FFF7h = 109h

  8. LOOP • Specified number of iteration • Initial value in CX • Automatic decrement in CX • If CX is non zero then go loop, else go next instruction • means short jmp • Format • [label:] LOOP short_address

  9. Same Sample with Loop .MODE SMALL .CODE ORG 100H A10MAIN PROC NEAR MOV AX, 00 MOV BX, 00 MOV DX, 01 MOV CX, 08 A20: INC AX ; 3 byte ADD BX, AX SHL DX,1 LOOP A20 MOV AX, 4C00H INT 21H A10MAIN ENDP END A10MAIN Two variant of LOOP LOOPE /LOOPZ (while CX is zero) LOOPNE/ LOOPNZ (while CX is not zero)

  10. The Flag Register C : unsigned arithmetic, shift-rotate, carry out of high order bit P : Odd parity after arithmetic operation A : skip until next chapter Z : result is zero or not S : sign of following arithmetic operation T : is single step mode or not I : Interrupt occured or not D : Direction of string processing (left to right or otherwise) O: signed arithmatic, carry out of high order sign bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Z C O D S A I T P

  11. CMP • Compares two numeric data field • Format • [label:] CMP r/m, r/m/i • Cmp of string bytes (use CMPS) • Result of CMP effects A, C,O,P, Z • Example CMP DX, 00 ; Behaves like SUB JE L10 …. L10:…..

  12. Conditional Jmp Instructions • JMP with condition • Format • [label:] Jnnn short-address • Example (equivalent of LOOP) DEC CX; JNZ A20 ; uses zero flag

  13. Signed / Unsigned Data • Signed for numeric values, unsigned for data values • CX = 11000110 and DX = 00010110 • if they are signed then CX is smaller • İf they are unsigned CX is greater • Use suitable Jnnn’s for signed and unsigned data CMP DX, CX CMP DX,CX JB A20; for unsigned JL A20; signed data

  14. Jump Based on UnSigned Data • JE/JZ = ZF • JNE/JNZ = ZF • JA/JNBE = CF,ZF • JAE/JNB = CF • JB/JNAE = CF • JBE/JNA = AF,CF

  15. Jump Based on Signed Data • JE/ JZ = ZF • JNE/JNZ = ZF • JG/JNLE = OF,SF,ZF • JGE/JNL = OF, SF • JL/JNGE = OF,SF • JLE / JNG = OF,SF,ZF

  16. Special Arithmetic Tests • JCXZ = none, cx is zero • JC = cf, carry on (same jb) • JNC = cf, carry off • JO = of, overflow on • JNO = of, overflow off • JP/JPE = pf, parity off or even parity • JNP/JPO= pf, parity off or odd parity • JS = sf, negative • JNS = sf, positive

More Related