Anda di halaman 1dari 4

Outline of the Lecture Control transfer instructions CALL statement Subroutines Data Types and Data Definition CONTROL

TROL TRANSFER INSTR CTIONS FAR and NEAR : (given CS:IP) In NEAR the control is transferred within the current code segment (intrasegment). IP is changed. In FAR the control is transferred outside the current code segment (intersegment). Both C and IP are changed. Conditional Jumps In the conditional !um"# control is transferred to a new location if a certain condition is met. $C (!um" if carr%) &CF is chec'ed(# $N) (!um" if not *ero) &)F is chec'ed(. !nemonic $A+$NBE $AE+$NB $B+$NAE $BE+$NA $C $E+$) $2+$N3E $2E+$N3 $3+$N2E $3E+$N2 $NC $NE+$N) $N5 $NP+$P5 $N $5 $P+$PE $ Condition Tested (CF,-) and ()F,-) CF,CF,1 (CF or )F),1 CF,1 )F,1 (( F 4or 5F) or )F) , (( F 4or 5F) , (( F 4or 5F) , 1 (( F 4or 5F) or )F) , 1 CF,)F,5F,PF,F,5F,1 PF,1 F,1 "#ump if $% a.o/e+not .elow nor e0ual a.o/e or e0ual+not .elow .elow+not a.o/e nor e0ual .elow or e0ual+not a.o/e carr% e0ual+*ero greater+not less nor e0ual greater or e0ual+not less less+not greater nor e0ual less or e0ual+not greater not carr% not e0ual+not *ero not o/erflow not "arit%+"arit% odd not sign o/erflow "arit%+"arit% e0ual sign

Note6 7a.o/e8 and 7.elow8 refer to the relationshi" of two unsigned /alues9 7greater8 and 7less8 refer to the relationshi" of two signed /alues. Short Jumps All conditional !um"s are short !um"s. In a short !um" the address of the target must .e within :1;< to =1;> .%tes of the memor% A conditional !um" is a two?.%te instruction6 one .%te is the o"code of the $ condition and the second /alue is a /alue .etween -- to FF. In a .ac'ward !um" the second .%te is the ;@s com"lement of the displacement /alue.

E46 A2AIN6

6 6 AAA A3#&BB( INC BB AEC CB $N) A2AIN H5I JH#A3


6

6 6 1-C>6---A -;-> 1-C>6---F DE 1-C>6--1- DF 1-C>6--11 >GFA 1-C>6&&'( A;-G--

6 6 AAA INC AEC $N) H5I

A3#&BB( BB CB ---A &---G(#A3

Khe instruction 7$N) A2AIN8 is assem.led as 7$N) ---A8 and the ---A is the address of the instruction with la.el A2AIN. (---A , --1E=FA , ---A) the carr% is dro""ed. Note that FA is ;@s com"lement of :C# meaning that the address of target is :C .%tes from the IP of the ne4t instruction. E46 ---G ---< ---A ---C ---E --1--1; <A D> -; EC C1 >; &) EC >A >> &* ;D AF << -D A2AIN6 H5I CHP $B CHP $A ANA H5I A3#&BB(=; A3#C1L NEBK A3#>AL NEBK A3#AFL & I(#A3

NEBK6

Khe dis"lacement /alue is added to the IP of the ne4t instruction to calculate the !um" address. (-C = ---C , --1;) (-; = --1- , --1;) Un onditional Jumps 7$HP la.el8 is the unconditional !um" in which control is transferred unconditionall% to the target la.el. Jnconditional !um" can ta'e the following forms. 1. L5RK $JHP# which is s"ecified .% the format 7$HP L5RK la.el8 . In this !um" the address of the target location is within :1;< to =1;> .%tes of the current IP. It wor's li'e the conditional !um". ;. NEAR $JHP# which is the default has the format 7$HP la.el8. It !um"s within the current code segment. It is e4actl% same as the short !um"# e4ce"t that the target address can .e an%where within the range of =E;>C> to :E;>C<. E. FAR $JHP# has the format 7$HP FAR PKR la.el8. Khis is the !um" out of the current code segment# meaning that not onl% the IP# .ut also the C is re"laced with new /alues. CALL STATE!ENTS Another control transfer instruction is the CA33 instruction# which is used to call a procedure Khe target address can .e in the current segment# hence a NEAR call (IP is changed C is not) Khe target address can .e outside the current segment# hence FAR call (IP and C are changed) Ko ma'e sure that after the e4ecution of the called su.routine the micro"rocessor 'nows where to come .ac'# the micro"rocessor automaticall% sa/es the address of the instruction following the call on the stac'. Khe last instruction of the called su.routine must .e REK (return) instruction# which directs CPJ to "o" the address of the ne4t instruction .efore the called su.routine to .e restored

S +RO TINES In Assem.l% 3anguage there can .e one main "rogram and man% su.routions called from the main "rogram. u.routines are organi*ed as "rocedures. PR5C can .e FAR or NEAR. If not mentioned# .% default a PR5C is NEAR hell of the Assem.l% 3anguage u.routines.
;------------------------------------------------------CODSEG SEGMENT MAIN PROC FAR ASSUME . MOV AX, MOV DA,AX CALL SUBR1 CALL SUBR2 CALL SUBR3 MOV AH,4CH INT 21H MAIN ENDP ;---------------------------------------------------SUBR1 PROC RET SUBR1 ENDP ;---------------------------------------------------SUBR2 PROC RET SUBR2 ENDP ;---------------------------------------------------SUBR3 PROC RET SUBR3 ENDP ;---------------------------------------------------CODSEG ENDS END MAIN

Alternati/el% the following format can .e used in implified Se,ment Definition6


;------------------------------------------------------.CODE MAIN: MOV AX,@DATA MOV DS, AX CALL SUBR1 CALL SUBR2 CALL SUBR3 MOV AH,4CH INT 21H ;---------------------------------------------------SUBR1: RET

;---------------------------------------------------SUBR2: RET ;---------------------------------------------------SUBR3: RET END MAIN

DATA T-.ES AND DATA DEFINITION M Assem.ler Aata Airecti/es OR/ 0Ori,in1 6 5R2 is used to indicate the .eginning of the offset address. Khe num.er after 5R2 can .e either in he4 or decimal. Hostl% used in Aata segment. E46
DTSEG DATA_IN SUM DTSEG SEGMENT DW 2 4DH,1DE!H, "C#H,$!!AH ORG 1%H DW & ENDS

D+ 0define byte1 6 AB allows allocation of memor% in .%tes for decimal# .inar%# he4 and A CII. E46
DATA1 D" 2$ ;DECIMA' D IS OPTIONA'

DATA2 DATA DATA4 DATA$ DATA!

D" D" ORG D" %RG D" ORG D"

1%%%1%%1" 12H %%1%H )2$*1+ %%1,H & %%2%H )M- ./01 23 451+

;"INAR( ;HEX ;ASCII NUM"ERS ;SET ASIDE A "(TE ;ASCII CHARACTERS

D . 0duplicate1 6 AJP is used to du"licate a gi/en num.er of characters. E46


E8: DATA1 DATA2 DATA DATA4 D" D" D" D" %FFH,%FFH,%FFH,%FFH ;FI'' 4 "(TES WITH FF 4 DUP6%FFH7 ;FI'' 4 "(TES WITH FF 2 DUP 6&7 $ DUP 62 DUP 6**77 ;SET ASIDE 2 "(TES ;FI'' 1% "(TES WITH **

D20define 3ord1 6 AN is used to allocate ; .%tes (one word) of memor% at a time. AJP is used to du"licate a gi/en num.er of characters. E46
DATA1 DATA2 DATA DATA4 DATA$ DW DW DW DW DW *$4 1%%1%1%1%1%%" 2$ FH *,2,#,%CH,%%1%%%%%9,$,+HI+ , DUP 6&7 ;DECIMA' ;"INAR( ;HEX ;MISCE''ANEOUS

E4 0e5uate1 6 EOJ is used to define a constant without occu"%ing a memor% location. E46
COUNT E:U MOV 2$ CX,COUNT

DD0define double3ord1 6 ame as AN .ut allocates ; words (D .%tes) of memor% at a time. E46
DATA1 DATA2 DATA DATA4 DD DD DD DD 1%2 1%%%111%%1%1%1%1%%" $C2A$#F2H 2 H,24#,*H,!$$ ;DECIMA' ;"INAR( ;HEX ;MISCE''ANEOUS

D40define 5uad3ord1 6 AO is used to allocate memor% < .%tes (D words) in si*e. E46
DATA1 DATA2 DATA D: D: D: 4$2 C2H )HE''O+ & ;HEX ASCII CHARACTERS ;NOTHING

DT0define ten bytes1 6 Allocates 1- .%tes of memor% s"ace. Hostl% used for BCA num.ers. E46
DATA1 DT ,!#*4 $!*,2* ; D1;/<=> 23 "CD .5> ?1@20/=

Anda mungkin juga menyukai