Home
Assembly Language Manual
Contents
1. 2 S N3 5 1N3H53S UTeW FE 29 394 41 Rire3tshud aq rrim 4t 05 SSETI 51 st 31 3244 os qusuwubas po3 45 13 HvdiesfigeatauM NHIX3 6 1192 fig a qessa22e 4 3 gt f pue 50 der3 q aapa 243 JUNO 777 awt st mon Bura43s ayy sandano 4aAaJ04 upuaboud styp saunparoud a npou 2 Sxurl u ma asme OB d S BI ST e IX Assembly Language Manual 92 10 7 6 HYO 2 xv HShd os Iv ACH BS VOCE 600 xv 5 6 06 PEASG xy val 96 a 00009008 vtoo prasad 1 sa 31 6500 HYO 7792 v 4 dunq puer doot SNI H 00009034 lt 00 4 qunos Wd Te O08183 doot2 xv 06 u 600019 3200
2. 55 6 Instruction Format cedd ecu were RR ww ERR DR saa 57 7 1 59 FLAG REGESESTS daaa a ah WU 59 Flag 60 Auxiliary Carry Flag 60 Carry Flag 60 Overflow Flag OF yc m on Ic o e 60 Parity Flag tetas AR y aa EIER RF Ru 60 Plaag BORDER 61 Zero 1 61 iv Assembly Language Manual 8 Macro Assemblers 63 63 Declarations s 63 Conditional ASSemDIY SRA 64 Repetitive 1 66 Interactive Assembly IN and 68 Comments a a 68 Match Operati ni a aasawa 69 Advanced 69 Bracket and EsCape EORR 71 MATCH Calling Patterns kuwa RUE E 72 Processing Macro 72 Expanded Unexpanded
3. Aq pasn 5 2 9 uotum s uawbas 2835 bE 3 paUrquo gt g Se 05 428365 30 55612 pue aueu Zuawhas 5 Bt sana eeg SE sajfiq 03 403 39Hu33314Mq2 re 0000 4901 quno2 9 doors ce 0000 0000 ce S A133341p SONS INSHD3S Te aq uoryeaer3 ap study 2 4409 ST 41 quaufas 244 UT gt st uotum pauadoaud 3 Sutsn Oapr 04 a4tum 3L1AB PIASQ NULX3 1434935 12 z Sser3 pue aweu sues yo quau as sz uytm paurquo3 aq TTIM uotum atqerae suaub s SONS 35005 uy 69464 yo 654264 3215 55 4 gt 008 ttl 24190402242 5 8 9 tZ02993902t96919 O2cs98S9r 02 J9 t 207 S903 d9c90237v402 3969090ct74749 9 0229291902244999 o269dqs6SsveZ0269569 Raued 41243 jo pte 243 auo2 04 4193 244 51 aa 6 264 pLOZELE90ELLAPAY 0000 81 3suoo 217809 GYOM 1434935 354035 91 3 12 pue aues jo quawhas aq ptm uorum gt
4. Burmo 03 6t 443 GC a3uB1a Bursstw By 1 4434 dON3 30Hd SIN3 1N3HD38 uado GN3 ON Zt O J43Y 688284 spaasxa arts Gy 04437 32384 per ueu4 sayqung 50HS Gp 0 4437 o3 dunf O 44ay 269 34n8Sv 3u0848434tp duni Eb 0 4437 86 3snu pueuedg 2g 0 4437 ddN3 20Md 49 BPTSIND O 4437 437195 0 4437 48351584 quawhas 0 30u few SE 0 4437 uor423n445ut 144 404 Spuesado yo sadhy 0 4437 s4 asr6 a aseq pue Kapur jo uotj3eurquo2 Z 0 4437 82u848484 paemaoj O3 BNP paAussau 2284 214311 SE 0 44237 8184 lt 7 1 you spueiadQ Gc 0 4437 49 QUOM JLAM snw 0 443y pueuado PITeAUT Z 0 2437 But4sau 1 349256 TE O 42437 548quau 30055 fuew of 0 2437 51N3493S fuew 62 0 443 Page 3 of 3 Error Message Module Program 11 1 Figure Assembly Language Manual 90 euo epueas 7 utag Le 9z SaNa 2845 ec 4a68nqsp asn 5019 4apunt
5. 86 86 86 5 86 86 Using a Printer with Assembly Listings 86 11 Sample Assembler 1 87 Appendix A Instruction A 1 Log CGNs 6665 86 06966 OF m EU OU UR OR OR RR A 1 Alternate A 4 Appendix B Reserved 4 B 1 Contents LIST OF FIGURES Figure Figure Figure Figure Figure Figure 1 1 1 2 2 1 11 11 11 WNE Analysis of Sample Instruction 6 Example of Complete Assembly Program 9 CALL RET C ntrol aon aqu RR URL asua aos sus iw 24 Error Message Module 88 Standalone Main 91 Convergent Compatible Main Program 92 LIST OF TABLES Table Table Table Table Table Table Table String Instruction 20 COnStanbtS scdhoge s EE sie aise UR RUND NUR NUR ITO 29 Target Label Addressability e ee 36 Effective Address Calculation Time A 3
6. dnoi95443 q2840 dn045443 AN3893S Z4gwsy Suraqss 25 4354 uras 244 am saqwaway y no3 42640 14 949 nea xe4248 19 2424 SIZ 64364 3339 tmoaaydogjaag sutg age sheJue artteued Z ay pue 34 84 y 61416 AN3H93S T43usV SaNa 89 Sample Assembler Modules SON3 Z 40443 99 0 443X 4ab qsut 8 At41s0d aq 3snu 4035284 69 teart spuesado Asowaw omy 99 9 4437 O q dow 10 Ce 0 1237 40 30u flew 29 uapptuua o0 aq 40u gg sasn s emI uot432nJ3suI 719 0 4437 419531 o4 646 ou4284 09 034437 uota3una 4131119 aurgapau o4 3842439 SG 0 4437 3 VS 380153886 0 4437 dasp 003 8 a Bur3sau 3uD153H 3A VS Z6 0 4437 HI9N3735Vd 40 HidIM39vd 96 0 4437 3007241 40 01584 GG 0 1137 TOQWHS 59201 bg T 443 HOLY 03 uja33ed prtieAu S T 4437 u2833ed TIED PIIeAU ZG T1 4437 1044002 paurjapun IG Qo 443 1043002 prie u 06 0 4437 123
7. abeiogs ayit Japao e3rsfiud paursap ut 396 o4 143 og casn oa am 142 1125 peaqeutwsag O 4234199 x8 S3 f 351 4 1 50 ur ue Bae pug 9 d8J Sa 84 39 uotse3o ur abessaw 04 sy mossedn Jau3sum Burgeotpur 5241035 Mosaydngo 348 34330043113S d 1155491 2434994411254 SIgnd auq uy 5 anes o3 heiua o ue ogur Burpeot 403 1923 115 AaTQwasse 243 10 a npou 40443 Assembly Language Manual 88 601235 10 7 T IT 11256 sd nOHS ueu ool ge 014437 385330 FOU 9yo 0 O 443X ur T qe e 460 04 qu un6av 92 04437 uorssaadxa ssauppe ue 40N GZ T 4437 10qufis ager dng 0 323 328 qo spoqwhs NHIX3 GOZ 40 A3IUTT EZ 0 443 1434935 aq 3snw group PYle u 2Z 004437 gt NVSN 328948 ur S2 SWNSSY ON I2 0 4437 1 sseg 5484419 sseg 10448 seu
8. dual aaa 5581 40443 3NC 954 xV any 48 0200 mwa 5 0000 6 9200 se 05 6200 394483314 92 van v8 u 00209008 1200 3 4 620 t sa 31 0200 El 5592 28 y 00269823 2100 IB 06 0 00 BsuuaBa xy van OB wu 00009008 4100 6542648 gir sa HShd 2 3 9100 xv BL 06 6100 ptAsq XvV v33 4 00009008 1100 prasad sa 5 92 0100 64 3254233144929 65442 6542644 prAsqd paooausgaa tum TYI 7 t4 xdona D ec 4a4ung3 azrrergrur 0 4 AOW u w 000000009022 w000 94 53423402 12451624 mau 4noqe ua quasse trait dnou6a sa 347859 69 Sa ADW 89 8000 SS ut st sr 9 asuts aq i5nu 2 35 230N 99 peor SS 3574 4236196 42835 oe3gurTm dnou6Q 135330 eS ADN y 0002238 5000 43Ua3U02 4aj810a4 Sas mau 3n0ge aus ITEL 3710464 55 awnssSy v9 xv 55 AH 9 0938 000 sa pue ss oiu dno46g peon xy AGN ev 88 0000 ulei 90 3404 aq rtm apo IV utew s gt 3S4nssv oF INZWO38 66 weaBoud st 45 SS papeci aq asnu pue saa4npaa2o d arnpou Ite 03 umouy ST u2tum dngs5g paweu
9. 73 Nested Macro 73 9 Accessing Standard Services from Assembly Code 75 Calling CODVOnLbtiOTnSiuzee ike 75 Register Usage 77 Segment and Group 78 Main 78 SS and DS When Calling Object Module Procedures 78 Interrupts and the 5 79 Use of 79 Virtual Code Segment Management and Assembly Code 81 System Programming 83 10 Assembly Control 85 85 UU RARIOR CR CR IRL 85 85 85 85 5 85 5 85 85 86
10. The complete table follows DEFINE p arg b arg EQS p arg EVAL p arg GES p arg GTS p arg IF p arg THEN b arg ELSE b arg ISDEF b arg LEN b arg LES p arg LTS p arg MATCH p arg b arg METACHAR p arg NES p arg OUT b arg REPEAT p arg b arg SUBSTR b arg p arg p arg WHILE p arg b arg where p arg denotes parameter like arguments and b arg denotes body like arguments Assembly control directives explained in section 10 begin with a after a RETURN If a control is encountered in expanded mode it is obeyed otherwise the control is simply treated as text A different character can be substituted for the built in metacharacter by calling the function METACHAR in the form SMETACHAR newmetacharacter The metacharacter should not be a left or right parenthesis an asterisk an alphanumeric character white space character 74 Assembly Language Manual 9 ACCESSING STANDARD SERVICES FROM ASSEMBLY CODE You can access all system services from modules written in assembly language To do so you must follow certain standard calling conventions register conventions and segment group conventions If in addition you wish to use the system s virtual code management services you must follow additional virtual code conventions Calling Conventions Here we explain how CTOS Operating System services and standard object module procedures a
11. See Appendix A for the flags set by each instruction Flags 59 Flag Usage Most arithmetic operations set or clear six flag registers Set means set to 1 and clear means clear to 0 Auxiliary Carry Flag AF If an operation results in a carry out of or a borrow into the low order four bits of the result AF is set otherwise it is cleared A program cannot test this flag directly it is used solely by the decimal adjust instructions Carry Flag CF If an operation results in a carry out of from addition or a borrow into from subtraction the high order bit of the result CF is set otherwise it is cleared This flag usually indicates whether an addition causes a carry into the next higher order digit or subtraction causes a borrow CF is not however affected by increment INC and decrement DEC instructions CF is set by an addition that causes a carry out of the high order bit of the destination and cleared by an addition that does not cause a carry CF is also affected by the logical AND OR and XOR instructions The contents of an operand are moved one or more positions to the left or right by the rotate and shift instructions The carry flag is treated as if it were an extra bit of the operand Only RCL and RCR preserve the original value in CF The value does not in these cases remain in CF The value is replaced with the next bit rotated out of the source If an RCL is used the value in CF is r
12. una 4223S paom HOG 2 dnd adha gt 42916 5 32695 2915 1N3H93S x23635 S N3 ueg oc po3 Jadaeq pug Br xdoo3 dun 1 4noqe 40g 440 sadaaq 9007 91 HddddO X2 AOW 79 ino I IX ET puo3as e 4noqe 404 4 4440 2 SOW TT TW ino HOt AOW 8007 amp 4adeaq ayy sdaaq uorum syy go a2e d ur aaay wedboad ang B8 turbag 9 S 159 34nssv v YOM 1434535 uten c weuboad urew 1 abed O8 d S 81 Gr SI 96 2383 33 3 333368 OSCE 2233169 593 OU 9000 2100 0100 aooo 8000 6000 1000 2000 0000 Z IX 48 quassy osse 91 Sample Assembler Modules go trqraeduoo qu Ba Auoo 6 11 SITANd 30u 42916 d eutquo2 ayy a30N 421849 3915 1N3HD3S 2235 tt 8 2 GO pue sadnad qur 404 2 smoTTe u3tum 69486 251 HOP paxty snId 19 143 UL saunpezou4d 40 qustItygns aq h uo aqau aseds aJ4em330s
13. not used SAR ROL ROR RCL RCR SHL SHR not used SAR not used XLAT ESC LOOPNZ LOOPZ LOOP JCXZ IN IN OUT OUT CALL JMP JMP JMP IN IN OUT OUT LOCK not used bEA CL bEA CL bEA CL bEA CL bEA CL bEA CL bEA CL wEA CL wEA CL wEA CL wEA CL AAM AAD TABLE EA bDISP bDISP bDISP bDISP AL bPort AX wPort bPort AL wPort AX wDISP wDISP wDISP wSEG bDISP AL DX AX DX DX AL DX AX Rotate bEA left CL bits Rotate bEA right CL bits Rotate bEA left through carry CL bits Rotate bEA right through carry CL bits Shift bEA left CL bits Shift bEA right CL bits Shift signed bEA right CL bits Rotate wEA left CL bits Rotate wEA right CL bits Rotate wEA left through carry CL bits Rotate wEA right through carry CL bits Shift wEA left CL bits Shift wEA right CL bits Shift signed wEA right CL bits ASCII adjust for multiply ASCII adjust for divide Translate using BX Escape to external device Loop CX times while not zero Loop CX times while zero Loop CX times Jump if CX 0 Input from bPort to AL Input from wPort to AX Output AL to bPort Output AX to wPort Direct near call Direct near jump Direct far jump Direct near jump Byte input from port DX to REG AL Word input from port DX to REG AX Byte output AL to port DX Word output AX to p
14. psDataRet DD sDataRet code to initialize fhl buffer and lfal Write fh pBuffer sBuffer lfa psDataRet You might instead want to invoke this macro with actual parameters on the stack Suppose that the quantities rbfhl rbsBuf rbpBuf rblfal and rbpsData are on the stack and that 80 Assembly Language Manual the top of stack pointer is in register BX Here is a sample invocation rbfhl EQU 6 rbsBuf EQU 8 rbpBuf EQU 10 rblfal EQU 14 rbpsDat EQU 18 Write BP rbfhl BP rbpBuf BP rbsBuf BP rblfal BP rbpsData Virtual Code Segment Management and Assembly Code The virtual code segment management services of the Convergent Information Processing System permit the programmer to configure a program written in any of the Convergent compiled languages in assembly language or in a mixture of these into overlays Although data cannot be overlaid with these services code can be overlaid Moreover the run time operations whereby code overlays are read into memory and discarded from memory are entirely automatic The programmer need only specify when linking the program which modules are to be overlaid and need make no change to the program apart from inserting at its start Single procedure call to initialize virtual code segment management services See the CTOS Operating System Manual for details The correct automatic operation of the virtual code facility requires certain assumptions about sta
15. 0 4 09 ONINVIW 3n1VA 3148 5 201124900 43 404 9320 483931 8 04 32 15 fec M MINN WYLS O 4 503151939 X3QNI 1 H x3 x8 XW 232415 30 801108 683151934 1 83819 1 3 935 3002 30 3SV8 mAn a 3 NI 581151938 3SV8 1N3W9IS SS X ePiei4 ISl dg 0 1 3 4 VilNIOd _ SS NOTLONULSNE ERE CL Assembly Language Manual 6 Source and destination operands cannot both be memory references A memory reference is direct when a data item is addressed with out the use of a register as in MUL prod DX prod is addressed toy 16 bit direct offset MOV CL jones bar Offset of jones plus bar is 16 bit direct offset A reference is indirect when a register is specified as in MUL prod BX DX Destination address is base register plus 16 bit displacement MOV BP SI Source address is sum of base register and index register See Figure 1 1 for an analysis of a sample instruction Procedures The Convergent assembly language formalizes the concept of a callable procedure by providing explicit directives to identify the beginning and end of a procedure Whereas other assembly languages start a procedure with a label and end it with a return instruction the Convergent assembly language defines a procedure as a block of code and data delim
16. O3 SP OS Beoua xa THS 31 24035 ADH 1048 paquem 60 1 2 42394 C9 d2 1d ADW 3 143 404 mojuedn q33a4 EX83mo41vdng4 Ba 49 AOW ui abessaw 10443 eujsqu asn T xeg24a xD AOW 40449 unurxeu 2 42 xg did 348 yg B dB 5 xa AOW 4944196 awess gas 44 sua qe2 dS dB AOW 30198 aunpasoug MVd 2044 2491044212594 SQ ut q3adxa of geym d qu ss ayy Tras dnoi5443 65 3unssv 4434935 4430s 43UsV gigusy sugwsy dnousuag dooa5443 Jo aseq 244 03 squrod 2 162 nayg eInpou sty ur Guru3baaaa ssauppyr SGN3 3148 713891 mo2awdng6a fq paraput selj motsedny yo eade quewBeg SuUOHN3 AYOM I1N3W93S E4gusy 5943 gu3usy 338v u Syeubu 34a hq paxapur aras 04 s30s440 104 SHOHNH3 DIANA GYOM INSWOAS S N3 saBessau 4 244 404 5 211804 GYOM 4434533 T4gwsy 0142 2594 40 244 10 quawBeg 3905 211404 AYOM 4434935 443usv sheasse TaTTeved omy fiq sBuzaqs tyase 49 dno45 paysed e q apo aunparzoud 43 30 54515000
17. WEA wEA AND wData Direct FAR call Direct NEAR call Indirect NEAR call Indirect FAR call AX Ext AL Clear carry flag Clear direction flag Clear interrupt flag Complement carry flag FLAGS AL CMP bData FLAGS AX CMP wData FLAGS bEA CMP bREG FLAGS wEA CMP wREG FLAGS bREG CMP bEA FLAGS wREG CMP wEA FLAGS bEA CMP bData FLAGS bEA CMP bData FLAGS wEA CMP wData FLAGS wEA CMP Ext bData Compare byte string Compare word string CS segment override DX Sign Decimal adjust for ADD Assembly Language Manual A7 2 99 27 Instruction Set in Alphabetic Order of Instruction Mnemonic 00001010 00001010 MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD 010 R M 010 R M 010 R M 010 R M REGR M REGR M REGR M REGR M REGR M REGR M REGR M REGR M 000 R M 000 R M 000 R M 000 REGR M REGR M REGR M REGR M 100 R M 100 R M 010 R M 011 R M REGR M REGR M REGR M REGR M 111 R M 111 R M 111 R M 111 R M 1 of 6 Flags ODITSZAPC U UUXUX 0 U XXUXU 83 U XXUXU 4 U UUXUX 4 x XXXXX 4 x XXXXX 17 x XXXXX 17 EA x XXXXX 17 EA x XXXXX 17 EA x XXXXX 16 EA 3 x XXXXX 16 EA 3 x XXXXX 9 3 x xxxxx 9 3 x xxxxx 4 X XXXXX 4 X XXXXX 16 EA 3 x XXXXX 16 EA 3 X xxxxx 9 3 x xxxxx 9 3 X xxxxx 17 x XXXXX
18. right thru carry D1 MOD 011 R M 15 EA x x 1 bit REP Same as REPZ REPE Same as REPZ REPNE Same as REPNZ REPNZ Repeat while CX 0 F2 AND ZF 0 2 REPZ Repeat while CX 0 F3 AND ZF 1 2 RET wData FAR return ADD CA data to REG SP 17 FAR return CB 18 RET NEAR return 8 wData NEAR return SP SP 2 wData 12 ROL bEA CL Rotate bEA left D2 MOD 000 R M 20 EA x x CL bits 4 bit ROL wEA CL Rotate wEA left 000 20 x x CL bits 4 bit ROL 1 Rotate bEA left 1 bit DO 000 15 x x ROL 1 Rotate wEA left 1 bit D1 000 15 x x ROR bEA CL Rotate bEA right D2 MOD 001 R M 20 EA x x CL bits 4 bit ROR wEA CL Rotate wEA right 001 20 EA x x CL bits 4 bit ROR 1 Rotate bEA right 1 bit DO 001 15 x x ROR wEA 1 Rotate wEA right 1 bit D1 001 15 EA x x SAHF FLAGS AH 9E 4 RRRRRRRRR SAL Same as SHL SAR bEA CL Shift signed bEA right D2 MOD 111 R M 20 EA x XXUXX CL bits 4 bit SAR wEA CL Shift signed wEA right 111 20 x XXUXX CL bits 4 bit SAR 1 Shift signed bEA right 1 bit DO 111 15 EA x XXUXX SAR wEA 1 Shift signed wEA right 1 bit D1 MOD 111 R M 15 EA x XXUXX 5 AL bData AL AL bData CF Jic 4 X XXXXX SBB AL wData AX AX wData CF 1D 4 X XXXXX SBB bEA bData bEA bEA bData CF 80 MOD 011 R M 17 x XXXXX SBB bEA bData b
19. Alternate A 4 Instruction Set in Numeric Order of Instr ction SERRE 5 Instruction set in Alphabetic Order of Instruction MDemODIiG ws x c 5885 A 12 vi Assembly Language Manual GUIDE TO TECHNICAL DOCUMENTATION This Manual is one of a series that documents the Convergent Family of Information Processing Systems The series includes Technical Summary Workstation Hardware Manual Peripherals Hardware Manual Central Processing Unit 5 Operating System Manual Executive Manual Editor Manual BASIC Manual FORTRAN Manual COBOL Manual Pascal Manual Assembly Language Manual Debugger Manual Utilities Manual Data Base Management System Manual 3270 Emulator Manual System Programmer s Guide Operator s Guide This section outlines the contents of these manuals The Technical Summary briefly describes the hardware and software of the Convergent Family of Information Processing Systems It summarizes the other manuals in one volume It can be helpful to read this overview before reading the other manuals The Workstation Hardware Manual describes the mainframe keyboard and video display It specifies system architecture printed circuit boards motherboard processor I O memory video Documentation Guide vi
20. Depending on the alignment and combine type of the segment see Section 2 on the SEGMENT directive the run time value here can be different from the assembly time value The OFFSET operator see Value Returning Operators in Section 4 can be used to compute this value TYPE for Data BYTE 1 byte WORD 2 bytes DWORD 4 bytes RECORD 1 or 2 bytes according to record definition STRUC n bytes according to structure definition DISTANCE for Code NEAR Reference only in same segment as definition definition with LABEL PROC or id FAR Reference in segment rather than definition defi nition with LABEL or PROC Data Definition 31 Variable Definition DB DW DD Directives To define variables and initialize memory or both use the DB DW and DD directives Memory is allocated and initialized by DD DW and DD in units of BYTES 8 bits WORDS 2 bytes and DWORDS doublewords 4 bytes respectively The attributes of the variable defined by DB DW or DD are as follows The SEGMENT attribute 15 the segment containing the definition The OFFSET attribute is the current offset within that segment The TYPE is BYTE 1 for DB WORD 2 for DW and DWORD 4 for DD The general form for DB DW and DD is either variable name DB DW DD exp variable name DB DW DD dup count PUP init where variable name is an identifier and either DB DW or DD must
21. Here are examples to illustrate the possibilities 64 Assembly Language Manual Evaluation Function Example of Example Description EVAL SEVAL 3 8 5 3h Evaluate expression LEN First 5h Length of string EQS SEQS OFFFFh String equality GTS SGTS y X OFFFFh String greater LTS SLTS y x Oh String less NES SNES AA AB OFFFFh String not equal GES SGES y y OFFFFh String greater or equal LES SLES z y Oh String less or equal SUBSTR SSUBSTR abcde 2 3 bed Substring Note that these functions evaluate to hexadecimal numbers and that the relational functions EQS etc evaluate to OFFFFh if the relation holds and Oh if it does not The parameter to EVAL must evaluate to a number The result of a numeric computation done during macro processing can be given a symbolic name with the SET function which is invoked in the form SET name value For example SSET xyz 7 5 sets the macro variable xyz to value OCh Subsequent to the use of SET xyz is equivalent to OCh Similarly the invocation SSET xyz xyz 1 decrements the value of the macro variable xyz The macro facility also supports conditional and repetitive assembly with the control functions IF REPEAT and WHILE IF has two versions SIF paraml THEN param2 ELSE param3 FI and SIF paraml THEN param2 FI The first parameter is treated as a truth value odd numbers are true and even numbers false If the first
22. NOT NOTHING NOXREF OFFSET OR ORG OUT PAGE PAGELENGTH PAGEWIDTH PAGING PARA POP POPF PROC PTR PUBLIC PURGE PUSH PUSHF RCL RCR RECORD REPE REPNE REPNZ REPZ RESTORE RET ROR SAL SAR SAVE SBB SCAS SCASB SCASW SEG SEGMENT SHL SHORT SHR SI SIZE SP ss STACK 5 5 5 5 05 STOSB STOSW SUB TEST THIS TITLE TYPE WAIT WIDTH WORD XCHG XLAT XLATB XOR SEG Reserved Words B 1
23. Programs and Segments 27 3 DATA DEFINITION Introduction The names of data items segments procedures and so on are called identifiers An identifier is a combination of letters digits and the special characters question mark 2 at sign and underscore _ An identifier may not begin with a digit Three basic kinds of data items are accepted by the assembler 1 Constants are names associated with pure numbers values with no attributes Here is an example Seven EQU 7 Seven represents the constant 7 While a value is defined for Seven no location intended use is indicated This constant can be assembled as a byte eight bits a word two bytes or a doubleword four bytes 2 Variables are identifiers for data items forming the operands of MOV ADD AND MUL and so on Variables are defined as residing at a certain OFFSET within a specific SEGMENT They are declared to reserve a fixed memory cell TYPE which is a byte a word a doubleword or the number of bytes specified in a structure definition Here is an example Prune DW 8 Declare Prune a WORD of initial value 0008H 3 Labels are identifiers for executable code forming the operands of CALL JMP and the conditional jumps They are defined as residing at a certain OFFSET within a specific SEGMENT The label can be declared to have a DISTANCE attribute of NEAR if it is referred to only from within the segment in which it is defined A label is us
24. SP DS and BP and if an overlay fault occurs during the return from a function preserves registers AX BX and ES where results may be returned Other registers are not in general preserved and therefore cannot be used to contain parameters or return results The stack segment must be named STACK and must be part of DGroup If a program is a mixture of assembly language code and compiled code and all code shares the same stack this happens automatically if a main program is written in assembly language it must be done explicitly See the example of an assembly language main program for details All procedures must be declared using the PROC and ENDP directives Procedure bodies may not overlap That is the pattern Outer PROC FAR Code of Outer Inner PROC FAR Code of Inner Inner ENDP code of Outer Outer ENDP is not permitted and must be replaced by the pattern Outer PROC FAR Code of Outer More code of Outer Outer ENDP Inner PROC FAR Code of Inner Inner ENDP Note that this is only a restriction on syntactic nesting there is no restriction on nested calls and Outer can in any case contain calls to Inner If all of these conventions are followed then when control enters an assembly language procedure the most recent entry on the stack is the return address In addition to preserving the value of BP as discussed above the procedure must push this value of BP onto the stack before it make
25. SP ss AX BP BX cs Cx DI DS DX EA ES SI SP ss bEA 1 1 Move word string Unsigned multiply by Unsigned multiply by Byte negate bEA Byte invert bEA Invert wEA AL AX bEA bEA OR WEA WEA OR WREG AL AX OR bData OR wData bEA bEA OR bData WEA wEA OR wData bEA WEA Carry Flag is C if destination is 0 Negate wEA Carry Flag is C if destination is 0 Same as XCHG AX AX bREG bREG OR bEA wREG wREG OR wEA Byte output AL port DX Word output AX port DX to to Output AL to bPort Output AX to wPort Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Push Push Push Push Push Push Push Push Push Push Push Push Push Push stack stack stack stack stack stack stack stack stack stack stack stack stack AX BP BX CS CX DI DS DX EA ES SI SP Ss FLAGS onto stack to to BX to BP to CX to DI to DS to DX to EA to ES to SI to SP to ss to FLAGS onto onto onto onto onto onto onto onto onto onto onto onto onto stack stack stack stack stack stack stack stack stack stack stack stack stack Rotate bEA left thru carry 1 bit Rotate wEA left thru carry 1 bit 4 5 F6 F7 F6 ET F6 F7 oc 0D 80 81 08 09 OA 0B EE EF E6 E7 58 5B 5D 59 SF 1F 5A 8F 07 5E 5 17 9D 50 55 5
26. addr expr is a variable label or number PTR sets or overrides the type of its operand without affecting the other attributes of the operand such as SEGMENT and Operands and Expressions 49 OFFSET Here are some examples of its use with data Suppose rgb and rgw are declared by rgb DB 100 DUP DW 100 DUP Then INC rgb SI INC rgw SI generate respectively byte increment and word increment instructions Types can be overridden with INC WORD PTR rgb SI word increment INC BYTE PTR rgw SI byte increment Sometimes no variable is named in an instruction the instruction uses an anonymous variable In such cases the PTR operator must always be used Thus INC WORD PTR BX word increment INC BYTE PTR BX byte increment INC BX INVALID because the operand BX is anonymous Segment Override The segment override operator is discussed in Section 2 It is denoted by the colon and takes these three forms seg reg addr expr segment name addr expr group name addr expr The SEGMENT attribute of a label variable or address expression is overridden by the segment override operator The other attri butes are unaffected The first two forms do a direct override the third recalculates the offset from the GROUP base SHORT The single argument of the SHORT operator is an offset that can be addressed through the CS segment register When the target code is within a l byt
27. but not a constant operand can be used in single operand operations Either 8 or 16 bit operands can be specified for almost all operations Immediate Operands An immediate value expression can be the source operand of two operand instructions except for multiply divide and the string operations Here are the formats label mnemonic memory reference expression and label mnemonic register expression Here label is an optional identifier mnemonic is any two operand mnemonic for example MOV ADD and XOR See Memory Operands below for the definition of memory reference In summary it has a direct 16 bit offset address and is indirect through BX or BP SI or DI or through BX or BP plus SI or DI all with an optional 8 or 16 bit displacement In the second format register is any general purpose not segment register For a definition of expression see the rest of this section See Table 3 1 Section 3 for rules on formation of constants The steps that the assembler follows in processing an instruction containing an immediate operand are Determine if the destination is of type BYTE or WORD Evaluate the expression with 17 bit arithmetic If the destination operand can accommodate the result encode the value of the expression using twos complement arith metic as an 8 or 16 bit field depending on the type BYTE Operands and Expressions 43 or WORD of the destination operand in th
28. o hardware reset o INT N o NEAR FAR o JUMP CALL Whatever the START CS SEGA IP 0OFFSET COMMENCE o CALL BX Assembly Language Manual 24 A recursive procedure is one which calls itself or one which calls another procedure which then calls the first and so forth Here are two points to note about recursive procedures 1 A recursive procedure must be reentrant This means that it must put local variables on the stack and refer to them with BP addressing modes 2 A recursive procedure must remove local variables from the stack before returning by appropriate manipulation of SP The number of calls that can be nested the nesting limit is delimited by the size of the stack segment Two words on the stack are taken up by FAR calls and one word by NEAR calls Of course parameters passed on the stack and any local variables stored on the stack take additional space Returning from a Procedure The RET instruction returns from a procedure It reloads IP from the stack if the procedure is NEAR it reloads both IP and SP from the stack if the procedure is FAR IRET is used to return from an interrupt handler and to restore flags A procedure can contain more than one RET or IRET instruction and the instruction does not necessarily come last in the procedure Location Counter and ORG Directive The assembly time counterpart of the instruction pointer is the location counter The value contained in the lo
29. so that the invocation DWDW 1 2 yields the expanded form Macro Assembler 71 DW 1 DW 2 The escape function is useful to bypass requirements for balanced text or to use special characters like or as regular characters The form is Sntext where n is a digit 0 to 9 and text is a string exactly n characters long For example you might define DEFINE Concat A B A B and invoke this macro by Concat DW 1 3 4 1 yielding the expansion DW 3 4 MATCH Calling Patterns Generalized calling patterns are applicable to MATCH just as they are to macro definition and invocation The general form is SMATCH identl macrodelimiter ident2 balancedtext For example if arg is initially 10 xyz 20 xyz 30 then SWHILE LEN arg GT O MATCH head xyz arg arg DW head expands to DW 10 DW 20 DW 30 Processing Macro Invocations In processing macro invocations the assembler expands inner invocations as they are encountered Thus in the invocation F G 1 72 Assembly Language Manual the argument to be passed to F is the result of expanding G 1 The expansion of inner invocations can be suppressed using the bracket and escape functions Thus with both of the invocations F G 1 5 1 it is the literal text G 1 not the expansion of that text that is the actual parameter of F Expanded and Unexpanded Modes 11 macro processor functions can b
30. 04 ADD AL bData AL AL bData 4 X 05 ADD AX wData AX AX wData 4 X 06 PUSH ES Push ES onto stack 10 07 ES Pop stack to ES 8 08 MOD REGR M OR bEA REG bEA bEA OR bREG 16 3 09 REGR M OR OR WREG 16 3 OA REGR M OR bREG bREG OR bEA 9 3 C OB MOD REGR M REG wEA wREG wREG OR WEA 9 3 C xxuxc oc OR AL bData AL AL OR bData 4 oD OR AX wData OR wData 4 0 PUSH cs Push CS onto stack 11 OF not used 10 MOD REGR M ADC EA REG bEA bEA bREG CF 16 EA 3 X 11 MOD REGR M ADC EA REG wEA wEA wREG CF 16 EA 3 xxxxx 12 MOD REGR M REG EA bREG bREG bEA CF 9 3 X xxxxx 13 MOD REGR M REG EA WREG wREG wEA CF 9 3 X xxxxx 14 ADC AL bData AL AL bData CF 4 X 15 ADC AX wData AX AX wData CF 4 x XXXXX 16 PUSH ss Push SS onto stack 11 x XXXXX 17 POP ss Pop stack to SS 8 18 MOD REGR M SBB bEA REG bEA bEA bREG CF 16 EA 3 xxxxx 19 MOD REGR M SBB wEA REG wEA wEA wREG CF 16 3 1 REGR M SBB REG bEA bREG bREG bEA CF 9 3 X 1B REGR M SBB REG wEA wREG wREG wEA CF 9 EA 3 X 1C SBB AL bData AL AL bData CF 4 x XXXXX 1D SBB
31. 38r 1H dW2 0 TUE gav H30 any KV XE AOW 5 eS AOW HSNd 2652 uv aN 48qunu 448Au02 04 aunparou xdoo4 dir 19443 ANT agga tum 1192 uteg 120243 711799 uo asap x Hiurag d 12207 II saoa4a djaul 9v1 Sti rr evi Tel Ort BET LET 9 SET EET cet oft ect Bet set EET eat ter oet 811 91T SITI bit TT OTT 101 90 0000v6 os ovez 0000v6 c oc 00009008 405508 5096 658308 055508 306308 bord 16 007068 343 0264 OES 7 0000v6 8500 too 4 00 271 481Quassy Assembly Language Manual 94 Appendix A INSTRUCTION SET Table A 3 lists the instruction set in numeric order of instruction code Table A 4 lists the instruction set in alphabetical order of instruction mnemonic This instruction set is described in detail in the Central Processing Unit Legend Each table contains seven columns The column labeled Op Cd is the operand code Memory Organization is explained in Section 6 The Instruction column is the instruction mnemonic The Opera
32. 4 4 OU adam d ul 9c S N3 5 vt 121404223 3394s GYR yo saqhq dod 009092 o200 A4 qurtod 10710 1046 47 903 oc 06 3100 OFUT sodua ands LLLL xV AON 40445 ec 311588 2100 428 5 3464 244 dod 9 138 Ba 069095 2100 4234104 aueu4 44 aucqgsaus da dOd Le as 40448 ACW 92 COOCBA 6100 FINSa4 814048 53 AOW 406698 Z100 41681 91045 dn yas rdqi d Mld s31 ve S036 3 3000 auop uau4 30071 eus YGmouyg STIEJ IO43U02 31 pue ur 4033283 geaday 9007 ez 9423 0000 MOTF4SAO Y1xa dodga 40443 200 4 8000 4033834 4xa8u q itdrarxnur xo INW 3 oz 1343 6000 u 5496 Cuqt da x 61 vOStBB 5000 ganpoud pow AON 81 O01088 E000 804 2 46 qu aqana 4utod dS dd AOW 41 2388 1000 9 aweug HSNd FI SS 0000 uruqt1m 4 4 JO 335330 A1381343 9 nea dqa 9000 WEL UTYZIM U 30 4964340 Nos uqa tl vooo uva ET 6 a awos gt eee 40448 Ou O p auanqsaaq 504646 10448 go puom e sr 1045 aq st
33. 42npO4d e 94 32314 p A qurod e st 3241214942244 e Buryua saadadq puom e stu 3dhi543 38H et1402326 4d 4423328 1214103224 6354224 5 3unSSv 211804 1N34938 6254224 181403263 31111 n 0n0oc OB 3d s BI 00 91 auranoaqnS IX quagssaauoy 9 Introduction You need to know how to fill in a form This is described in Filling in a Form in the Executive Manual Field Descriptions Source files Fill in the Source files field with a list of the names of the source files to be assembled It is the only required field If several files are specified the result is logically like assembling the single file that is the concat enation of all the source files In a list of names of source files separate each name by a space Do not use commas As an example suppose the program is contained in Main Asm and depends on a set of assembly time parameters You might maintain two source fragments to define the parameters one for debugging and one for production Then Source files would be either ParamsDegbugging Asm Main Asm or ParamsProduction Asm Main Asm Errors only Fill in the Errors only field with Yes if you want a listing only of lines with errors The listing normally contai
34. AL bPort Input from bPort to AL E4 10 IN AX DX Word input from port DX to REG AX ED 8 IN AX wPort Input from wPort to AX E5 10 INC AX AX AX 1 40 2 INC BP BP BP 1 45 2 INC BX BX BX 1 43 2 INC cx CX CX 1 41 2 INC DI DI DI 1 47 2 INC Dx DX DX 1 42 2 INC bEA bEA bEA 1 FE 000 R M 15 INC wEA 1 000 R M 15 INC sP SP SP 1 44 2 INC SI SI SI 1 46 2 INT bData Typed interrupt cD 51 INT 3 Type 3 interrupt cc 52 INTO Interrupt if overflow CE 53 or 4 Simple execution of the instruction takes 4 clocks and actual interrupt IRET Return from interrupt CF 24 JA bDISP Jump if above 77 16 or 4 JAE bDISP Jump if above or equal 73 16 or 4 JB bDISP Jump if below 72 16 or 4 JBE bDISP Jump if below or equal 76 16 or 4 JC Same as JB JNAE JCXZ bDISP Jump if 0 E3 18 or 6 JE Same as JZ JG bDISP Jump if greater 7F 16 or 4 JGE bDISP Jump if greater or equal 7D 16 or 4 JL bDISP Jump if less 7C 16 or 4 JLE bDISP Jump if less or equal 7E 16 or 4 JMP bDISP Direct NEAR jump EB JMP wDISP Direct NEAR jump E9 7 JMP wDISP EA wSEG Direct FAR jump 7 JMP EA Indirect FAR jump FF MOD 101 R M 16 EA JMP EA Indirect NEAR jump FF MOD 100 R M 7 Fi ODIT U C C gt gt lt gt lt gt lt MK gt lt gt lt gt lt xx c 5X gt lt OS gt lt gt DK gt X gt lt gt lt cc cc cc EE SZAPC XXXXX XXXX XXXX XXXX XXXX XXXX XXXX X
35. AL wData AX AX wData CF 4 X XXXXX 1E PUSH DS Push DS onto stack 10 1F POP DS Pop stack to DS 8 20 MOD REGR M AND bEA REG bEA bEA AND bREG 16 3 21 MOD REGR M AND wEA REG wEA wEA AND wREG 16 3 22 REGR M AND bREG bREG AND bEA 9 3 xxuxc 23 MOD REGR M AND REG wEA wREG wREG AND wEA 9 3 C xxuxc 24 AND AL bData AL AL AND bData 4 XXUXC 25 AND AX wData AX AX AND wData 4 XXUXC 26 ES ES segment override 2 27 DAA Decimal adjust for ADD 4 x XXXXX 28 MOD REGR M SUB bEA REG bEA bEA bREG 16 3 29 REGR M SUB 16 3 2 REGR M SUB REG bEA bREG bREG bEA 9 3 x xxxxx 2B MOD REGR M SUB REG wEA wREG wREG wEA 9 EA 3 x xxxxx 2c SUB AL bData AL AL bData 4 X 2D SUB AX wData AX AX wData 4 X 2E CS CS segment override 2 2F DAS Decimal adjust for subtract 4 U XXXXX 30 MOD REGR M XOR bEA REG bEA bEA XOR bREG 16 3 31 REGR M XOR wEA REG wEA wEA XOR wREG 16 3 32 REGR M XOR REG bEA bREG bREG bEA 9 3 C xxuxc 33 MOD REGR M XOR REG wEA wREG wREG XOR wEA 9 3 C xxuxc 34 XOR AL bData AL AL XOR bData 4 XXUXC 35 XOR AX wData wD
36. AX wAddr bAddr AL wAddr AX AL bData AX bData AL bData CL bData DL bData BL bData AH bData CH bData DH bData BH bData AX wData CX wData DX wData BX wData SP wData Instruction Set in Numeric Order of Instruction Code NOP Exchange AX CX Exchange AX DX Exchange AX BX Exchange AX SP Exchange AX BP Exchange AX SI Exchange AX DI AX Ext AL DX 2Sign AX Direct FAR call Wait for TEST signal Push FLAGS onto stack Pop stack to FLAGS FLAGS AH AH FLAGS AL bAddr AX wAddr bAddr AL wAddr AX Move byte string Move word string Compare byte string Compare word string FLAGS AL TEST bData FLAGS AX TEST wData Store byte string Store word string Load byte string Load word string Scan byte string Scan word string AL bData CL bData DL bData BL bData AH bData CH bData DH bData BH bData AX wData CX wData DX wData BX wData SP wData Page 4 of 7 Flags ODITSZAPC 8 RRRRRRRRR 4 RRRRRRRRR 10 10 10 10 18 9 17 rep 18 9 17 rep 22 Ix 9 22 22 Ix 9 22 4 x 4 x TE 9 10 rep 11 9 10 12 9 13 rep 12 9 13 rep 15 Ix 9 15 rep 15 Ix 9 15 4 gt gt P gt P gt P P P P P gt XXXXX XXXXX XXUXC XXUXC XXXXX XXXXX Table A 3 MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD
37. MOD MOD MOD MOD MOD MOD MOD Instruction Set in Numeric Order of Instruction Code REGR M REGR M 000 001 010 011 100 101 110 111 000 001 010 011 100 101 110 111 R M R M R M R M R M R M R M R M R M R M R M R M R M R M R M R M Simple execution CF D1 D1 D1 D1 D1 D1 D1 D1 MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD 000 001 010 011 100 101 110 111 000 001 010 011 100 101 110 111 R M R M R M R M R M R M R M R M R M R M R M R M R M R M R M R M RET RET INT INT INTO of the instruction takes 4 clocks IRET ROL ROR RCL RCR Sur SHR not SAR ROL ROR RCL RCR SHL SHR not SAR BP wData SI wData DI wData used used wData REG EA REG EA bEA bData used used used used used used used EA wData used used used used used used used used used wData 3 bData bEA 1 bEA 1 bEA 1 1 bEA 1 bEA 1 used bEA 1 1 1 1 1 1 1 used 1 Page 5 BP wData SI wData 4 DI wData 4 NEAR return SP SP wData 12 NEAR return 8 ES REG wEA 2 16 EA DS REG wEA 2 WEA 16 EA bEA bData 10 WEA wData 10 return ADD data to REG SP 17 FAR return 18 Type 3 interrupt 5
38. STI CLD STD INC DEC not not not not not not INC DEC CALL CALL JMP JMP PUSH not bEA bData used bEA bEA if destination bEA bEA bEA bEA wEA wData used wEA wEA if destination wEA wEA wEA wEA bEA bEA used used used used used used wEA wEA used Repeat while CX 0 AND ZF 0 Repeat while CX 0 AND ZF 1 Halt Complement carry flag FLAGS bEA TEST bData Byte invert bEA Byte negate bEA is 0 Unsigned multiply by bEA Signed multiply by bEA Unsigned divide by bEA Signed divide by bEA FLAGS wEA TEST wData Invert wEA Negate wEA is 0 Unsigned multiply by wEA Signed multiply by wEA Unsigned divide by wEA Signed divide by wEA Clear carry flag Set carry flag Clear interrupt flag Set interrupt flag Clear direction flag Set direction flag 1 bEA bEA 1 wEA wEA 1 1 Indirect NEAR call Indirect FAR call Indirect NEAR jump Indirect FAR jump Push EA onto stack HPNNN O EA 16 EA 16 EA 71 90 90 112 10 EA 16 EA 16 EA 124 144 155 177 NN N DN 15 EA 15 EA 15 EA 15 EA 13 EA 29 7 16 16 7 of 7 Flags ODITSZAPC x XXUXC x XXXXS X UUUUX X UUUUX U UUUUU U UUUUU XXUXC x XXXXS X UUUUX X UUUUX U UUUUU U UUUUU 5 x XXXX x XXXX x XXXX x XXXX A 11 Instruction Set Table A 3 Instruc tion AAD
39. The format is symbol EQU expression Here expression can be any assembly language item or expres sion An example is xyz EQU 7 30 Assembly Language Manual Attributes of Data Items The distinguishing characteristics of variables and labels are called attributes These attributes influence the particular machine instructions generated by the assembler Attributes tell where the variable or label is defined Because of the nature of the processor it is necessary to know both in which SEGMENT a variable or label is defined and the OFFSET within that segment of the variable or label Attributes also specify how the variable or label is used The TYPE attribute declares the size in bytes of a variable The DISTANCE attribute declares whether a label can be referred to under a different ASSUMEd CS than that of the definition Here is a summary of the attributes of data items SEGMENT SEGMENT is the segment base address defining the variable or label To ensure that variable and labels are addressable at run time the assembler correlates ASSUME CS DS ES and SS and segment prefix information with variable and label references The SEG operator see Value Returning Opera tors in Section 4 can be applied to a data item to compute the corresponding segment base address OFFSET OFFSET is the 16 bit byte displacement of a variable or labels from the number of bytes from the base of the contain ing segment
40. The instructions that must be executed differ slightly according to whether a parameter is in a register a static variable an immediate constant a word or a doubleword If you are programming a particular assembly module in which not all of this variability occurs it may be simplest Accessing Standard Services 79 to program the required calling sequences just once to include them in your program as macro definitions and to invoke them using the assembler s macro expansion capability For example the procedural interface to the Write operation is given in the CTOS Operating System Manual as Write fh pBuffer sBuffer lfa psDataRet ErcType where fh and sBuffer are 2 byte quantities and pBuffer lfa and psDataRet are 4 byte quantities The corresponding external declaration and macro definition would be EXTRN Write FAR DEFINE Write fh pBuffer sBuffer lfa psDataRet PUSH fh PUSH WORD PTR pBuffer 2 PUSH WORD PTR pBuffer 0 PUSH sBuffer PUSH WORD PTR 1fa 2 PUSH WORD PTR lfa 0 PUSH WORD PTR psDataRet 2 PUSH WORD PTR psDataRet 0 CALL Write Note that the 4 byte quantities are treated slightly differently from the 2 byte quantities requiring first a PUSH of the high order word then a PUSH of the low order word Here is an example of the use of this macro with static actual parameters fhl DW EVEN buffer DB 512 DUP sBuf DW SIZE buffer pBuf DD buffer lfal DD sDataRet DW
41. an expansion contains an error it is listed GENONLY Only the final results of macro expansion and not intermediate expansions or calls are listed This is the default mode INCLUDE file Subsequent source lines are read from the specified file until the end of the file is reached At the end of the included file Source input resumes in the original file just after the INCLUDE control line LIST Subsequent source lines appear in the listing NOLIST Subsequent source lines do not appear in the listing PAGELENGTH n Pages of the listing are formatted n lines long Assembly Control Directives 85 PAGEWIDTH n Lines of the listing are formatted a maximum of n characters wide PAGING The listing is separated into numbered pages This is the default NOPAGING The listing is continuous with no page breaks inserted SAVE The setting of the LIST NOLIST flag and the GEN NOGEN GENONLY flag is stacked up to a maximum nesting of 8 RESTORE The last SAVEd flags are restored TITLE text The text is printed as a heading on subsequent listing pages The default title is the null string The text must have balanced parentheses See Section 8 for details Using a Printer with Assembly Listings The listing produced by the assembler is paginated with titles and page numbers Since the entire page image is formatted in such a listing it should be printed by APPENDing or COPYing to Lpt rather than with the E
42. and CF are set by a result that has a carry and a zero Here is an example 00110101 11001011 00000000 Carry Flag 1 Zero Flag 1 Flags 61 8 MACRO ASSEMBLER Introduction The assembler supports the definition and invocation of macros expressions possibly taking parameters that are evaluated during assembly to produce text The text that results is then processed by the assembler as source code just as if it had been literally present in the input to the assembler For example consider the program fragment DEFINE Call2 subr argl arg2 PUSH argl PUSH arg2 CALL subr Call2 Input pl p2 This fragment defines a macro Call2 of three arguments and then invokes it The invocation is to the expanded form PUSH pl PUSH p2 CALL Input The character is called the metacharacter and is used to activate all macro processing facilities macro invocations are preceded by g and macro definitions by metacharacter changed how to do this is described later in this Section The simplest kind of macro definition takes the form DEFINE MacroName ParameterList Body where MacroName is an identifier ParameterList is a list of parameter names enclosed in parentheses and Body is the text of the macro When parameter names appear in the Body they are preceded by the character A simple macro invocation takes the form MacroName ArgList This expands to th
43. aoa DR Jp 43 Register hos 44 Explicit Register 44 Implicit Register 45 Segment 46 General REG sSt6rse 46 46 Memory 46 Memory Operands to JMP 46 ADU R E 48 SIMPLE 1 425 5 66 48 6 46 6 4 4 646 48 Indexed 1 wasu a ban ra sss 48 Double Indexed 1 1 48 Attribute cera aise 49 PTR the Type Overriding 49 Segment Override i 2 ash aa 50 50 5 51 Value Returning 51 Record 53 Operator Precedence Expressions 53 54 PURGE Directive es ao 54 5 Forward
44. be written with a more complex single index expression For example these two forms are completely equivalent Var Displ Disp2 and 48 Assembly Language Manual Var Displ Disp2 The displacements can be constants or expressions that evaluate to constants base or index registers BX BP SI or DI or base or index registers plus or minus a constant offset The only restriction is that BX and BP can not both appear and SI and DI cannot both appear in the same double indexed variable These three expressions are all invalid Primes Primes SI 2 BX Primes BX BP Indexing can be used in combination with structures Recall the example given earlier RqCloseFile STRUC sCntInfo DW 2 nReqPbCb DB 0 nRespPbCb DB 0 userNum DW exchResp DW ercRet DW rqCode DW 10 fh DW 7 RqCloseFile ENDS All of the following are valid MOV RqCloseFile sCntInfo AX MOV BX userNum AX MOV BP SI 4 fh Attribute Operators In addition to indexing structure arithmetic and logical oper ators operands can contain a class of operators called attribute operators Attribute operators are used to override an operand s attributes to compute the values of operand attributes and to extract record fields PTR the Type Overriding Operator PTR is an infix operator That is it has two operands and is written between them in this format type PTR addr expr type is BYTE WORD DWORD NEAR FAR or structure name
45. does not alter segment ordering to make this happen An example is DGroup GROUP dSeg sSeg An associated ASSUME directive that might be used with this group is ASSUME CS codel DS DGroup SS DGroup You can not use forward references to GROUPS A single segment register can be used to address all the segments in a group This should be done carefully however because offsets in instructions and data are relative to the base of the group and not a particular segment Procedures PROC ENDP Directives Procedures can be implemented using the PROC and ENDP direc tives Although procedures can be executed by in line fall through of control or jumped to the standard and most useful method of invocation is the CALL Here is the format of the PROC ENDP directives 22 Assembly Language Manual name PROC NEAR FAR name ENDP name is specified as type NEAR or FAR and defaults to NEAR If the procedure is to be called by instructions assembled under the same ASSUME CS value then the procedure should be NEAR A RET return instruction in a NEAR procedure pops a single word of offset from the stack returning to a location in the same segment If the procedure is to be called by instructions assembled under another ASSUME CS value then the procedure should be FAR A RET in a FAR procedure pops two words new segment base as well as offset and thus can return to a different segment Calling a Procedure The CALL instr
46. formats such 4 byte quantities are dealt with exactly as 4 byte pointers when they are parameters the high order part is pushed first and the low order part second when they are results the high order part is returned in ES and the low order part is returned in There is one additional case not illustrated by the example of ReadBsRecord When a parameter is a single byte such as a boolean flag two bytes on the stack are actually required although the high order byte of these two bytes is not used Thus the instruction PUSH BYTE PTR BX adds two bytes to the stack One of these bytes is specified by the operand of the PUSH instruction the other is not set and no reference should be made to it Similarly when the result of a function is a single byte that byte is returned in AL and no reference should be made to the contents of AH Register Usage Conventions When writing in assembly language a call to a standard object module procedure or to the Operating System be aware of the Convergent standard register conventions The contents of CS DS SS SP and BP are preserved across calls they are the same on the return as they were just prior to the pushing of the first argument It is assumed that SS and SP point respectively to the base of the stack and the top of the stack and this stack will in general be used by the called service Do not put temporary variables in the stack area below SS SP see Interrupts and
47. is by standard twos complement arithmetic The addition subtraction operations serve as both signed and unsigned operations the two possibilities are distinguished by the flag settings Arithmetic may be performed directly on unpacked decimal digits or on packed decimal representations Some operations indicate these results only by setting flags For example the processor implements compare as a special subtract which does not change either operand but does set flags to indicate a zero positive or negative result By using one of the conditional jump instructions a program can test the setting of five of the flags carry sign zero overflow and parity The flow of program execution can be altered based on the outcome of a previous operation One more flag the auxiliary carry flag is used by the ASCII and decimal adjust instructions It is important to understand which instructions set which flags Suppose you wish to load a value into AX and then test whether the value is 0 The MOV instruction does not set ZF so the following does not work MOV AX wData JZ Zero Instead since ADD does set ZF the following does work MOV AX wData ADD 0 JZ Zero A flag can be set but not tested over the duration of several instructions In such cases the intervening instructions must be carefully checked to ascertain that they do not affect the flag in question This is generally a dangerous programming practice
48. parameter is true the IF expression is equivalent to the value of its second parameter if the first parameter is false the IF expression is equivalent to the value of its third parameter or to the null string if the third parameter is omitted For example Macro Assembler 65 SIF 1 THEN aa ELSE bb FI is equivalent to aa and IF 2 THEN aa FI is equivalent to the null string The IF function can be used in conjunction with macro variables to provide conditional assembly Suppose a program contains a table that is to be searched for a value at run time If the table is small a simple linear search is best if the table is large a binary search is preferable Then you could code SIF sTable GT 10 THEN binary search version here else 11 search here The macro variable sTable would have to be defined with some numeric value otherwise the expansion of the IF would yield an error Sometimes it is convenient to control a conditional assembly by whether or not a symbol has been defined in the usual case the symbol is not defined and one alternative is selected but if a definition for the symbol is found a different alternative is selected The macro processor supports this capability with the ISDEF function ISDEF may use two forms one tests whether a run time symbol for example a label has been defined and the other tests whether a macro time symbol has been defined In both cases the res
49. record definition to be used is specified by record name Finally the operand is a possibly empty list of initial field values For example lt gt Use field default values from the record definition lt 8 10 gt Set initial values of the first and third fields to 8 and 10 respectively but use the default from the definition for the middle field The initial field values can be constants constant expressions or the indeterminate initialization If the expression eval uates to a number not expressible in binary within the width of the corresponding record field then the number is truncated on the left For example 11001 binary in a 2 bit field is trun cated to 01 With Format 2 multiple instances of the record can be allocated at once The number of copies of the record to be allocated is given by dup count Note that in this format the angle brackets must be enclosed within parentheses as shown You can use a record as part or all of an expression as in MOV AX Inst2B lt OP D W MOD REG RM gt Structures Just as records are used to format bit aligned data at the byte or word level structures are used to define byte aligned fields within multibyte data structures Structures can be used to group together logically related data items For example suppose you give the name Car to a structure You use this structure to define individual fields of size in bytes 1 2 2 and 4 symbolically The assembler generate
50. the assembler assigns the name SEG The SEGMENT directive also controls the alignment combination and contiguity of seg ments Its format is segname SEGMENT align type combine type classname segname ENDS The optional fields must be in the order given The segment is located on a memory boundary specified by align type as follows 1 PARA the default the segment begins on paragraph boundary an address with the least significant hexadecimal digit of 0 2 BYTE the segment can begin anywhere 3 WORD the segment begins on a word boundary i e an even address 4 PAGE the segment begins an address divisible by 256 Segments can be combined with other segments by the Linker as Specified by combine type Segment combination permits segment elements from different assemblies to be overlaid or concatenated by the Linker Such segment elements must have the same segname classname and an appropriate combine type as follows 1 Not combinable the default 2 PUBLIC when linked this segment is concatenated made adja cent to others of the same name The Linker controls the order of concatenation during linkage according to your Specifications 3 expression the segment is located at the 16 bit segment base address evaluated from the given expression The expression argument is interpreted as a paragraph number For example if you wish the segment to begin at paragraph 322
51. to right are stored in ascending memory locations For example is stored as 41h 42h 43h Strings must be enclosed in single quotes A single quote is included in a string as two consecutive single quotes Here are some examples Single Quote DB I m so happy Date DB 08 08 80 Quote DB TEM Jabberwocky DB BRILLIG AND THE SLITHY TOVES Run Header DW GW Enumerated Initialization variable name DB DW DD init Bytes words or doublewords are initialized in consecutive memory locations by this directive An unlimited number of items can be specified Here are some examples Squares DW 0 1 4 9 16 25 36 Digit Codes DB 30h 316 32h 33h 34h 35h 36h 37h 38h 39h Message DB HELLO FRIEND 0Ah l4 byte text plus new line code DUP Initialization To repeat init or list of init a specified number of times use the DUP operator in this format dup count DUP init The duplication count is expressed by dup count which must be a positive number init can be a numeric expression an address if used with DW or DD a question mark a list of items or a nested DUP expression Note that in the DB DW and DD directives the name of the vari able being defined is not followed by a colon This differs from many other assembly languages For example Name DW 100 okay Name DW 100 WRONG Labels and the LABEL Directive Labels identify locations within executable code to
52. to the starting address with interrupts enabled SS and DS When Calling Object Module Procedures If the program calls Convergent object module procedures there are additional requirements The program format used in Figure 11 2 does not suffice A correct program is given Figure 11 3 illustrating the following points The stack segment must have segment name Stack combine type Stack and classname Stack See line 44 Although not required it is standard practice that user code be contiguous in memory with Convergent code and that code be at the front of the memory image This is achieved if all 78 Assembly Language Manual code segments have classname Code and this class is mentioned before any other in the module See lines 11 12 It is desirable to avoid forward references to constants It is also standard though not required to make user constants contiguous with Convergent constants in the memory image and to locate constants directly after code You can achieve both goals by giving all constant segments the classname Const and by mentioning this classname before any other save Code See lines 17 22 It is desirable to avoid forward references to data It is also standard though not required to make user data contiguous with Convergent data in the memory image and to locate data directly after constants You can achieve both goals by giving all data segments the classname Data and by mentioning this c
53. 0 Assembly Language Manual Dev lt Jones gt Main then the default object file is Dev lt Jones gt Main Obj If the last source file is Prog Asm then the default object file is Prog Obj List File A listing of the assembly is written to the speci fied list file The default is the last source file That is if no explicit listing file is specified a file name is derived from the last source file With the examples given above the list files would be named respectively lt Jones gt Main 1lst and Prog lst Error file Fill in the Error file field with the name of the file to receive the errors only listing if you wish to create both a full listing and a listing of just the errors The default is to create no such listing List on pass 1 Fill in the List on pass 1 field with Yes to diagnose certain errors in macros Listings are normally generated only during the second assembly pass However some programming errors involving macros prevent the assembly process from ever reaching its second pass To diagnose such errors specify List on pass 1 as Yes Listings are then generated during both assembly passes The default is No Introduction 11 2 PROGRAMS AND SEGMENTS Segments SEGMENT ENDS Directives Each of the instructions and variables of a program is within some segment Segments can be named explicitly using the SEGMENT directive but if no name is specified for a segment
54. 17 The instruction INT n loads the instruction pointer IP with the 16 bit value stored at location 4 n of physical memory and loads CS with the 16 bit value stored at physical memory address 4 2 A hardware RESET loads CS with OFFFFh and IP with 0 Here is an example of defining the stack and loading the stack segment register SS Stack SEGMENT STACK DW 1000 DUP 0 1000 words of Stack StackStart LABEL WORD Stack expands toward low memory Stack ENDS StackSetup SEGMENT ASSUME CS StackSetup MOV BX Stack MOV SS BX MOV SP OFFSET StackStart start end initially StackSetup ENDS This example illustrates an important point each of the two register pairs SS SP and CS IP must be loaded together The hardware has special provision to assist in this loading a segment register by a POP or MOV instruction causes execution of the very next instruction to be protected against all inter rupts That is why the very next instruction after the load of the stack base register SS must load the stack offset register SP CS and its associated offset IP are loaded only by special instructions and never by normal data transfers SS and its associated offset SP are loaded by normal data transfers but must be loaded in two successive instructions Segment Override Prefix If there is no ASSUME directive for a reference to a named variable then the appropriate segment reference can be inserted explicitly as a segment o
55. 17 EA x XXXXX 17 EA x XXXXX 17 EA x XXXXX 4 XXUXC 4 XXUXC 16 EA 3 XXUXC 16 EA 3 XXUXC 9 3 xxuxc 9 3 xxuxc 17 XXUXC 17 EA XXUXC 28 11 13 EA 29 2 2 2 2 2 x 4 x XXXXX 4 x XXXXX 9 x XXXXX 9 x XXXXX 9 x XXXXX 9 x XXXXX 10 EA x XXXXX 10 EA x XXXXX 10 EA x XXXXX 10 EA x XXXXX 22 x XXXXX 9 22 rep 22 x 9 22 rep 2 5 4 x XXXXX Table A 3 Instruction Set in Alphabetic Order of Instruction Mnemonic Instruc Operand Summary Memory Clocks tion ca organization 2 of 6 53 DAS Decimal adjust for subtract DEC AX 1 48 2 DEC BP BP BP 1 4D 2 DEC BX BX BX 1 4B 2 DEC cx CX CX 1 49 2 DEC DI DI DI 1 4F 2 DEC Dx DX DX 1 4 2 DEC bEA bEA bEA 1 FE 001 R M 15 DEC wEA WEA wEA 1 MOD 001 R M 15 DEC SP SP SP 1 4c 2 DEC SI SI SI 1 4 2 DIV bEA Unsigned divide by bEA F6 110 90 DIV wEA Unsigned divide by wEA 7 110 R M 155 DS DS segment override 3E 2 ES ES segment override 26 2 ESC EA Escape to external device D8 MOD R M 8 HLT Halt F4 2 IDIV bEA Signed divide by bEA F6 111 112 IDIV wEA Signed divide by wEA F7 111 R M 177 IMUL bEA Signed multiply by bEA F6 101 30 IMULT WEA Signed multiply by F7 101 R M 144 AL DX Byte input from port DX to REG AL EC 8 IN
56. 2 Typed interrupt 51 Interrupt if overflow 53 or 4 and actual interrupt Return from interrupt Rotate bEA left 1 bit Rotate bEA right 1 bit 24 15 EA 15 EA Rotate bEA left through earry 1 bit 15 EA Rotate bEA right through carry 1 bit Shift bEA left 1 bit Shift bEA right 1 bit Shift signed bEA right 1 bit Rotate wEA left 1 bit Rotate wEA right 1 bit 15 EA 15 EA 15 EA 15 EA 15 EA 15 EA Rotate wEA left through carry 1 bit 15 EA Rotate wEA right through carry 1 bit Shift wEA left 1 bit Shift wEA right 1 bit Shift signed wEA right 1 bit 15 EA 15 EA 15 EA 15 EA Instruction Set Of T Flags ODITSZAPC 53 RRRRRRRRR x x x x x x x x x x x x x XXUXX x x x x x x x x x x x x x XXUXX 9 Table Op D2 D2 D2 D2 D2 D2 D2 D2 D3 D3 D3 D3 D3 D3 D3 D3 D4 D5 D6 D7 D8 EO El E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF FO Fl A 10 A 3 Instruction Set in Numeric Order of Instruction Code MOD 000 R M MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD 00001010 00001010 001 010 011 100 101 110 111 000 001 010 011 100 101 110 111 R M R M R M R M R M R M R M R M R M R M R M R M R M R M R M MOD R M Assembly Language Manual ROL ROR RCL RCR SHL SHR
57. 3 0 51 57 1 52 FF 06 56 54 16 9c DO DI MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD 100 100 011 011 010 010 001 001 Instruction Set in Alphabetic Order of Instruction Mnemonic Operand Summary op Memory Clocks ca organization R M R M R M R M R M R M R M R M REGR M REGR M REGR M REGR M MOD 000 R M MOD 110 R M MOD 010 R M MOD 010 R M 4 of 6 Flags ODITSZAPC 18 9 17 rep 18 9 17 rep 71 X UUUUX 124 X UUUUX 16 X XXXXS 16 Xx xxxxs 16 16 4 C 4 17 C 17 16 3 16 3 9 3 9 3 8 8 10 10 8 8 8 8 8 8 8 17 8 8 8 8 8 RRRRRRRRR 11 11 11 11 11 11 10 11 16 10 11 11 11 X XXXXX 10 15 x x 15 x x 15 Instruction Set Table A 3 Instruction Set in Alphabetic Order of Instruction Mnemonic 5 of 6 Summary Op Memory Clocks Flags tion Cd Organization ODITSZAPC MOVS MOVSB Move byte string A4 18 MOVSW Move word string A5 18 RCR bEA CL Rotate bEA right thru carry D2 MOD 011 R M 20 EA x x CL bits 4 bit RCR wEA CL Rotate wEA right thru carry MOD 011 R M 20 EA x x CL bits 4 bit RCR 1 Rotate bEA right thru DO MOD 011 R M 15 EA x x 1 bit RCR wEA 1 Rotate
58. 3 absolute memory address 32230h specify AT 3223h You can use any valid expression that evaluates to a constant and Programs and Segments 13 has no forward references An absolute segment is permitted to establish a template for memory to be accessed at run time no assembly time data or code is automatically loaded into an absolute segment 4 STACK the elements are overlaid such that the final bytes of each element are juxtaposed to yield a combined segment whose length is the sum of the lengths of the elements Stack segments with the name STACK are a special case When stack segments are combined they are overlaid but their lengths are added together When the Linker has combined all stack segments it forces the total length of the aggregate stack segment to a multiple of 16 bytes Compilers construct stack segments automatically However if your entire program is written in assembly language you have to define an explicit stack segment There are special rules regarding the use of the stack that must be observed for calls to standard object module procedures See Section 9 Accessing Standard Services from Assembly Code below 5 COMMON the elements are overlaid such that the initial bytes of each element are juxtaposed to yield a combined segment whose length is the largest of the lengths of the elements The optional classname can be used to affect the ordering of segments in the memory image constructed by the Linker S
59. 6 MOD REGR M 17 EA 4 XCHG WREG wEA Exchange wREG 87 MOD REGR M 17 4 XLAT TABLE Translate using BX D7 11 XOR AL bData AL AL XOR bData 34 4 XXUXC XOR AX wData AX AX XOR wData 35 4 XXUXC XOR bEA bData bEA bEA XOR bData 80 MOD 101 R M 17 XXUXC XOR wEA wData wEA wEA XOR wData 81 101 R M 17 EA XXUXC XOR bEA REG bEA bEA XOR bREG 30 MOD REGR M 16 3 XOR wEA REG wEA wEA XOR WREG 31 REGR M 16 EA 3 XOR REG bEA bREG bREG XOR bEA 32 MOD REGR M 9 3 xxuxc REG wEA WREG wWREG XOR wEA 33 MOD REGR M 9 3 xxuxc Instruction Set A 17 Appendix B AAA AAD AAM AAS ABS ADC ADD AH AL AND ASSUME AT AX BH BL BP CALL CBW CH cL CLC CLD CLI CMC CMP CMPS CMPSB CMPSW COMMON cs CWD Cx DAA DAS DB DD DEC DH DI DIV DL DS DUP DW DWORD DX EJECT END ENDP RESERVED WORDS ENDS EQ EQU ES ESC EVEN EXTRN FAC FALC FAR GE GEN GENONLY GROUP GT HIGH HLT IDIV IMUL IN INC INCLUDE INT INTO IRET JA JAE JB JBCZ JBE JC JE JGE JL JLE JMP JNA JNAE JNB JNBE JNC JNE JNG JNGE JNLE JNO JNP JNS JNZ JO JP JPE JPO JS JZ LABEL LAHF LDS LE LEA LENGTH LES LIST LOCK LODS LODSB LODSW LOOP LOOPE LOOPNZ LOOPZ LOW LT MASK MEMORY MOD MOV MOVS MOVSB MOVSW MUL NAME NE NEAR NEG NIL NOGEN NOLIST NOPAGING
60. A SR REG effective address SR WwEA Pop stack to EA Instruction Set ie or 16 or 16 or 16 or 16 or 16 or 16 or 16 or 16 or 17 EA 17 EA 17 EA 17 EA 17 EA 17 EA 17 EA 10 EA 17 EA 17 EA 17 EA 17 EA 17 EA 17 EA 17 EA 10 EA 17 EA gt P P P P P P P P P gt 17 EA 17 EA 17 EA 10 EA 17 EA 17 EA 17 EA 17 EA 10 9 3 9 3 17 4 17 EA 4 9 EA 2 9 EA 2 8 EA 2 8 EA 2 9 EA 2 2 EA 2 8 EA 2 17 EA Page 3 of 7 Flags ODITSZAPC gt lt gt lt Q gt O gt KOR KOKO x KOK lt XXXXX XXUXC XXXXX XXXXX XXUXC XXXXX XXUXC XXXXX XXXXX XXUXC XXXXX XXXXX XXUXC XXXXX XXUXC XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXUXC XXUXC A 7 Table A 3 8F MOD 100 R M not 8F MOD 101 R M not 8F MOD 110 R M not 8F MOD 111 R M not 90 XCHG 91 XCHG 92 XCHG 93 XCHG 94 XCHG 95 XCHG 96 XCHG 97 XCHG 98 CBW 99 CWD 9A CALL 9B WAITX 9c PUSHF 9D POPF 9E SAHF 9F LAHF AO MOV Al MOV 2 MOV A3 MOV A4 MOVSB A5 MOVSW A6 CMPSB A7 CMPSW A8 TEST A9 TEST AA STOSB AB STOSW AC LODSB AD LODSW AE SCASB AF SCASW BO MOV B1 MOV B2 MOV B3 MOV B4 MOV B5 MOV B6 MOV B7 MOV B8 MOV B9 MOV BA MOV BB MOV BC MOV A 8 Assembly Language Manual used used used used AX AX 5 5 off sba AL bAddr
61. AAM AAS ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADD ADD ADD ADD ADD ADD ADD ADD ADD ADD AND AND AND AND AND AND AND AND CALL CALL CALL CALL CBW CLC CLD CLI CMC CMP CMP CMP CMP CMP CMP CMP CMP CMP CMP CMPSB CMPSW 5 CWD DAA A 12 Operand Summary Op Memory Clocks Cd Organization AL bData AX wData bEA bData wEA wData bEA bData wEA bData bEA REG wEA REG REG bEA REG wEA AL bData AX wData bEA REG wEA REG REG bEA REG bEA bData wEA wData bEA bData wEA bData AL bData AX wData bEA REG WEA REG bEA REG wEA bEA bData wEA wData off sba wDISP EA EA AL bData AX wData bEA bREG WEA WREG bREG bEA wREG wEA bEA bData bEA bData wEA wData wEA bData ASCII adjust for add ASCII adjust for divide ASCII adjust for multiply ASCII adjust for subtract AL AL bData CF AX AX wData CF bEA bEA bDatat CF wEA wEA wDatat CF bEA bEA bDatat CF wEA wEA Ext bData CF bEA bEA bREG CF wEA wEA wREG CF DREG bREG bEA CF WREG wREG wEA CF AL AL bData AX AX wData bEA bEA bREG bREG bREG bEA WREG wWREG wEA bEA bEA bData wEA wEA wData bEA bEA bData FLAGS wEA Ext bData AL AL AND bData AX AX AND wData bEA bEA AND bREG wEA wEA AND wREG bREG bREG AND bEA WREG wREG AND bEA bEA AND bData
62. ASSEMBLY LANGUAGE MANUAL Specifications Subject to Change Convergent Technologies Convergent CTOS CT BUS IWS EWS and MWS are trademarks of Convergent Technologies Copyright 1980 by Convergent Technologies CONTENTS Guide to Technical Documentation 1 2 3 ENETGOAUCE Choice Among Convergent Languages Features of the Assembly Language Design of the Instruction Set Object Modules Linking Segments and Memory References Registers Addressing Procedures Macros 6 aves asua s awas ean es Invoking the Assembler from the Executive Field Descriptions Programs and Segments Segments SEGMENT ENDS Directives Segment Nesting ASSUME Directive Loading Segment Registers Segment Override Prefix Anonymous References Memory Reference in String Instructions GROUP Directive Procedures PROC ENDP Directives Calling a Procedure Recursive Procedures and Procedure Nesting on the Returning from a Procedure Location Counter and ORG Directive EVEN UR RD nsnm Program Linkage NAME END END Directive Data Definition ww IntroduoctioDisksexk e sawas ConstantS Attributes of Data Items SEG
63. C directive 54 Assembly Language Manual 5 FORWARD REFERENCES The instruction set of the 8086 often provides several ways of achieving the same end For example if a jump is within 128 bytes of its target the control transfer can be a SHORT jump two bytes a NEAR jump three bytes or a FAR jump four bytes If the assembler knows which case applies it generates the optimal object code However for the convenience of the programmer the assembly language allows in many cases the use of a variable or label prior to its definition When the assembler encounters such a forward reference it must reserve space for the reference although it does not yet know whether the label for example will turn out to be SHORT NEAR or FAR The assembler makes a guess if it must about the memory required and proceeds on the basis of that guess The assembler makes two successive passes over the source program and can always tell during the second pass whether a guess made during the first pass was correct If a guess is too generous the assembler can repair matters during the second pass by for example inserting an extra no op instruction after an offending jump and still produce valid output If a guess is too conservative however no such remedy is available and the assembler flags the forward reference as an error during the second pass The programmer can generally repair this kind of error by a small change to the sour
64. D PARA or PAGE It cannot be used in a segment whose alignment type is BYTE Program Linkage NAME END PUBLIC and EXTRN The Linker combines several different assembly modules into single load module for execution For more about the Linker see the Utilities Manual Three program linkage directives can be used by the assembly module to identify symbolic references between modules None of these three linkage directives can be labeled They are NAME which assigns a name to the object module generated by the assembly For example SortRoutines If there is no explicit NAME directive the module name is derived from the source file name For example the source file Volname lt Dirname gt Sort Asm has the default module name Sort PUBLIC which specifies those symbols defined within the assembly module whose attributes are made available to other modules at linkage For example PUBLIC SortExtended Merge If a symbol is declared PUBLIC in a module the module must contain a definition of the symbol EXTRN which specifies symbols that are defined as PUBLIC in other modules and referred to in the current module Here is the format of the EXTRN directive 26 Assembly Language Manual EXTRN name type In this format name is the symbol defined PUBLIC elsewhere and type must be consistent with the declaration of name in its defining module type is one of BYTE WORD DWORD struct
65. EA bEA bData CF 82 MOD 011 R M 17 EA x XXXXX SBB wEA wData WEA wEA wData CF 81 MOD 011 R M 17 EA x XXXXX SBB wEA bData wEA wEA Ext bData CF 83 011 17 EA X XXXXX SBB bEA REG bEA bEA bREG CF 18 MOD REG 16 3 xxxxx SBB wEA WEA CF 19 MOD REG 16 3 xxxxx SBB REG bEA bREG bREG bEA CF 1A MOD REG 9 3 X xxxxx SBB REG wEA wWREG WREG WEA CF 1B MOD REG 9 EA 3 X xxxxx SCASB Scan byte string AE 15 x XXXXX 9 15 rep SCASW Scan word string AF 15 Ix XXXXX 9 15 rep SHL bEA CL Shift bEA left D2 MOD 100 R M 20 CL bits 4 bit x x A 16 Assembly Language Manual Table A 3 Instruction Set in Alphabetic Order of Instruction Mnemonic 6 of 6 Instruc Operand Summary op Memory Clocks a tion cd Organization ODITSZAPC SHL wEA CL Shift wEA left 20 EA CL bits 4 bit x x SHL bEA 1 Shift bEA left 1 bit DO 100 15 x x SHL 1 Shift wEA left 1 bit D1 100 15 x X SHR bEA CL Shift bEA right D2 MOD 101 R M 20 CL bits 4 bit x x SHR wEA CL Shift wEA right D3 MOD 101 R M 20 EA CL bits 4 bit x x SHR bEA 1 Shift bEA right 1 bit DO 101 15 EA x x SHR wEA 1 Shift wEA right 1 bit D1 MOD 101 R M 15 EA x x ss SS segment override 36 2 STC Set carry flag F9 2 S STD Set direction flag FD 2 STI Set interrupt flag FB 2 s STOSB Store byte
66. FAR LENGTH It accepts one argument a variable It returns the number of units allocated for that variable The number returned is not necessarily bytes Here are examples One DB 250 Two DW 350 LENGTH One 250 LENGTH Two 350 SIZE It returns the total number of bytes allocated for a variable SIZE is the product of LENGTH and TYPE SEG It computes the segment value of a variable or a label Use it in ASSUME directives or to initialize segment registers as described in Section 2 Operands and Expressions 51 OFFSET It returns the offset of a variable or label At time of linking when the final alignment of the segment is frozen the value is resolved If a segment is combined with pieces of the same segment defined in other assembly modules or is not aligned on a paragraph boundary the assembly time offsets shown in the assembly listing can not be valid at run time The offsets are properly calculated by the Linker if you use the OFFSET operator The only attribute of a variable in many assembly languages is its offset A reference to the variable s name is a reference also to its offset Three attributes are defined by this assembly language for a variable so to isolate the offset value the OFFSET operator is needed DW direc tive however the OFFSET operator is implicit The variables in address expressions that appear in DW and DD directives have an implicit OFFSET When used with th
67. MENT OFFSET TYPE DISTANCE Variable Definition DB Constant Initi lizatioOn 9 ee Side Indeterminate Initialization Address Initialization DW and DD Only String InitializatiOn n e e aves DW DD Directives PUBLIC and EXTRN Contents vii 4 Q N 23 25 25 26 26 27 iii Enumerated Initialization y Z 665 ss e RAE RE ER 34 DUP Initialization a ae aos ane ase 34 Labels and the LABEL 34 LABEL Wee Sea OER 35 LABEL with VariableS 442 sah i wa ee ee ae eee 35 WICH COGO naa waqsa ain ania ara uyata 36 Label 4 111 36 4 37 Initializing RecordS e 9r BSS ees 38 39 Default Structure FieldS i 4 ie wana RUE 41 Overridable Structure 145 41 Initializing 44 6 48 asa a a OS HERE hawa 42 4 Operands and 43 4 43 Immediate
68. ORD PTR BX Indirect NEAR Contained in word at BX Assuming NextIteration is a NEAR label in the same segment or group as the jump or call Assuming FltMul is a FAR label a label to which control be transferred from outside the segment containing the label Assuming LabelsNear is an array of words Assuming LabelsFar is an array of dwords CALL differs from JMP only in that a return address is pushed onto the stack The return address is a word for a near call and a dword for a far call If the assembler determines that the target of a JMP or CALL is addressable by 1 displacement from the instruction it uses a special short jump or call instruction Here are some examples Again DEC BX JNZ Again Short jump will be used JMP Last Not short because Last is a forward reference Last JMP 5 17 Short jump since displacement is the range 128 to 127 BEWARE Variable length instructions make it easy to get this wrong it s safer to use a label JMP SHORT Last Forces assembly of a short transfer it 2 111 yield an error if the target is not addressable with 1 byte displacement Operands and Expressions 47 NOTE Do not confuse the concepts of PUBLIC and EXTRN with NEAR and FAR PUBLICS and EXTRNs are used at assembly and link time only and are not run time concepts NEAR and FAR in contrast control the instructions to be executed at run time It is entirely possibl
69. OV AX wAddr AX wAddr Al 10 MOV AX wData AX wData B8 4 MOV BH bData BH bData B7 4 MOV BL bData BL bData B3 4 MOV BP wData BP wData BD 4 MOV BX wData BX wData BB 4 MOV CH bData CH bData B5 4 MOV CL bData CL bData Bl 4 MOV CX wData CX wData 9 4 MOV DH bData DH bData B6 4 MOV DI wData DI wData BF 4 MOV DL bData DL bData B2 4 MOV DX wData DX wData BA 4 MOV bEA bData bEA bData 000 10 MOV wEA wData wEA wData C7 000 R M 10 MOV bEA bREG bEA bREG 88 MOD REGR M 9 2 MOV wEA WREG wEA wREG 89 MOD REGR M 9 EA 2 MOV wEA SR wEA SR 8c OSR 9 2 MOV bREG bEA bREG bEA 8A MOD REGR M 8 EA 2 MOV wREG wEA wREG wEA 8B MOD REGR M 8 EA 2 MOV SI wData SI wData BE 4 MOV SP wData SP wData BC 4 MOV SR wEA SR wEA 8E MOD OSR R M 8 EA 2 A 14 Assembly Language Manual Table A 3 Instruc tion MOVS MOVSB MOVSW MUL MUL NEG Note NEG Note NOP NOT NOT OR OR OR OR OR OR OR OR OUT OUT OUT OUT POP POP POP POP POP POP POP POP POP POP POP POP POPF PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSHF RCL RCL Use MOVSB MOVSW Move byte string bEA wEA bEA bEA wEA AL bData AX wData bEA bData wEA wData bEA REG wEA REG bEA REG wEA DX AL DX AX bPort AL wPort AX AX BX BP Cx DI DS DX EA ES SI
70. P bDISP bDISP bDISP bDISP bDISP bDISP bEA bData bEA bData bEA bData bEA bData bEA bData bEA bData bEA bData bEA bData wEA wData wEA wData wEA wData wEA wData wEA wData wEA wData wEA wData wEA wData bEA bData not used bEA bData bEA bData not used bEA bData not used bEA bData wEA bData not used wEA bData wEA bData not used wEA bData not used wEA bData bEA bREG wEA WREG bREG bEA wREG wEA bEA bREG wEA WREG bREG bEA WREG WEA wEA SR used REG EA SR wEA used used used used Jump if below or equal Jump is above Jump if sign Jump if no sign Jump if parity even Jump if parity odd Jump if less Jump if greater or equal Jump if less or equal Jump if greater bEA bEA bData bEA bEA OR bData bEA bEA bDatat CF bEA bEA bData CF bEA bEA AND bData bEA bEA bData bEA bEA XOR bData FLAGS bEA CMP bData WEA wEA wData wEA wEA OR wData wEA wEA wDatat CF WEA wEA wData CF wEA wEA AND wData WEA wEA wData WEA wEA XOR wData FLAGS wEA XOR wData bEA bEA bData bEA bEA bData CF bEA bEA bData CF bEA bEA bData FLAGS bEA CMP bData FLAGS wEA Ext bData wEA WwEA Ext bData CF WEA wEA Ext bData CF WEA wEA Ext bData FLAGS wEA CMP Ext bData FLAGS bEA TEST bREG FLAGS wEA TEST wREG Exchange bREG bEA Exchange wREG wEA bEA bREG WEA wREG bREG bEA WREG wEA wE
71. R M fields determine the effective address EA of the memory operand and the interpretation of successive bytes of the instruction as follows MOD Interpretation 00 DISP 0 disp low and disp high are absent 01 DISP disp low sign extended to 16 bits disp high is absent 10 DISP disp high disp low 11 There is no DISP disp low and disp high are both absent and R M is interpreted as a register If MOD 11 then R M is interpreted as follows R M interpretation 000 BX SI DISP 001 BX DI DISP 010 BP SI DISP 011 BP DI DISP 100 SI DISP 101 DI DISP 110 BP DISP if MOD 0 DISP if MOD 0 111 BX DISP Instruction Format 57 If MOD 11 then the effective address is a register designated by R M In word instructions the interpretation is R M Register 000 AX 001 CX 010 DX 011 BX 100 SP 101 BP 110 SI 111 DI In byte instructions W 0 the interpretation is R M Register 000 AL 001 cL 010 DL 011 BL 100 AH 101 CH 110 DH 111 BH 58 Assembly Language Manual 7 FLAGS Flag Registers Certain results of data manipulations are distinguished or denoted by flags The flags that are affected by data manipulations are AF CF OF PF SF and ZF The four basic mathematical operations addition subtraction multiplication and division are provided by the processor 8 and 16 bit operations are available as are signed and unsigned arithmetic The representation of signed values
72. XXX XXXX XXXX XXXX UUUUU UUUUU UUUUU UUUUU UUUUX UUUUX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX RRRRRRRRR Instruction Set A 13 Table A 3 Instruction Set in Alphabetic Order of Instruction Mnemonic 3 of 6 Instruc Operand Summary Op Memory Clocks Flags tion Cd Organization ODITSZAPC as JNA Same JBE JNB Same as JAE JNBE Same as JA JNG Same as JLE JNGE Same as JL JNL Same as JGE JNLE Same as JG JNO bDISP Jump if no overflow 71 16 or 4 JNP Same as JPO JNS bDISP Jump if no sign 79 16 or 4 JNZ bDISP Jump if not zero 75 16 or 4 JO bDISP Jump if overflow 70 16 or 4 JPE bDISP Jump if parity even 7A 16 or 4 JPO bDISP Jump if parity odd 7B 16 or 4 JS bDISP Jump if sign 78 16 or 4 JZ bDISP Jump if zero 74 16 or 4 LAHF AH FLAGS 9F 4 LDS REG EA DS REG wEA 2 WEA C5 MOD REGR M 16 LEA EA REG effective address 8D MOD REGR M 2 EA 2 LES EA ES REG wEA 2 wEA 4 MOD REGR M 16 LODSB Load byte string AC 12 9 13 rep LODSW Load word string AD 12 9 13 rep LOCK Bus lock prefix FO 2 LOOP bDISP Loop CX times E2 17 5 LOOPE Same as LOOPZ LOOPNE Same as LOOPNZ LOOPNZ bDISP Loop CX times while 0 not zero 19 or 5 LOOPZ bDISP Loop CX times while zero El 18 or 6 MOV bAddr AL bAddr AL A2 10 MOV wAddr AX wAddr AX A3 10 MOV AH bData AH bData B4 4 MOV AL bAddr AL bAddr AO 10 MOV AL bData AL bData BO 4 M
73. aining RETURN or apostrophe or text not containing RETURN or apostrophe RETURN Here RETURN designates the character generated by the Convergent RETURN key code OAh Since the characters of the embedded text of a comment are consumed without any effect comments may be used to insert extra returns for readability macro definitions 68 Assembly Language Manual Match Operation The special macro function MATCH is particularly useful for parsing strings during macro processing It permits its parameters to be divided into two parts a head and a tail A simple form is SMATCH varl var2 text For example following the expansion of SMATCH varl var2 a b c d The macro variable varl has the value a and var2 the value b Gp od This facility might be used together with LEN and WHILE Consider the expression SWHILE LEN arg GT 0 head arg arg DW head If arg is initially the text 10 20 30 40 then the expansion is DW 10 DW 20 DW 30 DW 40 Advanced Features The form of MATCH just described as well as the form of macro definition and call described above are actually only special cases In fact the separator between the parameters of MATCH or of a macro can be a user specified separator other than comma The remainder of this Section explains this and a number of related advanced features of the macro facility Most programmers find the macro facilities described above
74. ame field of a SEGMENT directive an expression of the form SEG variable name or an expression of the form SEG label name See Value Returning Operators in Section 4 for a definition of the SEG operator is an optional list of segnames Each segname in the list is preceded by a comma This directive defines a group consisting of the specified seg ments The group name can be used much like a segname except that a group name must not appear in another GROUP statement as a segname Here are three important uses of the GROUP directive Programs and Segments 21 1 Use it as an immediate value loaded first into a general register and then into a segment register as in MOV CX DGroup MOV ES CX The Linker computes the base value as the lowest segment in the group 2 Use it an ASSUME statement to indicate that the segment register addresses all segments of the group as in ASSUME CS CGroup 3 Use it as an operand prefix to specify the use of the group base value or offset instead of the default segment base value or offset as in MOV CX OFFSET DGroup xTab See Value Returning Operators in Section 4 for additional information about OFFSET It is not known during assembly whether all segments named in a GROUP directive will fit into 64K the Linker checks and issues a message if they do not fit Note that the GROUP directive is declarative only not imperative it asserts that segments fit in 64K but
75. andy et nas S43ue3suo2 sa qgtueA Hutssauppe V 2 35 e eqseq 48u05 danosa es sana Y2V1S 15 56 JO DUB 34 TAJET os 8943 pauyquo3 aue squaufas 92946 hem ev 243 40 asne2ag l qgl 13835 go PT4TUI f ayom nea Br 0200 0000 t dna HOF 4 9 0000 abed 08 4 5 1 SYGT Z IX ueqquassy o42e4 93 Sample Assembler Modules urew ur6 g 40 ssauppe 34e3s fyroads sawt 9007 t rp eucqsau 319310 o4 3403584 248 yr dunf 2 prasad T 3 9 8 0 1 dunt TYISE 4u8Au02 330 QE aya saaqqor2 2 4 3urs anes 4151p yxau uoti415sad gunos 4165p sA4asasud 01 1086400 pue ur 110220 souua ue sua 45814 a6eg OB d S BI Sr SI utbag SON3 itx340443 VI xv HSNd 34 3113404 348 XV 10119 ejeg 138 9007 x2 dOd xv 494495 anv 1192 xv prAsq xy vai sa P ASQd agfgaa3t4M 01 0 4 18 aay e1utrad
76. ata 4 XXUXC 36 ss SS segment override 2 37 ASCII adjust for 4 U UUXUX 38 MOD REGR M bEA bREG FLAGS bEA bREG 9 EA x XXXXX 39 MOD REGR M CMP WEA wREG FLAGS wEA WREG 9 EA x XXXXX MOD REGR M bREG bEA FLAGS bREG CMP bEA 9 x XXXXX Instruction Set A 5 Table A 3 op 3B A 6 Memory Instruc Operand Summary Clocks Organization tion MOD REGR M CMP JNZ Assembly Language Manual used used used used used used used used used used used used used used used used wREG wEA FLAGS wREG CMP AL bData FLAGS AL CMP AX wData FLAGS AX CMP DS segment override AX CX DX BX SP BP SI DI AX CX DX BX SP BP SI DI AX Cx DX BX SP BP SI DI AX Cx DX BX SP BP SI DI bDISP bDISP bDISP bDISP bDISP bDISP ASCII adjust for subtract AX AX 1 CX CX 1 DX DX 1 BX BX 1 SP SP 1 BP BP 1 SI SI 1 DI DI 1 AX AX 1 CX CX 1 DX DX 1 BX BX 1 SP SP 1 BP BP 1 SI SI 1 DI DI 1 onto onto onto onto onto onto onto onto Push Push Push Push Push Push Push Push Pop Pop Pop Pop Pop Pop Pop Pop Jump Jump Jump Jump Jump Jump AX CX DX BX SP BP SI DI stack stack stack stack stack stack stack stack to to to to to to to to AX CX DX BX SP BP SI DI Instruction Set in Nu
77. ate E00h MASK sKey 1E00h MASK rbKey 1FFh WIDTh state 3h WIDTh skey 4h WIDTh rbKey 9h As another example let us define the format for the first two bytes of an instruction Inst2b RECORD Opcode 6 D 1 W 1 Mod 2 Reg 3 Rm 3 The definition might be used in this way Inst_Table Inst2b 100 DUP lt gt Code to initialize Inst Table MOV AX Inst Table BX Load the entry at offset BX AND AX MASK Mod Mask off all but Mod MOV CL Mod SHR AX CL Now AX contains Mod This example also shows how for each record field the bit position and MASK operator can be used to extract the field from a record The assembler right justifies a record s user defined fields when those fields do not occupy an entire word or byte The fields are moved to the least significant bit positions of the byte or word defined by the record For example the definition Ascii Twice RECORD C1 7 C2 7 would result in the format 15 14 13 7 6 0 undefined C1 C2 2 bits 7 bits 7 bits Initializing Records After records have been declared the record name and operator can be used for allocation and initialization There are two formats Format 1 name record name lt init 38 Assembly Language Manual Format 2 name record name dup count DUP lt init gt In both formats the first byte or word depending on the RECORD definition of the allocated memory is optionally named The
78. be chosen The DB DW and DD directives can be used in many ways The possibilities are 1 constant initialization 2 indeterminate initialization the reserved symbol 3 address initialization DW and DD only 4 string initialization 5 enumerated initialization and 6 DUP initialization Constant Initialization One two or four bytes are allocated The expression is evalu ated to a 17 bit constant using twos complement arithmetic For bytes the least significant byte of the result is used For words the two least significant bytes are used with the least significant byte the lower addressed byte and the most signifi cant byte the higher addressed byte As an example OAAFFh is stored with the OFFh byte first and the OAAh byte second For double words the same two bytes are used as for words and they are followed by an additional two bytes of zeros Here are some examples 32 Assembly Language Manual number DW 1F3Eh 3Eh at number 1Fh at number 1 DB 100 Unnamed byte inches per yard DW 3 12 Assembler performs arithmetic Indeterminate Initialization To leave initialization of memory unspecified use the reserved symbol Here are some examples x DW 2 Define and allocate a word contents indeterminate buffer DB 1000 DUP 71000 bytes The DUP clause is explained in Dup Initialization below Address Initialization DW and DD Only variable name DW DD init addr An address ex
79. be immediate a WORD reference to memory or a WORD register When an 8 bit general register AH AL BH BL CH CL DH DL is one of the operands of a two operand instruction the other operand must be an 8 bit immediate quantity a BYTE reference to memory or a BYTE register Flags Instructions never specify the 1 61 flags as operands flag instructions as STC CLC CMC manipulate all flags at once and other instructions affect one or more flags implicitly as INC DEC ADD MUL and DIV See Section 7 for flag operation and Appendix A for how each instruction affects the flags Memory Operands Memory Operands to JMP and CALL The JMP and CALL instructions take a simple operand There are a number of different cases determined by the operand The control transfer can be direct with the operand specifying the target address or indirect with the operand specifying a word or doubleword containing the target address The transfer can be NEAR in which case only IP changes or PAR both IP and CS change Here are examples to illustrate the cases 46 Assembly Language Manual Operand to JMP CALL Direct Indirect NEAR FAR Target NextIteration Direct NEAR NextIteration FltMul Direct FAR2 FltMul DX Indirect NEAR CS DX LabelsNear DI Indirect NEAR Contained in word at LabelsNear DI LabelsFar DI Indirect FAR Contained in dword at LabelsFar DI DWORD PTR BX Indirect FAR Contained in FAR dword at BX W
80. be used as operands of jump and call instructions A NEAR label is declared by any of the following 34 Assembly Language Manual Start LABEL is the default Start LABEL NEAR NEAR can be explicit Start Followed by code Start EQU Start EQU THIS NEAR Start PROC NEAR is the default Start PROC NEAR NEAR can be explicit A FAR label is declared by any of the following Start2 EQU THIS FAR Start2 LABEL FAR Start PROC FAR LABEL Directive To create a name for data or instructions use the LABEL direc tive in the format name LABEL type name is given segment offset and type attributes The label is given a segment attribute specifying the current segment an offset attribute specifying the offset within this segment and a type as explicitly coded NEAR FAR BYTE WORD DWORD struc ture name or record name When the LABEL directive is followed by executable code type is usually NEAR or FAR The label is used for jumps or calls but not MOVs or other instructions that manipulate data NEAR and FAR labels cannot be indexed When the LABEL directive is followed by data type is one of the other five classifications An identifier declared using the LABEL directive can be indexed if assigned a data type such as BYTE WORD etc The name is then valid in MOVs ADDs and so on but not in direct jumps or calls See Section 4 for indi rect jumps or calls A LABEL directive using structure name or recor
81. cation counter is symbolically represented by the dollar sign The value is the offset from the current segment at which the next instruction or data item will be assembled This value is initialized to 0 for each segment If a segment is ended by an ENDS directive and then reopened by a SEGMENT directive then the location coun ter resumes the value it had at the ENDS The ORG directive is used to set the location counter to a nonnegative number Here is the format ORG expression The expression is evaluated modulo 65536 and must not contain any forward references The expression can contain the current value of the location counter as in ORG OFFSET 1000 which moves the location counter forward 1000 bytes An ORG directive may not have a label Programs and Segments 25 The use of the location counter and ORG are related to the use of the THIS directive which is discussed in Attribute Operators in Section 4 EVEN Directive It is sometimes necessary to ensure that an item of code or data is aligned on a word boundary For example a disk sector buffer for use by the Operating System must be word aligned The assembler implements the EVEN directive by inserting before the code or data where necessary l byte NOP no operation instruction 90h Here is an example EVEN Buffer DW 256 DUP 0 The EVEN directive can be used only in a segment whose alignment type as specified in the SEGMENT directive is WOR
82. ce text and a reassembly For example the insertion of an attribute coercion such as BYTE PTR or FAR PTR is often sufficient correction However the safest course is to follow programming practices that make it unnecessary for the assembler to guess This can be done as follows Put EQU directives early in programs Put EXTRN directives early in programs Within multisegment source file try to position the data segments and hence the variable definitions before the code segments Forward References 55 6 INSTRUCTION FORMAT The instruction format of the 8086 uses up to three fields to specify the location of an operand in a register or in memory The assembler sets all three fields automatically when it generates code These fields when used make up the second byte of an instruction which is called the MOD R M byte The two most significant bits of the MOD R M byte are the MOD field which specifies how to interpret the R M field The next three bits are occupied by the REG field which specifies an 8 or 16 bit register as an operand Instead of specifying a register the REG field can in some instructions refine the instruction code given in the first byte of an instruction The next three bits are occupied by the R M field which can specify either a particular register operand or the addressing MODe to select a memory operand This occurs in combination with the MOD field The MOD and
83. ck formats and register usage in the run time environment to be satisfied These assumptions are automatically satisfied by the compiled languages of the Convergent System however the assembly language programmer must follow some simple rules if virtual code segment management is to be used If a program contains no calls to overlaid modules from assembly language code or from procedures called from assembly language code then the presence of assembly language code in the program has no affect on the operation of virtual code segment management services In this case there are no additional rules that the assembly language programmer must follow An overlay fault is defined as a call to or return to an overlaid module that is not in memory An overlay fault automatically invokes virtual code segment management services to read the required overlay into memory and possibly to discard one or more other overlays from memory The virtual code segment management services do this in part by examining the run time stack Therefore if there are control paths in a program such that the stack may contain entries created by assembly language code when an overlay fault occurs the assembly language programmer is subject to additional rules These are the rules Accessing Standard Services 81 82 The register usage conventions discussed earlier must be followed The intervention of virtual code segment Management services preserves the registers SS
84. cumulator is the high order or low order byte of AX BX CX or DX Addressing Operands can be addressed in several different ways with various combinations of base registers BX and BP index registers SI and DI displacement adding an 8 or 16 bit value to a base or index register or to both and direct offset 16 bit addresses used without the base or index register A two operand instruction has a source operand and a destination operand as in MOV destination source The source operand can be an immediate value a constant that is part of the instruction itself such as the 7 in MOV CX 7 a register or a memory reference If the source is an immediate value then the destination operand can be either a register or a memory reference Introduction 5 2904350 40 sis Aqeuy I I 195 0 40 34ed 1 49 INLLA 1 22 0 1 e 40 xapul 319 91 40 8 um gg 2574 5 15592044 1744092 ayy s wy pue 938 GOW 30 5 404 y dstpe IS d8 sssaappe 2341328133 010 24 3 451 0 esf 010 933 ujuii 195440 e 1 9349 2 2 1 4510 10 00 SSTARRE 5 3 4 Q spuesado T M eseq 319 91 e 4915 ueau e uo zeurysap
85. d name names data and is assigned a type attribute according to the record or structure definition The main uses of the LABEL directive illustrated below are accessing variables by an alternate type defining FAR labels and accessing code by an alternate distance for example defi ning a FAR label with the same segment and offset values as an existing NEAR label LABEL with Variables The assembler uses the type of a variable in determining the instruction assembled for manipulating it You can cause an instruction normally generated for a different type to be assem Data Definition 35 bled by using LABEL to associate an alternative name and type with a location For example the same area of memory can be treated sometimes as a byte array and sometimes as a word array with the definitions rgw LABEL WORD rgb DB 200 DUP 0 The data for this array can be referred to in two ways ADD AL rgb 50 Add fiftieth byte to AL ADD AX rgw 38 Add twentieth word to AX LABEL with Code A label definition can be used to define a name of type NEAR and FAR This is only permitted when a CS assumption is in effect the CS assumption not the segment being assembled is used to determine the SEG and OFFSET for the defined name For example Place LABEL FAR SamePlace MUL CX BP introduces Place as a FAR label otherwise equivalent to the NEAR label SamePlace Label Addressability The addressability of a label is determi
86. d raqej Oz2 0 443X 13210 dNONO LNSWOSS RIIEA UJ 0 4237 fiquo saa45e4eq5 Z lt sbulu435 BT T 443X PI tj 409 afue 003 an eA ZT1 0 4437 83ntosqe aq 35nu uorssaadx3 Oy 0 4437 SOIN3 1N3H938 0 4437 19qwhs 30 uor3rTUTJapau pr PAu pT 0 4437 3usw6as a n osqe 40 urbruo Ey 0 4437 9043 2059 P9u23eustu ET 0 4437 Burasau JaN3 20ud 1t 0 443 asnu 3unssv 04 prie u OT 1 4437 uodo azeuado HLONAT pue 3715 60 0 4437 zou po n03 04 5u 4 jaa Q 4137 TOqWAS paurgapun 0 1 4437 uorss iadx ssaippe uodn aqeuado 30 asn 90 0 4437 uOtssaudxa UT asm eg 1 2437 40 UOoTZedado pO O 4437 40448 1941834 EO 0 423 094 5240 3 20 o 443 30442 zequhS TO 1 443 3u835u02 3r4 unu prie u OO T 443 paurjap repaua 340m 243 oq S N3 mosuedn moauydnsy ga aaay Sup 4434935 43usVy SQN3 52 r 385330
87. e BP DI BX SI Index BP SI BX DI Displacement BP DI DISP BX SI DISP Base BP SI DISP Index BX DI DISP Add two clocks for segment override Add four clocks for each 16 bit word transfer with an odd address Instruction Set A 3 Alternate Mnemonics These instructions have synonymous alternate mnemonics Table A 2 Alternate Mnemonics Instruction Synonym Description JA JNBE 1 not below or equal JNB 1 not below JNC if not carry JB JNAE if not above or equal JB JC if carry JBE JNA if not above JG JNLE if not less or equal JGE JNL if not less JL JNGE if not greater or equal JLE JNG if not greater JNZ JNE if not equal JPE JP if parity JPO JNP if no parity JZ JE if equal LOOPNZ LOOPNE CX times while not equal LOOPZ LOOPE CX times while equal REPZ REP Repeat string operation REPZ REPE Repeat string operation while equal REPNZ REPNE Repeat while CX 0 and ZF 1 SHL SAL Byte shift EA left 1 bit A 4 Assembly Language Manual Table A 3 Instruction Set in Numeric Order of Instruction Code Page 1 of 7 Memory Instruc Operand Summary Clocks Flags Organization tion ODITSZAPC 00 MOD REGR M ADD bEA REG bEA bEA DbREG 16 EA 3 xxxxx 01 MOD REGR M wEA WEA WREG 16 EA 3 02 REGR M REG bEA bREG bREG bEA 9 EA 3 X 03 MOD REGR M REG wEA wREG wREG wEA 9 EA 3 X xxxxx
88. e GROUP directive the OFFSET operator does not yield the offset of a variable within the group It returns rather the offset of the variable within its segment Use the GROUP override operator to get the offset of the variable within the group Here is an example DGroup GROUP Data SEG data SEGMENT xyz DB 0 DW xyz Offset within segment DW DGroup xyz Offset within group data ENDS ASSUME CS SEG DS DGroup MOV CX OFFSET xyz Loads seg offset of xyz MOV CX OFFSET Dgroup xyz Loads group offset of xyz LEA CX xyz Also loads group offset xyz You may not use forward references to group names 52 Assembly Language Manual Record Operators The use of operators with records is illustrated in Section 3 The definitions are repeated here for completeness Associated with each field of a record are the following Shift count This is the field name of the record MASK operator This operator has one argument which is a field name It returns a bit mask that consists of 1 s in the bit positions included by the field and 0 s elsewhere WIDTH operator This operator returns the number of bits record or field If the definition of a record formats 8 bits the record is of type BYTE and if it formats 16 bits of type WORD Operator Precedence in Expressions The assembler evaluates expressions from left to right It eval uates operators with higher precedence before other operators that come directly bef
89. e corresponding macro Body with parameter names of the macro definition replaced by arguments from the macro invocation LOCAL Declaration The purpose of macros is to permit the definition of a pattern the body of the macro that is to be recreated at each invocation Macro Assembler 63 of the macro Thus two invocations of a macro normally expand to source text differing only insofar as the parameters of invocation differ Consider however the definition DEFINE CallNTimes n subr AX n Again DEC AX JZ Done PUSH AX CALL subr POP AX Done An invocation such as CallNTimes 5 FlashScreen expands to MOV 5 DEC AX JZ Done PUSH AX CALL FlashScreen POP AX JMP Again Done A second invocation of this macro produces an error because it doubly defines the labels Again and Done The problem is that in this case we want a new unique pair of labels created for each invocation This can be done in a macro definition using the LOCAL declaration The proper form is illustrated by DEFINE CallNTimes n subr LOCAL Again Done MOV AX n Again DEC AX JZ Done PUSH AX CALL subr POP AX JMP Again Done Conditional Assembly In a manner carefully integrated with macro processing the assembler also supports assembly time expression evaluation and string manipulation facilities These include the functions EVAL LEN EQS GTS LTS NEX GES LES and SUBSTR
90. e evaluated in either of two modes expanded and unexpanded When the function invocation or definition is preceded by the mode used is expanded when preceded by the mode used is unexpanded In either case actual parameters expanded and substituted for formal parameters within the body of invoked macros In unexpanded mode there is no further expansion In expanded mode macro processing specified in the body of a macro is also performed For example let the macros F and G be defined by DEFINE F X G X DEFINE G Y Y 4 Y Then the invocation F 1 expands to G 1 whereas the invocation 1 expands to 1 1 Nested Macro Expansion When macro expansion is nested inner expansions are according to the mode they specify completion of inner expansions processing continues in the mode of the outer expansion An alternate way of saying this is that the parameters of user defined macros are always processed in expanded mode The bodies are processed in expanded mode when a invocation is used and in unexpanded mode when a invocation is used It is also possible to invoke built in functions in either expanded or unexpanded mode For each built in function some arguments Macro Assembler 73 classified as parameter like and therefore processed in expanded mode whereas others are classified as body like and therefore processed in expanded mode only if the invocation is with
91. e for an EXTRN to be NEAR Variables This section covers the use of simple indexed and structured variables as operands If you are unfamiliar with how to define and initialize variables review Section 3 Simple Variables An unmodified identifier used the same way it is declared is a simple variable Here is an example wData DW AB MOV BX wData Indexed Variables simple variable followed square bracketed expression is an indexed variable The expression in square brackets is a constant or constant expression base register as BX or BP or an index register as SI or DI a base or index register plus or minus a constant expression in any order or a base register plus an index register plus or minus a constant or constant expression in any order When you use indexed variables be aware that the indexing is 0 origin that is the first byte is numbered 0 the index is always a number of bytes and the type is the type of the simple variable to which the index is applied For example if the table Primes is defined by Primes DW 250 DUP and register BX contains the value 12 then the instruction MOV Primes BX 17 sets the twelfth and thirteenth bytes of Primes which are the bytes of the seventh word in Primes to 17 Double Indexed Variables Double indexed variables use a sum of two displacements to address memory Here is an example Primes BX SI 5 Most forms of double indexing can
92. e instruction being assembled In 8086 instruction formats as in data words the least signifi cant byte of a word is at the lower memory address MOV CH 5 8 bit immediate value to register ADD DX 3000H 16 bit immediate value to register AND Table BX OFF00h 16 bit immediate value where Table is a WORD through BX 16 bit displacement XOR Table BX DI 100 7 16 bit immediate through BX DI Table 100 Register Operands The 16 bit segment registers are CS DS SS and ES The 16 bit general registers are AX BX CX DX SP BP SI and DI 8 bit general registers are AH AL BH BL CH CL DH and DL The 16 bit pointer and index registers are BX BP SI and DI The 1 bit flag registers are AF DF IF OF SF TF and ZF Segment base addresses are contained in segment registers and must be initialized by the programmer Arithmetic and logical operations can be performed using each of the general 8 bit general 16 bit and pointer and index 16 bit registers So even though AX is often called the accumulator there are actually eight separate 16 bit accumulators and eight 8 bit accumulators as listed above Each of the 8 bit accumula tors is either the high order H or the low order L byte of AX BX CX or DX After each instruction the flags are updated to reflect conditions detected in the processor or any accumulator See Appendix A and the Central Processing Unit for the flags affec
93. e signed twos complement self relative displacement SHORT can be used in conditional jumps jumps and calls This means that the target must lie within a range no more than 128 behind the beginning of the jump or call instruc tion and no more than 127 bytes in front of it See Memory Operands to JMP and CALL Operands in this Section for more on SHORT 50 Assembly Language Manual THIS The single argument of the THIS operator is a type BYTE WORD DWORD or distance NEAR FAR attribute A data item with the specified type or attribute is defined at the current assembly location Here are the formats THIS type THIS distance The segment and offset attributes of the defined data item are respectively the current segment and the current offset The type or distance attributes are as specified Thus the two statements byteA LABEL BYTE byteA EQU THIS BYTE have the same effect Similarly is equivalent to THIS NEAR In the example EQU THIS FAR E2 REPNZ SCASW the two addresses El and E2 differ exactly in that El is FAR whereas E2 is NEAR Value Returning Operators Here are the value returning operators TYPE It accepts one argument either a variable or a label TYPE returns for variables 1 for type BYTE 2 for type WORD 4 for type DWORD and the number of bytes for a variable declared with a structure type TYPE returns for labels either 1 or 2 representing respectively NEAR or
94. eatures of FORTRAN Is an interpreted language such as BASIC suitable Will the system programming and data structuring facilities of Convergent Pascal be particularly valuable in the program to be written Should the program be divided into parts to be written in different languages and combined by the Linker If the program or program part requires direct access to processor registers and flags then assembly language is the best choice To the extent that memory utilization and object code efficiency are more important than development speed and program mer productivity assembly language is a better tool than Pascal or FORTRAN It is rarely the case that an entire application system ought to be written in assembly language The programmer should determine those parts in which direct access to machine features efficien cy and memory utilization are overriding concerns and implement those parts in assembly language while writing the remainder of the application in an appropriate high level language Introduction 1 Features of the Assembly Language The Convergent assembly language features a powerful instruction set sophisticated code and data structuring mechanisms strong typing the ability to check that the use of data is consistent with its declaration a conditional assembly facility and a macro language with extensive string manipulation capabilities Design of the Instruction Set A complete descript
95. ee the Utilities Manual for details Segment Nesting You can code a portion of one segment start and end another and then continue with the coding of the first However there is only lexical not physical nesting since the combination rules given above are always followed Lexically nested segments must end with an ENDS directive before the enclosing SEGMENT directive is closed with its ENDS directive The fundamental units of relocation and linkage are segment elements linker segments class names and groups An object module is a sequence of segment elements Each segment element has a segment name An object module might consist of segment elements whose names are B C and D The Linker combines all segment elements with the same segment name from all object modules into a single entity called a linker segment A linker segment forms a contiguous block of memory in the Fun time memory image of the task For example you might use the Linker to link these two object modules 14 Assembly Language Manual Object Module 1 containing segment elements B C D Object Module 2 containing segment elements C D E Linkage produces these four linker segments Linker Segment B consisting of element 1 Linker Segment C consisting of elements Cl C2 Linker Segment D consisting of elements D1 D2 Linker Segment E consisting of element E2 In each of these cases xi denotes the segment element x in module i T
96. eplaced by the high order bit and goes into the low order bit If an RCR is used the value in CF is replaced by the low order bit and goes into the high order bit This is useful in multiple word arithmetic operations In other rotates and shifts the value in CF is lost Overflow Flag OF signed operation results in an overflow OF is set otherwise it is cleared That is an operation results in a carry into the high order bit of the result but not a carry out of the high order bit or vice versa Parity Flag PF If the modulo 2 sum of the low order eight bits of an operation is 0 even parity PF is set otherwise it is cleared odd parity 60 Assembly Language Manual Following certain instructions the number of one bits in the destination is counted and the parity flag set if the number is even and cleared if the number is odd Sign Flag SF If the high order bit of the result is set SF is set otherwise it is cleared Following an operation the high order bit of its target can be interpreted as a sign The SF flag is set equal to this high order bit by instructions that affect SF Bit 7 is the high order bit of a byte and bit 15 is the high order bit of a word Zero Flag ZF If the result of an operation is 0 ZF is set otherwise it is cleared Following certain operations if the destination is zero the zero flag is set and if the destination is not zero the zero flag is cleared Both ZF
97. estore The Operator s Guide addresses the needs of the average user for operating instructions It describes the workstation switches and controls keyboard function and floppy disk handling Documentation Guide 1 1 INTRODUCTION This Manual describes the Convergent assembler and assembly lang uage The Manual is directed towards readers who understand some assembly language reasonably well To understand an assembler it is usually helpful to first under stand the machine architecture of the target CPU you are not already familiar with the machine level architecture of the Convergent Information Processing System you can find it useful to read the Central Processing Unit That document also contains a brief discussion of assembly language programming at an elemen tary level and it describes the instruction set in detail So if this Manual is too difficult try reading the Central Processing Unit Since this Manual is primarily a reference work we do not expect you to read it straight through But if you are not entirely conversant with Convergent assembly language you should initially read the first four sections Choice Among Convergent Languages A programmer working with a Convergent Information Processing System has many different languages to choose among The choice among languages involves several considerations Does the program require the unique business features of COBOL or the scientific f
98. esult undefined code should not rely on these values replaced from memory e g POPF blank unaffected Z cC x OQ mn Instruction Set A 1 These are the flags Auxiliary Carry flag Parity flag Carry flag 0 Overflow flag D Direction flag 1 Interrupt enable flag T Trap flag S Sign flag Z Zero flag A P These symbols used the tables Symbol Interpretation bAddr bData bEA bREG CE Ext b FLAGS off Sign w sba SR wAddr wData wEA wREG l6 bit offset within a segment of a word addressed without use of base or indexing byte immediate constant effective address of a byte 8 bit register AH AL BH CH CL DH or DL value 0 or 1 of the carry flag word obtained by sign extending byte b values of the various flags 16 bit offset within a segment word of all 0 s if is positive all 1 s if w is negative Segment base address segment register CS DS ES or SS 16 bit offset within a segment of a word addressed without use of base or indexing word immediate constant effective address of a word 16 bit register BX CX DX SP BP SI or DI A 2 Assembly Language Manual Effective Address EA calculation time is according to Table 1 below Table A 1 Effective Address Calculation Time EA Components Clocks Displacement only 6 Base or Index only 5 Displacement Base or Index BX BP SI DI Bas
99. gt Macro Assembler 67 Interactive Assembly IN and OUT The macro capability supports interactive assembly based on the two functions IN and OUT which are used respectively to read input from the keyboard during assembly and to display information on the video display during assembly When using IN and OUT it is important to understand the two pass nature of the assembler Since the assembler makes two passes over the text it expands all macros and macro time functions twice This works but the programmer must take care 1 that expressions involving macro time variables generate the same code or data in both passes and 2 that IN and OUT are not expanded twice The programmer may control these effects using the specially defined macro variables PASS1 and PASS2 whose values are During First Pass During Second Pass PASS1 1 0 552 0 1 is example to illustrate these facilities Suppose you want to prompt the user for a number at the beginning of an assembly then use this input string later Do this by inserting near the beginning of the source this code SIF 561 EQ 1 THEN OUT Enter table size in bytes SSET sTable IN FI The OUT and IN execute during the first pass only and the user s input becomes the value of the macro variable sTable this can later be referred to by sTable Comments You can write macro time comments The format is either text not cont
100. he ordering of the various linker segments is determined by class names A class name is an arbitrary symbol used to desi gnate a class All the linker segments with a common class name and segment name go together in memory For example if Bl Dl and E2 have class names Red while Cl has class name Blue then the ordering of linker segments in memory is B D E C If you look inside the linker segments you see that the segment elements are arranged in this order Bl Dl D2 E2 Cl C2 If two segment elements have different class names then they are considered unrelated for purposes of these algorithms even though they have the same segment name As you see from this segment names and class names together determine the ordering of segment elements in the final memory image The next step for the Linker is to establish how hardware segment registers address these segment elements at run time A group is a named collection of linker segments that is addres sed at run time with a common hardware segment register To make the addressing work all the bytes within a group must be within 64K of each other Several linker segments can be combined into a group For example if B and C were combined into a group then a single hardware segment register could be used to address segment elements Bl Cl and C2 Segment class and group names can be assigned explicitly in assembler modules using appropriate assembler direc
101. i control ROM expansion and RAM expansion keyboard video monitor Multibus interface communications interfaces power supply and environmental characteristics of the workstation The Peripherals Hardware Manual describes the disk subsystems It specifies the disk controller motherboard controller boards for the floppy disk and the Winchester disks power supplies disk drives and environmental characteristics The Central Processing Unit describes the main processor the 8086 It specifies the machine architecture instruction set and programming at the symbolic instruction level The cCTOS Operating System Manual describes the operating system It specifies services for managing processes messages memory exchanges tasks video disk keyboard printer timer communications and files In particular it specifies the standard file access methods The Executive Manual describes the command interpreter the program that first interacts with the user when the system is turned on It specifies commands for managing files and invoking other programs such as the Editor and the programming languages The Editor Manual describes the text editor The BASIC FORTRAN COBOL Pascal and Assembly Language Manuals describe the system s programming languages Each manual specifies both the language itself and also operating instructions for that language For Pascal the manual is supplemented by a popular te
102. ion of the instruction set is given in Appen dix A and in the Central Processing Unit This assembly language differs from most other assembly lan guages which usually have one instruction mnemonic for each operation code opcode In this assembly language a particular instruction mnemonic can be assembled into any of several opcodes the type of opcode depends on the type of operand This assembly language is a strongly typed language because mixed operand types are not permitted in the same operation as for example moving a declared byte to a word register You cannot inadvertently move a word to a byte destination thereby overwriting an adjacent byte nor can you move a byte to a word destination thereby leaving meaningless data in an adjacent byte However if you need to override the typing mechanism there is a special operation called PTR which allows you to do this See Section 4 The assembly language makes it possible to convey much informa tion in a single easy to code instruction Consider this instruction SUB BP SI field4 CH The contents of the 8 bit register CH are subtracted from a memory operand registers BP and SI are used to calculate the address of the memory operand and the identifier field4 and the dot operator are used to designate symbolically an offset within the structure pointed to by BP and SI The register BP points within the run time stack and is used as is the case in this exa
103. is a jump instruction for an overlay in memory thus an invocation of a procedural argument for such a procedure results in a call to a jump instruction which then transfers control to the procedure The virtual code segment management facility arranges that the operation code for an overlay not in memory is a call since the address part of such a stub is the address of the virtual code segment management facility the invocation of such a procedure results instead in the activation of the virtual code segment management facility 84 Assembly Language Manual 10 ASSEMBLY CONTROL DIRECTIVES The Convergent assembly language contains facilities to control the format of the assembly listing and to sequence the reading of included source files These facilities are invoked by assembly control directives Assembly control directives must occur on one or more separate lines within the source i e not intermixed on the same line as other source code An assembly control line must begin with the character Such a line may contain one or more controls separated by spaces Here is an example STITLE Parse Table Generator PAGEWIDTH 132 EJECT The meanings of the individual controls are described below EJECT The control line containing EJECT begins a new page GEN All macro calls and macro expansions including intermediate levels of expansion appear in the listing NOGEN Only macro calls not expansions are listed However if
104. ited by PROC and ENDP state ments Thus the extent of a procedure is apparent Here is an example WriteFile PROC RET WriteFile ENDP Procedures can be nested but must not overlap Introduction 7 WriteFile PROC RET WriteLine PROC WriteLine ENDP RET WriteFile ENDP Macros The macro capability of the assembler is used to define abbrevi ations for arbitrary text strings including constants expres sions operands directives sequences of instructions comments etc These abbreviations can take parameters they are string functions that are evaluated during assembly Fields of instruction can be parameters of macros Macro calls can be nested Macro definitions can be saved in a file By including such a macro library the programmer can customize the assembler to include frequently used expressions instruction sequences and data definitions The macro facility also provides interactive assembly by means of a macro time console I O facility Example See Figure 1 2 for an example of a complete assembly program Invoking the Assembler from the Executive Invoke the assembler with the Executive s assemble command The following form appears Assemble Source files Errors only GenOnly NoGen or Gen Object file List file Error file List on pass 1 8 Assembly Language Manual wezboid go z eunbr4 p s32 sap
105. ith a total width of up to 16 bits A byte is allocated for each instance of a record of the first class and a word for each instance of a record of the second class The data of each record instance is right justi fied within the allocated memory The definition of a record can include a specification of how instances are to be initialized This specification is given with the optional default clause For example this definition HashEntry RECORD state 2 3 sKey 4 rbKey 9 might be used in setting up a hash table Each entry has 2 bit State field a 4 bit size of key sKey and 9 bit relative byte of key in page rbKey The state field being two bits wide can hold four values The state field is explicitly speci fied to default to 3 The other fields are assigned the implicit default value 0 since no explicit default is specified A field eight bits wide can have a single character as its default value as in bData 8 a When a record is declared the assembler associates with its field names these special values the width of the field Data Definition 37 the bit position of the right end of the field a mask constant for extracting the field from an instance of the record The width is computed with the WIDTH operator the mask with the MASK operator and the bit position with the field name itself Thus with HashEntry as above the following holds state ODh sKey 9h rbKey Oh MASK st
106. lassname before any others save Code and Const See lines 27 36 Note that EXTRN declarations for data declared in object module procedures must be embedded in the data SEGMENT ENDS declarations At any time that call is made to an object module procedure DS and SS must contain the segment base address of a special group named DGroup This group contains the Data Const and Stack segments and is declared as illustrated in line 53 In addition at the time of a call to an object module procedure SP must address the top of a stack area to be used by the called procedure A correct initialization of SS SP and DS is illustrated in lines 62 68 These values need not be maintained constantly but if they are changed they should be restored using the appropriate top of stack value in SP if it has changed for any call to an object module procedure Note that the Operating System s interrupt handlers save the user registers by pushing them onto the stack defined by SS SP Therefore some valid stack must be defined at all times that interrupts are enabled Interrupts and the Stack If interrupts are enabled interrupt routines use the stack as defined by SS and SP Therefore you should never even temporarily put data in the stack segment at a memory address less than SS SP Use of Macros The instructions to set up parameters on the stack before a call and to examine the result on return have a number of cases as discussed above
107. ld default values from the structure definition lt 8 10 gt Set initial values of the first and third fields to 8 and 10 respectively but use the default from the definition for the middle field The initial field values can be constants constant expressions or the indeterminate initialization One byte strings can override any field Two byte strings can override any DW or DD field Multibyte strings can override a DB field but only if the overriding string is no longer than the overridden string The number of copies of the structure to be allocated is dup count it must evaluate to a positive integer 42 Assembly Language Manual 4 OPERANDS AND EXPRESSIONS Operands The instruction set of the 8086 makes it possible to refer to operands in a variety of ways The instruction set is described in the Central Processing Unit Either memory or a register can serve as the first operand destination in most two operand instructions while the second operand source can be memory a register or a constant within the instruction There are no memory to memory operations A 16 bit offset address can be used to directly address operands in memory Base registers BX or BP or index registers SI or DI or both plus an optional 8 or 16 bit displacement constant can be used to indirectly address operands in memory Either memory or a register can receive the result of a two operand operation Any register or memory operand
108. le here is a structure that implements the request block for the Close File operator used with the CTOS Operating System RqCloseFile STRUC sCntInfo DW 2 nReqPbCb DB 0 nRespPbCb DB 0 userNum DW exchResp DW ercRet DW rqCode DW 10 fh DW RqCloseFile ENDS rqCloseFilel RqCloseFile lt 1 3 gt Nondefault values are userNum 1 exchResp 3 MOV AX fhNew MOV rqCloseFilel fh Fill in the fh field if an rq CMP rqCloseFilel ercRet ercOk Is the error return equal to the value ercOK 40 Assembly Language Manual Structures are not restricted to use with statically allocated data For example BP rbRqCloseFile rqCode 10 Examine rqCode in an anonymous instance of RqCloseFile that s on the Stack Here is the general format of the STRUC ENDS statement pair together with the enclosed DB DW and DD directives structure name STRUC 2 default field name DB DW DD dup count DUP default 1 structure name ENDS In this case DB DW and DD are used just as defined earlier with the exception that there cannot be any forward references Matching STRUC ENDS pairs must have the matching structure names Field names are optional if used they must be unique identifiers Default Structure Fields Default values for structure fields are as specified in the DB DW or DD directives Because the STRUC ENDS pair does not allo cate memory these default initializations have no im
109. mediate effect The defaults are used to initialize memory later when the structure name is used as a memory allocation operator as in the allocation of rqCloseFilel above Overridable Structure Fields When memory is allocated certain structure field default values can be overridden by initial values specified in the allocation expression these are called simple fields Other field values that include a list or a DUP clause cannot be overridden A DB character string is considered simple Here are some examples of what can and cannot be overridden Super STRUC DW Simple field override okay DB Message Simple character string field override okay DD 5 DUP Multiple field no override DB 7 2 3 Multiple field no override Super ENDS Data Definition 41 Initializing Structures After structures have been declared they can be allocated and initialized with the structure name as operator The general format is similar to that for record initialization There are two formats Format 1 name structure name lt init gt Format 2 with duplication name structure name dup count PUP lt init 1 gt In both formats the first byte or word depending on the struc ture definition of the allocated memory is optionally named The structure definition to be used is specified by structure name Finally the operand is a possibly empty list of initial field values For example lt gt Use fie
110. meric Order of Instruction Code bData wData stack stack stack stack stack stack stack stack if overflow if no overflow if below if above or equal if zero if not zero Page 2 of 7 16 16 16 16 16 16 or or or or or or Pe gt P Flags ODITSZAPC DS gt lt gt lt gt lt gt lt DX PX gt lt gt lt gt lt P4 gt lt gt lt gt gt gt x C XXXXX XXXXX XXXXX UUXUX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX Table A 3 MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD MOD Instruction Set in Numeric Order of Instruction Code 000 R M 001 R M 010 R M 011 R M 100 R M 101 R M 110 R M 111 R M 000 R M 001 R M 010 R M 011 R M 100 R M 101 R M 110 R M 111 R M 000 R M 001 R M 010 R M 011 R M 100 R M 101 R M 110 R M 111 R M 000 R M 001 R M 010 R M 011 R M 100 R M 101 R M 110 R M 111 R M REGR M REGR M REGR M REGR M REGR M REGR M REGR M REGR M OSR R M 1 R M OSR R M R M 000 R M 001 R M 010 R M 011 R M SUB CMP ADD ADC SBB SUB TEST TEST XCHG XCHG MOV MOV MOV MOV MOV not LEA MOV not POP not not not bDISP bDISP bDISP bDIS
111. mple when the operand is on the stack The segment register for the stack segment is SS so the 16 bit contents of SS are automatically used together with BP in addres sing the memory operand The 16 bit contents of register SI are the offset of the data from the top of the stack That is the contents of BP and SI are added in the effective address calculation In this context the dot operator refers to a structure See Section 3 for a description of structure definitions The 2 Assembly Language Manual identifier that follows field4 identifies a structure field Its value gives the relative distance in bytes from the begin ning of the structure to field4 Offset values for each field of the structure relative to the beginning of the structure are generated by the assembler In this way the structure can be used as a pattern of relative offset values a storage template This instruction combines the contents of the stack segment reg ister SS the end of stack register BP the index register SI and the offset of field4 to form an absolute machine address The contents of the 8 bit register CH are subtracted from the byte thus addressed This instruction includes opcode base register index register structure displacement and relative offset type information direction register to memory and source register The instruction assembles into only three bytes Arrays Arrays of bytes words doublewords str
112. n example 16 Assembly Language Manual Tables SEGMENT xTab DW 100 DUP 10 yTab DW 500 DUP 20 Tables ENDS ZSeg SEGMENT zTab DW 800 DUP 30 ZSeg ENDS sum SEGMENT ASSUME CS Sum DS Tables ES NOTHING Start MOV BX xTab ADD BX yTab MOV AX SEG zTab MOV ES AX MOV ES zTab 35 sum ENDS In this example the ASSUME directive 100 word array initially 10 s 500 word array initially 20 s 800 word array initially 30 s Sum addressable through CS and Tables through DS No assumption about ES xTab addressable by DS defined in Tables yTab addressable by DS defined in Tables Now AX is the proper segment base address to address references to ES now holds the Segment base address for ZSeg zTab must be addressed with explicit segment override the assembler doesn t know what segment register to use automatically 1 Tells the assembler to use CS to address the instructions in the CS Sum For example long call segment Sum This fragment of program does CS must previously have been set to point to the segment CS is often initialized by a long jump or not load 2 Tells the assembler to look at DS for the symbolic references to xTab and yTab Loading Segment Registers The CS register is CALL an interrupt hardware RESET loaded by a long jump INT n or external Programs and Segments JMP a long call interrupt or by a
113. n offset The segment base address must be in one of the four segment registers CS DS ES or SS When a program gets a data item from memory the hardware com bines the 16 bit offset and the 16 bit segment base address as follows 20 bit physical address 16 segment base address offset For example if a program is assembled at offset 2400h within the data segment and if segment register DS is loaded with the value 3E00h then the physical address of the data is 16 3E00h 2400h 40400h 4 Assembly Language Manual The programmer is generally not concerned with this physical address Registers The registers are 16 bit segment CS DS SS ES 16 bit general AX BX CX DX SP BP SI DI 8 bit general AH AL BH BL CH CL DH DL Base and index 16 bit BX BP SI DI and l bit flag AF DF IF OF PF SF ZF Segment registers contain segment base addresses and must be appropriately initialized at run time If assembly language is used only to implement subroutines for a main program written in a high level language this initialization is automatic Each of the 16 bit general 8 bit general and base and index registers can be used in arithmetic and logical operations We frequently call AX the accumulator but the processor actually has eight 16 bit accumulators AX BX CX DX SP BP SI DI and eight 8 bit accumulators AH AL BH BL CH CL DH DL Each 8 bit ac
114. nd if there is one is the operand acted upon by the instruction The Summary column contains brief summary of each instruction Parentheses surrounding an item means the contents of For example EA means the contents of memory location EA and SS means the contents of register SS The infix operators OR XOR etc denote the standard arithmetic or logical operation CMP denotes a subtraction wherein the result is discarded and only the values of the flags are changed TEST denotes a logical AND wherein the result is discarded and only the values of the flags are changed The clocks column is the clock time for each instruction See Table A 1 below Where two clock times are given in the conditional instructions the first is the time if the jump or loop is performed and the second if it is not In all instructions with memory EA as one of the operands a second clock time is given in parentheses This is because in all these instructions memory may be replaced by a register In such cases the faster clock time applies Where repetitions are possible a second clock time is also given in parentheses in the form where x is the base clock time is the clock time to be added for each repetition and rep is the number of repetitions The flags column enumerates the flag conditions according to this code set to 1 cleared to 0 altered to reflect operation r
115. ned by 1 its declaration as NEAR or FAR and 2 its use under the same or different ASSUME CS directive as its declaration The four possibilities of code for each are shown in Table 3 2 Table 3 2 Target Label Addressability Near Label Far Label Same NEAR Jump Call NEAR Jump ASSUME CS FAR Call Different FAR Jump ASSUME CS Not allowed FAR Call A NEAR jump or call is assembled with a 1 or 2 byte displacement using modulo 64K arithmetic 64K bytes of the current segment can be addressed as NEAR 36 Assembly Language Manual A FAR jump or call is assembled with a 4 byte address The address consists of a 16 bit offset and 16 bit segment base address An entire megabyte of memory can be addressed as FAR The semantics of PROC ENDP directives are discussed in Section 2 Records A record is a format used to define bit aligned subfields of bytes and words The two steps in using records are 1 define and name a record format and 2 invoke the record name as an operator thereby allocating and initializing memory Define a record by writing record name RECORD field name width default Neither record name nor any of the field names can conflict with existing names The sum of the widths of the fields can not exceed 16 bits Each width can be an expression but must not make forward references The assembler divides records into two classes those with a total width of up to 8 bits and those w
116. ns source and object code for all source lines Assembly produces an object file and a list file The names of the object and list files are specified as described below The default for Errors only is No that is a full listing GenOnly NoGen or Gen Fill in the GenOnly NoGen or Gen field to specify how the results of macro expansion are listed This setting can also be made in the source with the assembly control directives S GENONLY NOGEN and SGEN In GenOnly mode the results of macro expansion are listed In NoGen mode the listing contains the unexpanded macro invocations In Gen mode the listing contains invocations and full expansions as well as intermediate stages of expansion This last mode is most useful in debugging complex macros Note that these controls affect only the content of the listing the result of full expansions is always assembled to produce the object code The default for GenOnly NoGen or Gen is GenOnly Object file Fill in the Object file field to specify to which object file to write the object code that results from the assembly The default is the last source file That is if you do not specify an object a default object file is chosen as follows treating the last source name as a character string strip off any final suffix beginning with the character period and add the characters Obj The result is the name of the file For example if the last source file is 1
117. ny balanced strings and 4 locals is optional and if present consists of the reserved word LOCAL and a list of macro identifiers separated by spaces In all macro definitions illustrated above the pattern has the form idl id2 idn and all invocations are of the form ident paraml param2 paramn Here are examples to illustrate other cases The definition 70 Assembly Language Manual DEFINE DWDW A AND B DW A DW B requires an invocation such as SDWDW 1 AND 2 which expands to DW 1 DW 2 Here the delimiter preceding the formal parameter A and following the formal parameter B is an implicit space The delimiter between the A and the B is the identifier delimiter AND Bracket and Escape The macro processor has two special functions bracket and escape which are useful in defining invocation patterns and parameters The bracket function has the form text where text is balanced The text within the brackets is treated literally Thus given the definition DEFINE F A F 2 the invocation 1 expands to F 2 since the F 2 is embedded within a bracket function and hence not treated as another macro call Similarly the definition DEFINE DWDW A AND B DW A DW B declares three formal parameters A AND and B with implicit blank delimiters whereas the definition DEFINE DWDW A AND B DW A DW B treats the AND as a literal delimiter
118. ore or after To override the normal order of precedence use parentheses In order of decreasing precedence here are the classes of operators 1 Expressions within parentheses expressions within angle brackets records expressions within square brackets the structure dot operator and the LENGTH SIZE WIDTH and MASK operators 2 PTR OFFSET SEG TYPE THIS and name segment override 3 Multiplication and division MOD SHL SHR 4 Addition and subtraction 5 Relational operators EQ NE LT LE GE 6 Logical NOT 7 Logical AND 8 Logical OR XOR 9 SHORT Operands and Expressions 53 EQU Directive Use EQU to assign an assembly time value to a symbol This is the format name EQU expression Here are examples to illustrate the cases y EQU 2 7y is made a synonym for z EQU BX DI 3 XX is a synonym for an indexed reference note that the right side is evaluated at use not at definition x EQU EX Bar BP 2 Segment overrides are also allowed EQU TYPE y 5 Random expressions are allowed EQU AX Synonyms for registers are allowed PURGE Directive Use the PURGE directive to delete the definition of a specified symbol After a PURGE the symbol can be redefined The symbol s new definition is used by all occurrences of the symbol after the redefinition You cannot purge register names reserved words or a symbol appearing in a PUBLI
119. ort DX Bus lock prefix 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 20 4 bit 83 60 11 8 19 18 17 18 10 10 10 10 11 7 x or or or or 6 of 7 Memory Instruc Operand Summary Clocks Organization tion Flags ODITSZAPC x x x x x x x x x x x x x XXUXX x x x x x x x x x x x x x XXUXX U XXUXU U XXUXU Table F2 F3 F4 F5 F6 F6 F6 F6 A 3 Instruction Set in Numeric Order of Instruction Code Memory Instruc Operand Summary Clocks Organization tion MOD 000 R M MOD 001 R M MOD 010 R M MOD 011 R M Note Carry Flag F6 F6 F6 F6 F7 F7 F7 F7 MOD 100 R M MOD 101 R M MOD 110 R M MOD 111 R M MOD 000 R M MOD 001 R M MOD 010 R M MOD 011 R M Note Carry Flag F7 F7 F7 F8 F9 FA FB FC FD FE FE FE FE FE FE FE FE FF FF FF FF FF MOD 100 R M MOD 101 R M MOD 110 R M MOD 111 R M MOD 000 R M MOD 001 R M MOD 010 R M MOD 011 R M MOD 100 R M MOD 101 R M MOD 110 R M MOD 111 R M MOD 000 R M MOD 001 R M MOD 010 R M MOD 011 R M MOD 100 R M MOD 101 R M MOD 110 R M MOD 111 R M REPNZ REPZ HLT CMC TEST not NOT NEG is MUL IMUL DIV IDIV TEST not NOT NEG is MUL IMUL DIV IDIV CLC STC CLI
120. pression is computed with four bytes of precision two bytes of segment base and two bytes of offset All four bytes are used with DD with the offset at the lower addresses but only the offset is used with DW Address expressions can be combined to form more complex expressions as follows A relocatable expression plus or minus an absolute expression is a relocatable expression with the same segment attribute A relocatable expression minus a relocatable expression is an absolute expression but it is permitted only if both compo nents have the same segment attribute Absolute expressions can be combined freely with each other 11 other combinations are forbidden Here are some examples of initializing using address expressions pRequest DD Request 32 bit offset and segment Request pErc DD Request 5 Offset of sixth byte in Request oRequest DW Request 16 bit offset of Request String Initialization Variables can be initialized with constant strings as well as with constant numeric expressions With DD and DW strings of one or two characters are permitted The arrangement in memory is tailored to the 8086 architecture this way DW XY allocates two bytes of memory containing in ascending addresses Data Definition 33 DD XY allocates four bytes of memory containing ascending addresses Y X 0 0 With DB strings of up to 255 characters are permitted Characters from left
121. quite sufficient for their needs what follows can be deferred to a second reading The entities manipulated during macro processing are macro identifiers macro delimiters and macro parameters A macro identifier is any string of alphanumeric characters and underscores that begins with an alphabetic character A macro delimiter is a text string used as punctuation between macro parameters There are three kinds of macro delimiters 1 An identifier delimiter is the character followed by an identifier Macro Assembler 69 2 An implicit blank delimiter is any text string made up of the white space characters space RETURN or TAB 3 A literal delimiter is any other delimiter Thus all the preceding examples have used the comma as a literal delimiter A macro parameter is any text string in which parentheses are balanced The following are valid parameters xyz xyz 2 whereas the following are not That is parentheses are considered balanced if the number of left and right parentheses is the same and moreover in reading from left to right there is no intermediate point at which more right than left parentheses have been encountered The most general form of macro definition is DEFINE ident pattern locals body where 1 the is optional see below for details 2 ident is a macro identifier as defined above 3 pattern and body are a
122. re invoked from programs written in assembly language The following example of a call to the standard object module procedure ReadBsRecord is helpful in understanding this subject The calling pattern of this procedure described in detail in the CTOS Operating System Manual is ReadBsRecord pBSWA pBufferRet sBufferMax psDataRet ErcType The Operating System and the standard object modules deal with quantities of many different sizes ranging from single byte quantities such as Boolean flags to multibyte quantities such as request blocks and Byte Stream Working Areas Three of these sizes are special one byte two bytes and four bytes Only quantities of these sizes are passed as parameters on the stack or returned as results in the registers When it is necessary to pass a larger quantity as a parameter or to return a larger quantity as a result a pointer to the larger quantity is used in place of the quantity itself A pointer is always a 4 byte logical memory address consisting of an offset and segment base address For example ReadBsRecord takes as parameters a pointer to a Byte Stream Work Area pBSWA a pointer to a buffer pBufferRet a maximum buffer size sBufferMax and a pointer to a word containing the size of some data psDataRet ReadBsRecord returns an error status of type ErcType The pointers are all 4 byte quantities the size is a 2 byte quantity and the error status is a 2 byte quantity Suppo
123. register pushed onto the stack Finally note that this sample code actually computes the various pointers at run time It would also be possible to have the pointers precomputed by adding to the program the declaration pBSWA DD bswa pBuffer DD buffer psData DD sData If this were done then the appropriate calling sequence would be LES BX pBSWA PUSH ES PUSH BX LES BX pBuffer PUSH ES PUSH BX MOV AX sBuffer PUSH AX LES BX psData PUSH ES PUSH BX CALL ReadBxRecord 76 Assembly Language Manual Note that the LES instruction loads the offset part of the pointer into BX and the segment part into ES in a single instruction Object module and system common procedures as well as procedural references to system services must be declared EXTRN and FAR These declarations may not be embedded in a SEGMENT ENDS declaration See line 6 of Figure 11 3 The result returned by ReadBsRecord is a 2 byte quantity and according to the Convergent calling conventions is returned in AX If the result were a 4 byte quantity the high order part would be returned in ES and the low order part in BX All of the 4 byte quantities dealt with in this example are pointers There are many cases in which the Operating System and standard object module procedures deal with 4 byte quantities other than pointers such as logical file addresses lfa It is important to understand that as far as regards calling and register conventions and stack
124. s long as each assembly module has least one segment You can omit segment definition statements in which case the default segment is assigned the name SEG by the assembler Each inst ruction of the program and each item of data must lie within a segment Code and data may be mixed in the same segment but this is generally not done because such a segment cannot be link ed with object segments produced by Pascal or FORTRAN Here are examples of segments global data segment local data segment stack segment and main program segment code A hardware segment in memory contains up to 64K bytes starts at an address divisible by 16 called a paragraph boundary A paragraph number that is used to address the beginning of a hard ware segment is a segment base address A segment defined by the programmer is a logical segment It does not necessarily start at a paragraph boundary so logical segments need not correspond to hardware segments The paragraph numbers at which segments begin are contained at run time within the four 16 bit segment registers CS DS ES and SS At any time there are four current segments cs always defines the current code segment DS usually defines the current data segment SS always defines the current stack seg ment ES can define an auxiliary data segment The memory address calculations done by the processor have two components a segment base address and a
125. s any nested call No values may be pushed onto the stack between the return address and the pushed BP This convention enables the virtual code segment management services to scan the stack during an overlay fault its violation is not detected as an error but causes the overlaid program to fail Assembly Language Manual in unpredictable ways Naturally the pushed BP must be popped during the procedure s exit sequence 5 11 code must be a class named CODE 6 The SEG operator may not be used on an operand in class CODE nor in any segment that is part of an overlay In particular an instruction such as MOV AX SEG Procedure is not permitted 7 If a procedural value that is a value that points to a procedure is to be constructed this must be done in a class other than CODE by either pProc DD Procedure or pProc DW Procedure DW SEG Procedure Such procedural values do not point directly at the procedure since the procedure may be in an overlay but at a special resident transfer vector created by the Linker Such a procedural value may be invoked by the code CALL DWORD PTR pProc 8 If a procedure is known to be resident and it is desired to address not its entry in the resident transfer vector but the procedure code directly this may be done using in place of SEG and OFFSET the operators RSEG and ROFFSET If RSEG or ROFFSET is applied to a value in an overlay an error is detected during linking S
126. s the rela tive offsets Car STRUC No memory reserved use this yas template for Ford below Year DB 0 Reference to Year generates relative offset of 0 Model DW 0 Reference to Model generates relative offset of 1 Color DW 0 Reference to Color generates relative offset of 3 License DB XXXX Reference to License generates relative offset of 5 Car ENDS Data Definition 39 The body of the structure definition is delimited by the STRUC and ENDS directives The spacing of offsets within the structure is determined by the enclosed DB DW and DD directives You now allocate real memory and initialize using Car as an operator Ford Car 63 FL GR FOXY allocate and initialize Note that the programmer assigned name Car is used here as an operator and that the initialization of the structure is done with both integer data 63 and character data FL This use of Car as an operator is the assembly time analog of this run time initialization FORD DB 8 DUP allocate 8 bytes uninitialized MOV Ford Year 63 initialize Year field MOV Ford Model FL initialize Model field MOV Ford Color GR initialize Color field MOV Ford License FOXY initialize License field It is also possible as described below to specify default values during the definition of the structure and to selectively override these defaults during memory allocation All this can take place during assembly As another examp
127. se that data is allocated by the declarations sBSWA EQU 130 sBuffer EQU 80 bswa DB SBSWA DUP buffer DB sBuffer DUP sData DW Accessing Standard Services 75 Then to call ReadBsRecord it is necessary first to push onto the stack in order a pointer to bswa a pointer to buffer the size of buffer the constant sBuffer and a pointer to sData If DS contains the segment base address for the segment containing bswa buffer and sData then this may be done by the code PUSH DS Push the segment base address for bswa MOV AX OFFSET Set BX to the offset of bswa PUSH AX Push the offset of bswa PUSH DS Ditto for the buffer MOV AX sBuffer Get the buffer size into a register PUSH AX Push this word onto the stack PUSH DS Push the segment base address MOV AX OFFSET sData PUSH AX and then the offset of sData CALL ReadBsRecord Do the call Note that pointers are arranged in memory with the low order part the offset at the lower memory address and the high order part the segment base at the higher memory address However the processor architecture of the Convergent Information Processing System is such that stacks expand from high memory addresses toward low memory addresses hence the high order part of a pointer is pushed before the low order part Note also that the processor has no instruction that pushes an immediate constant that is why the constant sBuffer must first be loaded into a register and that
128. ss of a procedure in the virtual code segment management facility Thus a call of such a procedure actually transfers to the virtual code segment management facility Such a call of the virtual code segment management facility is a call fault When a call fault occurs the virtual code segment Management facility reads the needed overlay into the swap buffer Before control is transferred to the called procedure two other steps are taken 1 The address in all stubs for procedures in the overlay is changed to the swapped in address of the procedure 2 If some overlays had to be deleted from the swap buffer to make room for the new overlay the stubs for their procedures reset to the address of the procedure in the virtual code segment management facility that deals with call faults It is possible for an overlay to be deleted from memory even though control is nested within it i e even though return into it is pushed onto the stack This situation is handled properly all such stacked return addresses are modified to be the address of a procedure in the virtual code Segment management facility that subsequently swaps the overlay back into memory when a return fault occurs The user will observe that in the preceding discussion no use is made of the first byte of a stub the operation code This byte is in fact only used for calls of procedural values The virtual code segment management facility arranges that the operation code
129. ssembler checks the addressability of symbolic operands The opcode generated is determined by the type BYTE or WORD of the operands 20 Assembly Language Manual A string instruction must be preceded by a load of the offset of the source string into SI and a load of the offset of the desti nation string into DI The string operation mnemonic may preceded by a repeat prefix REP REPZ REPE REPNE or REPNZ as in REPZ SCASB This specifies that the string operation is to be repeated the number of times contained in CX String operations without operands MOVSB MOVSW etc use the hardware defaults which are SI offset from DS and DI offset from ES Thus MOVSB is equivalent to MOVS ES BYTE PTR DI SI If the hardware defaults are not used both segment and type overriding are required for anonymous references as MOVS ES BYTE PTR DI SS SI See Section 4 below for a discussion of PTR String instructions can not use BX or BP addressing For details of string instructions and their use with a repeat prefix see the Central Processing Unit page 65 In particular note that repeat and segment override should not be used together if interrupts are enabled GROUP Directive The GROUP directive specifies that certain segments lie within the same 64K bytes of memory Here is the format name GROUP segname Here name is a unique identifier used in referring to the group segname can be the n
130. string AA 11 9 10 rep STOSW Store word string AB 11 9 10 rep SUB AL bData AL AL bData 2c 4 X XXXXX SUB AX wData AX AX wData 2D 4 X XXXXX SUB bEA bData bEA bEA bData 80 101 R M 17 x XXXXX SUB bEA bData bEA bEA bData 82 MOD 101 R M 17 x XXXXX SUB wEA wData wEA wEA wData 81 MOD 101 R M 17 EA x XXXXX SUB wEA bData wEA wEA Ext bData 83 101 17 X XXXXX SUB bEA REG bEA bEA bREG 28 MOD REGR M 16 EA 3 X xxxxx SUB WEA REG WEA WwEA WREG 29 MOD REGR M 16 EA 3 X SUB REG bEA bREG bREG bEA 2A MOD REGR M 9 3 X xxxxx SUB REG WEA WREG WREG wEA 2B MOD REGR M 9 3 X xxxxx TEST AL bData FLAGS AL TEST bData A8 4 X XXUXC TEST AX bData FLAGS AX TEST wData A9 4 X XXUXC TEST bEA bData FLAGS bEA TEST bData F6 MOD 000 R M 10 XXUXC TEST wEA wData FLAGS wEA TEST wData F7 MOD 000 R M 10 XXUXC TEST bEA bREG FLAGS bEA TEST DREG 84 MOD REGR M 9 EA 3 XXUXC TEST WEA wREG FLAGS wEA TEST wREG 85 MOD REGR M 9 EA 3 XXUXC WAITX Wait for TEST signal 9B 3 WAITX XCHG 90 3 XCHG AX BP Exchange AX BP 95 3 XCHG BX Exchange AX BX 93 3 XCHG AX CX Exchange AX CX 91 3 XCHG AX DI Exchange AX DI 97 3 XCHG Exchange DX 92 3 XCHG SI Exchange AX SI 96 3 XCHG SP Exchange AX SP 94 3 XCHG bREG bEA Exchange bREG bEA 8
131. ted for each instruction These are the flag register mnemonics AF Auxiliary Carry CF Carry DF Direction IF Interrupt enable OF Overflow PF Parity SF Sign TF Trap zF Zero Explicit Register Operands These are two operand instructions that explicitly specify registers 44 Assembly Language Manual Register to register label mnemonic reg reg Example ADD BX DI BX BX DI Immediate to register label mnemonic reg imm Example ADD BX 30H BX BX 30H Memory to register label mnemonic reg mem Example ADD BX Table DI BX BX DI th entry in Table Register to memory label mnemonic mem reg Example ADD Table D1 BX Increment DI th entry in Table by BX Note that i th entry means entry at i th byte Implicit Register Operands These instructions use registers implicitly Instruction Implicit Uses AAA AAD AAM AAS AL AH CBW CWD AL AX or AX DX DAA DAS AL IN OUT AL or AX MUL IMUL DIV IDIV AL AX or AX DX LAHF SAHF AH LES ES LDS DS Shifts Rotates CL String CX SI DI XLAT AL BX Operands and Expressions 45 The instructions with a single register operand have the form label mnemonic reg Example INC DI DI DI 1 Segment Registers Segment registers are discussed in Section 2 General Registers When a 16 bit general register or pointer index register is one of the operands of a two operand instruction the other operand must
132. the Stack below for details These conventions place no particular requirement on the contents of BP unless virtual code segment management services are being used See Accessing Standard Services 77 Virtual Code Segment Management and Assembly Code below for details of BP usage with virtual code The other registers and the flags are not automatically preserved across calls to the Operating System or the standard object module procedures Any other registers which must be saved in a particular application must be saved explicitly by the caller Although there is not an absolute requirement that these register usage conventions be followed in parts of an application that do not call standard Convergent services failing to follow them is not recommended in the Convergent programming environment Segment and Group Conventions Main Program A main program module written in assembly language must declare its stack segment and starting address in a special way This is illustrated in the sample module of Figure 11 2 In particular The stack segment must have the combine type Stack See line 22 The starting address must specified in the END statement See line 27 When the program is run the Operating System performs the following steps It loads the program It initializes SS to the segment base address of the program s stack It initializes SP to the top of the stack It transfers control
133. tives Most Programs and Segments 15 compiled languages assign these names automatically See the individual language manuals for details ASSUME Directive The ASSUME directive declares how the instructions and data spec ified during assembly are to be addressed from the segment base registers during execution The programmer must explicitly con trol the values in segment registers at run time Use of the ASSUME directive permits the assembler to verify that data and instructions will be addressable at run time The ASSUME directive can be written either as ASSUME seg reg seg name or ASSUME NOTHING Here seg reg is one of the segment registers Seg name is one of these 1 A segment name as ASSUME CS codeSeg DS dataSeg 2 A GROUP name that has been defined earlier as ASSUME DS DGroup CS CGroup 3 The expression SEG variable name or SEG label name as ASSUME CS SEG Main DS SEG Table 4 The keyword NOTHING as ASSUME ES NOTHING A particular seg reg seg name pair remains in force until another ASSUME assigns a different segment or NOTHING to the given seg reg ASSUME NOTHING means to cancel any ASSUME in effect for the indicated registers A reference to a variable whose segment is ASSUMEd automatically generates the proper object instruction a reference to a variable whose segment is not ASSUMEd must have an explicit segment specification See the Segment Override Prefix below Here is a
134. ually intro duced by writing label instruction which yields a NEAR label See also PROC under Procedures in Section 2 and LABEL under Labels and the LABEL Directive below which can introduce NEAR or FAR labels Constants There are five types of constants binary octal decimal hexa decimal and string Table 3 1 specifies their syntax Data Definition 29 Table 3 1 Constants Constant Type Rules For Formation Examples Binary Base 2 Octal Base 8 Decimal Base 10 Hexadecimal Base 16 STRING An instruction can contain 8 is an example Sequence of 0 s and 1 s plus letter B Sequence of digits 0 through 7 plus either letter 0 or letter 0 Sequence of digits 0 through 9 plus optional letter D Sequence of digits 0 through 9 and or letters A through F plus letter h If the first digit is a letter it must be preceded by 0 Any character string within single quotes More than two characters only with DB or 16 bit immediate values 10B 11001011B 76540 77770 777770 9903 9903D 77h 1Fh OCEACh ODFh A B ABC Rowrff UP URZ Here MOV CH MOV CX 53H 3257H Byte immediate value Word immediate value Constants can be values assigned to symbols with the EQU direc tive These are examples Seven EQU 7 MOV AH Seven 7 used wherever Seven referenced Same as MOV AH 7 See Section 4 for the complete definition of EQU
135. uction assembles into one of two forms depending on whether the destination procedure is NEAR FAR When a NEAR procedure is called the instruction pointer IP the address of the next sequential instruction is pushed onto the stack and control transfers to the first instruction in the procedure When a FAR procedure is called first the content of the CS reg ister is pushed onto the stack then the IP is pushed onto the stack and control transfers to the first instruction of the procedure Multiple entry points to a procedure are permitted All entry points to a procedure should be declared as NEAR FAR depen ding on whether the procedure is NEAR Or FAR All returns from a procedure are assembled according to the procedure type NEAR or FAR See Figure 2 1 for the procedure CALL RET control flow Recursive Procedures and Procedure Nesting on the Stack When procedures call other procedures the rules are the same for declaration calling and returning Programs and Segments 23 SEGB AGAIN PROC FAR XXX LABEL FAR RET 8 AGAIN ENDP SEGB ENDS For RET 8 SEGB SEGMENT ASSUME CS OFFSET xxx SP4 SP 8 SEGA PROC Figure 2 1 CALL RET Control Flow CALL BBB MOY BX CALL XXX INC AX RET 88B ENDP 5 lt 5 2 SEGA ENDS BBB PROC NEAR TAO SEGA SEGMENT ASSUME CS external interrupt Comes from any of
136. uctures and records defined below be defined and initialized with tively the DB DW DD structure name and record name direc tives as shown here rgb DB 50 DUP 66 Allocate 50 bytes named rgb initialize each to 66 rgw DW 100 DUP 0 Allocate 100 words named rgw initialize each to O0 rgdd DD 20 DUP Allocate 20 doublewords named rgdd don t initialize them When you refer to array elements be aware that the origin of an array is 0 This means that the first byte of the array rgb is rgb 0 not rgb 1 Its nth byte is rgb n 1 Also be aware that indexes are the number of bytes from the start of the array regardless of whether the array elements are bytes words or doublewords Object Modules and Linking An object module can contain any or all of the following code constants variable data The Linker see the Utilities Manual arranges the contents of a set of object modules into a memory image typically with all code together all constants together and all variable data together This arrangement makes optimal use of the addressing structures of the 8086 Although the Linker produces such arrangements automatically the programmer will occasionally want to exercise explicit control The con cepts and facilities used to arrange memory are explained in Section 2 Introduction 3 Segments and Memory References At assembly time you can define as many segments as you wish a
137. ul that an anonymous reference is to the correct segment unless there is a segment prefix override the hardware default is applied For example ADD BX BP 5 is the same as ADD SS BP 5 MOV BX 4 CX is the same as MOV DS BX 4 CX SUB BX SI CX is the same as SUB DS BX SI CX AND BP DI DX is the same as AND SS BP DI DX MOV BX SI one is the same as MOV BX DS SI one AND DI CX is the same as AND DS DI CX The following examples require explicit overrides since they differ from the default usage MOV CS BX 2 AX SS BX SI CX AND DS BP DI CX MOV BX CS DI one AND ES SI 4 DX Memory Reference in String Instructions The mnemonics of the string instructions are shown in Table 2 1 These include those that can be coded with operands MOVS etc and those that can be coded without operands MOVSB MOVSW etc Each string instruction has type specific forms e g LODSB LODSW and a generic form e g LODS The assembled machine instruction is always type specific If you code the generic form you must provide arguments that serve only to declare the type and addressability of the arguments Table 2 1 String Instruction Mnemonics Mnemonic Mnemonic Mnemonic For Byte For Word For Symbolic Operands Operands Operands Operands Move MOVSB MOVSW MOVS Compare CMPSB CMPSW CMPS Load AL AX LODSB LODSW LODS Store from AL AX STOSB STOSW STOS Compare to AL AX SCASB SCASW SCAS The a
138. ult is 1 if the symbol is defined and 0 if the symbol is not defined The two forms are ISDEF symbol to check a run time symbol and ISDEF symbol to check macro time symbol Repetitive Assembly REPEAT is used to assemble one of its parameters a specified number of times The form is SREPEAT paraml param2 For example REPEAT 4 DW 0 is equivalent to 66 Assembly Language Manual DW DW DW DW oooo Note that in this and in most examples involving the macro facility the parentheses are the delimiters of textual parameters so their placement is critical WHILE is used to assemble one of its parameters a variable number of times depending on the result of an assembly time computation to be performed before each repetition The form is SWHILE paraml param2 For example suppose nWords has the value 3h Then the result of SWHILE nWords GT 0 REPEAT nWords DW nWords SET nWords nWords 1 is DW 3h DW 3h DW 3h DW 2h DW 2h DW lh When using the control functions REPEAT and WHILE it is sometimes desirable to explicitly terminate expansion This can be done with EXIT whose invocation stops the expansion of the enclosing REPEAT WHILE macro For example if n is initially 5 then the expression WHILE n GT 0 SREPEAT n 1F n THEN FI DW n 5 n n 1 expands to DW DW DW DW DW DW N N gt gt gt
139. ure name or record name for variables NEAR FAR for labels procedures ABS for pure numbers the implicit SIZE is WORD If you know the name of the segment in which an external symbol is declared as PUBLIC place the corresponding EXTRN directive inside a set of SEGMENT ENDS directives that use this segment name You may then access the external symbol in the same way as if the uses were in the same module as the definition If you do not know the name of the segment in which an external symbol is declared as PUBLIC place the corresponding EXTRN directive at the top of the module outside all SEGMENT ENDS pairs To address an external symbol declared in this way you must do two things 1 Use the SEG operator to load the 16 bit segment part into segment register See Value Returning Operators in Section 4 for a description of the SEG operator Here is an example MOV AX SEG Var Load segment base MOV ES AX value into AX and thence to ES 2 Refer to the variable under control of a corresponding ASSUME such as ASSUME ES SEG var or using a segment override prefix END Directive The end of the source program is identified by the END direc tive This terminates assembly and has the format END expression The expression should be included only in your main program and must be NEAR or FAR and specifies the starting execution address of the program Here is an example END Initialize
140. verride prefix coding This is the format seg reg Here seg reg is CS DS ES or SS as in DS xyz This construct does not require an ASSUME directive for the vari able reference but its scope is limited to the instruction in which it occurs 18 Assembly Language Manual Thus the following two program equivalent Hohum SEGMENT ASSUME CS Hohum DS Pond MOV AX Frog ADD AL Toad MOV Cicada AX Hohum ENDS Hohum SEGMENT ASSUME CS Hohum MOV AX DS Frog ADD AL DS Toad MOV DS Cicada AX Hohum ENDS where Pond would be defined by Pond SEGMENT Frog DW 100 DUP 0 Toad DB 500 DUP 0 Cicada DW 800 DUP 0 Pond ENDS Anonymous References fragments are 7100 words 0 s 7500 bytes 0 s 7800 words 0 s correct and Memory references that do not include a variable name are called anonymous references These are examples BX Hardware defaults determine the segment registers anonymous references unless there is an explicit segment prefix operator These are the hardware defaults Addressing Default BX DS BX DI DS BX SI DS BP ss BP DI SS BP SI SS DI DS SI DS The exceptions to these defaults are for these 1 PUSH POP CALL RET INT and IRET always use SS and this default cannot be overridden Programs and Segments 19 2 String instructions on operands pointed to by DI always use ES and this default cannot be overridden Be particularly caref
141. xecutive s PRINT command The PRINT command can be used to print such a listing but only by overriding many of its default values these values were chosen to make the printing of text files created with the Editor most convenient 86 Assembly Language Manual 11 SAMPLE ASSEMBLER MODULES This section contains three complete sample assembler modules The first Figure 11 1 is a source module of the assembler itself It is the module that translates the assembler s internal error numbers into textual error messages The second module Figure 11 2 is a skeleton of a standalone assembler main program and illustrates how the run time stack is allocated in an assembler module This example follows a bare minimum of the standard system conventions and does not link properly to standard object module procedures The third module Figure 11 3 is an assembler main program compatible with Convergent conventions and linkable with standard object module procedures as described above in Section 9 Accessing Standard Services from Assembly Code Sample Assembler Modules 87 go wezboig ebessaw 2434044112554 u4nj3a4 pue 438935 dung 13H dg 48 le dg dOd 53 ut 4x83 0 3uawbas 53 AGW 55 4 23 abessaw 40148 03 aarzetau 52 433834 Lxa1u28geuba xg AoW Spuom yO Aeuse
142. xt Pascal User Manual and Report The Debugger Manual describes the Debugger which is designed for use at the symbolic instruction level Together with appropriate interlistings it can be used for debugging FORTRAN Pascal and assembly language programs BASIC and COBOL in contrast are more conveniently debugged using special facilities described in their respective manuals The Utilities Manual describes miscellaneous programs such as the Linker which links together separately compiled object files and the Asynchronous Terminal Emulator The Data Base Management System Manual describes the data base management system It specifies 1 the data definition language which defines the logical structure of data bases and separately defines their physical organization 2 the host language interfaces for accessing data bases from each of the system s programming languages and 3 the utilities for creating loading unloading and reorganizing data bases The 3270 Emulator Manual describes the 3270 emulator package viii Assembly Language Manual The System Programmer s Guide addresses the needs of the system programmer system manager for detailed information operating system structure and system operation It describes 1 diagnostics 2 procedures for customizing the operating system and 3 system utilities normally used only by a system programmer or manager for example Initialize Volume Backup and R
143. ystem Programming Notes The rest of this Section describes some of the algorithms and data structures that make up the virtual code segment management facility An understanding of these details is not needed by the user of the virtual code segment management facility they are included for the information of the system programmer desiring a model of the internal workings of the virtual code segment Management facility When you invoke the Linker if you specify the use of overlays then the Linker creates in the run file a special segment in the resident part of the program called the statics segment This segment contains a transfer vector an array of 5 byte entries called stubs with one stub for each public procedure in the Accessing Standard Services 83 program A stub consists of one byte containing an operation code either JUMP or CALL and four bytes containing a long address The Linker notes each call to a public procedure in an overlaid program and transforms it to an intersegment indirect call through the address part of the corresponding stub The contents of the address part of a stub for a procedure which is in memory i e either resident or overlaid but currently swapped in is the actual starting address of the procedure thus the call of such a procedure is slower than it would be ina nonoverlaid program by only one memory reference The contents of the address part of a stub for a procedure not in memory is the addre
Download Pdf Manuals
Related Search
Related Contents
OS Upgrade - SDE Systeme GmbH V4N2 - Forth 冷蔵庫(組立式)1坪型 User Manual v1.0 - Auto 1 ISTRUZIONI ORIGINALI ISTRUZIONI GENERALI DI instruction booklet mode d`emploi folleto de AT&T 1145 User's Manual iRhythms Portable Digital Docking Speakers Copyright © All rights reserved.
Failed to retrieve file