logging in or signing up ASSembler subroutine prog vadapally Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 712 Category: Education License: All Rights Reserved Like it (1) Dislike it (0) Added: April 15, 2009 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Introduction to Assemblers : Introduction to Assemblers Fundamental functions translating mnemonic operation codes to their machine language equivalents assigning machine addresses to symbolic labels Machine dependency different machine instruction formats and codes Example Program (Fig. 2.1) : Example Program (Fig. 2.1) Purpose reads records from input device (code F1) copies them to output device (code 05) at the end of the file, writes EOF on the output device, then RSUB to the operating system Example Program (Fig. 2.1) : Example Program (Fig. 2.1) Data transfer (RD, WD) a buffer is used to store record buffering is necessary for different I/O rates the end of each record is marked with a null character (0016) the end of the file is indicated by a zero-length record Subroutines (JSUB, RSUB) RDREC, WRREC save link register first before nested jump Assembler’s functions : Assembler’s functions Convert mnemonic operation codes to their machine language equivalents Convert symbolic operands to their equivalent machine addresses ? Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing Assembler Directives : Assembler Directives Pseudo-Instructions Not translated into machine instructions Providing information to the assembler Basic assembler directives START END BYTE WORD RESB RESW Slide 6: Line Source statement 5 COPY START 1000 10 FIRST STL RETADR SAVE RETURN ADDRESS 15 CLOOP JSUB RDREC READ INPUT RECORD 20 LDA LENGTH TEST FOR EOF (LENGTH = 0) 25 COMP ZERO 30 JEQ ENDFIL EXIT IF EOF FOUND 35 JSUB WRREC WRITE OUTPUT RECORD 40 J CLOOP LOOP 45 ENDFIL LDA EOF INSERT END OF FILE MARKER 50 STA BUFFER 55 LDA THREE SET LENGTH = 3 60 STA LENGTH 65 JSUB WRREC WRITE EOF 70 LDL RETADR GET RETURN ADDRESS 75 RSUB RETURN TO CALLER 80 EOF BYTE C.EOF. 85 THREE WORD 3 90 ZERO WORD 0 95 RETADR RESW 1 100 LENGTH RESW 1 105 BUFFER RESB 4096 4096-BYTE BUFFER AREA Example Program Fig. 2.1 Slide 7: 110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER 120 . 125 RDREC LDX ZERO CLEAR LOOP COUNTER 130 LDA ZERO CLEAR A TO ZERO 135 RLOOP TD INPUT TEST INPUT DEVICE 140 JEQ RLOOP LOOP UNTIL READY 145 RD INPUT READ CHARACTER INTO REGISTER A 150 COMP ZERO TEST FOR END OF RECORD (X.00.) 155 JEQ EXIT EXIT LOOP IF EOR 160 STCH BUFFER,X STORE CHARACTER IN BUFFER 165 TIX MAXLEN LOOP UNLESS MAX LENGTH 170 JLT RLOOP HAS BEEN REACHED 175 EXIT STX LENGTH SAVE RECORD LENGTH 180 RSUB RETURN TO CALLER 185 INPUT BYTE X.F1. CODE FOR INPUT DEVICE 190 MAXLEN WORD 4096 195 . 200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 . 210 WRREC LDX ZERO CLEAR LOOP COUNTER 215 WLOOP TD OUTPUT TEST OUTPUT DEVICE 220 JEQ WLOOP LOOP UNTIL READY 225 LDCH BUFFER,X GET CHARACTER FROM BUFFER 230 WD OUTPUT WRITE CHARACTER 235 TIX LENGTH LOOP UNTIL ALL CHARACTERS 240 JLT WLOOP HAVE BEEN WRITTEN 245 RSUB RETURN TO CALLER 250 OUTPUT BYTE X.05. CODE FOR OUTPUT DEVICE 255 END FIRST Slide 8: Example Program with Object Code Line Loc Source statement Object code 5 1000 COPY START 1000 10 1000 FIRST STL RETADR 141033 15 1003 CLOOP JSUB RDREC 482039 20 1006 LDA LENGTH 001036 25 1009 COMP ZERO 281030 30 100C JEQ ENDFIL 301015 35 100F JSUB WRREC 482061 40 1012 J CLOOP 3C1003 45 1015 ENDFIL LDA EOF 00102A 50 1018 STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 65 1021 JSUB WRREC 482061 70 1024 LDL RETADR 081033 75 1027 RSUB 4C0000 80 102A EOF BYTE C.EOF. 454F46 85 102D THREE WORD 3 000003 90 1030 ZERO WORD 0 000000 95 1033 RETADR RESW 1 100 1036 LENGTH RESW 1 105 1039 BUFFER RESB 4096 Slide 9: 110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER 120 . 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203D 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A RSUB 4C0000 185 205D INPUT BYTE X.F1. F1 190 205E MAXLEN WORD 4096 001000 195 . 200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 . 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER,X 509039 230 206D WD OUTPUT DC2079 235 2070 TIX LENGTH 2C1036 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X.05. 05 255 END FIRST Slide 10: SIC Instruction Set (Review) . Load/Store: LDA/STA, LDX/STX. . Arithmetic: ADD, SUB, MUL, DIV . Compare: COMP . Jump: J . Conditional Jump: JLT, JEQ, JGT SIC Instruction Format . Opcode : 8 bits . Address: one bit flag (x) and 15 bits of address FORMAT OF THE INSTRUCT.. IN SIC Slide 11: Forward reference: Reference to a label that is defined later in the program. Loc Label Operator Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … … … … … 1012 J CLOOP … … … … … 1033 RETADR RESW 1 Object Program : Object Program Header Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col. 14-19 Length of object program in bytes (hex) Text Col.1 T Col.2~7 Starting address in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69 Object code (69-10+1)/6=10 instructions End Col.1 E Col.2~7 Address of first executable instruction (hex) (END program name) Object code of above program : H COPY 001000 00107A T 001000 1E 141033 482039 001036 281030 301015 482061 ... T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000 T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 … T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 … T 002073 07 382064 4C0000 05 E 001000 Object code of above program Two Pass Assembler : Two Pass Assembler Pass 1 Assign addresses to all statements in the program Save the values assigned to all labels for use in Pass 2 Perform some processing of assembler directives Pass 2 Assemble instructions Generate data values defined by BYTE, WORD Perform processing of assembler directives not done in Pass 1 Write the object program and the assembly listing Two Pass Assembler : Two Pass Assembler Read from input line LABEL, OPCODE, OPERAND Pass 1 Pass 2 Object codes Source program OPTAB SYMTAB SYMTAB Data Structures : Data Structures Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter(LOCCTR) OPTAB (operation code table) : OPTAB (operation code table) Content mnemonics, machine code (instruction format, length) etc. Characteristic static table Implementation array or hash table, easy for search SYMTAB (symbol table) : SYMTAB (symbol table) Content label name, value, flag, (type, length) etc. Characteristic dynamic table (insert, delete, search) Implementation hash table, non-random keys, hashing function COPY 1000 FIRST 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039 Slide 19: Two Pass Assembler . Pass 1 Two Pass Assembler . Pass 2 : Two Pass Assembler . Pass 2 Assembler Design : Assembler Design Machine Dependent Assembler Features instruction formats and addressing modes program relocation Machine Independent Assembler Features literals symbol-defining statements expressions program blocks control sections and program linking Instruction Format and Addressing Mode : Instruction Format and Addressing Mode SIC/XE PC-relative or Base-relative addressing: op m Indirect addressing: op @m Immediate addressing: op #c Extended format: +op m Index addressing: op m,x register-to-register instructions larger memory -> multi-programming (program allocation) Example program Figure 2.5 Translation : Translation Register translation register name (A, X, L, B, S, T, F, PC, SW) and their values (0,1, 2, 3, 4, 5, 6, 8, 9) preloaded in SYMTAB Address translation Most register-memory instructions use program counter relative or base relative addressing Format 3: 12-bit address field base-relative: 0~4095 pc-relative: -2048~2047 Format 4: 20-bit address field PC-Relative Addressing Modes : PC-Relative Addressing Modes PC-relative 10 0000 FIRST STL RETADR 17202D (14)16 1 1 0 0 1 0 (02D) 16 displacement= RETADR - PC = 30-3 = 2D 40 0017 J CLOOP 3F2FEC (3C)16 1 1 0 0 1 0 (FEC) 16 displacement= CLOOP-PC= 6 - 1A= -14= FEC You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
ASSembler subroutine prog vadapally Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 712 Category: Education License: All Rights Reserved Like it (1) Dislike it (0) Added: April 15, 2009 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Introduction to Assemblers : Introduction to Assemblers Fundamental functions translating mnemonic operation codes to their machine language equivalents assigning machine addresses to symbolic labels Machine dependency different machine instruction formats and codes Example Program (Fig. 2.1) : Example Program (Fig. 2.1) Purpose reads records from input device (code F1) copies them to output device (code 05) at the end of the file, writes EOF on the output device, then RSUB to the operating system Example Program (Fig. 2.1) : Example Program (Fig. 2.1) Data transfer (RD, WD) a buffer is used to store record buffering is necessary for different I/O rates the end of each record is marked with a null character (0016) the end of the file is indicated by a zero-length record Subroutines (JSUB, RSUB) RDREC, WRREC save link register first before nested jump Assembler’s functions : Assembler’s functions Convert mnemonic operation codes to their machine language equivalents Convert symbolic operands to their equivalent machine addresses ? Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing Assembler Directives : Assembler Directives Pseudo-Instructions Not translated into machine instructions Providing information to the assembler Basic assembler directives START END BYTE WORD RESB RESW Slide 6: Line Source statement 5 COPY START 1000 10 FIRST STL RETADR SAVE RETURN ADDRESS 15 CLOOP JSUB RDREC READ INPUT RECORD 20 LDA LENGTH TEST FOR EOF (LENGTH = 0) 25 COMP ZERO 30 JEQ ENDFIL EXIT IF EOF FOUND 35 JSUB WRREC WRITE OUTPUT RECORD 40 J CLOOP LOOP 45 ENDFIL LDA EOF INSERT END OF FILE MARKER 50 STA BUFFER 55 LDA THREE SET LENGTH = 3 60 STA LENGTH 65 JSUB WRREC WRITE EOF 70 LDL RETADR GET RETURN ADDRESS 75 RSUB RETURN TO CALLER 80 EOF BYTE C.EOF. 85 THREE WORD 3 90 ZERO WORD 0 95 RETADR RESW 1 100 LENGTH RESW 1 105 BUFFER RESB 4096 4096-BYTE BUFFER AREA Example Program Fig. 2.1 Slide 7: 110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER 120 . 125 RDREC LDX ZERO CLEAR LOOP COUNTER 130 LDA ZERO CLEAR A TO ZERO 135 RLOOP TD INPUT TEST INPUT DEVICE 140 JEQ RLOOP LOOP UNTIL READY 145 RD INPUT READ CHARACTER INTO REGISTER A 150 COMP ZERO TEST FOR END OF RECORD (X.00.) 155 JEQ EXIT EXIT LOOP IF EOR 160 STCH BUFFER,X STORE CHARACTER IN BUFFER 165 TIX MAXLEN LOOP UNLESS MAX LENGTH 170 JLT RLOOP HAS BEEN REACHED 175 EXIT STX LENGTH SAVE RECORD LENGTH 180 RSUB RETURN TO CALLER 185 INPUT BYTE X.F1. CODE FOR INPUT DEVICE 190 MAXLEN WORD 4096 195 . 200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 . 210 WRREC LDX ZERO CLEAR LOOP COUNTER 215 WLOOP TD OUTPUT TEST OUTPUT DEVICE 220 JEQ WLOOP LOOP UNTIL READY 225 LDCH BUFFER,X GET CHARACTER FROM BUFFER 230 WD OUTPUT WRITE CHARACTER 235 TIX LENGTH LOOP UNTIL ALL CHARACTERS 240 JLT WLOOP HAVE BEEN WRITTEN 245 RSUB RETURN TO CALLER 250 OUTPUT BYTE X.05. CODE FOR OUTPUT DEVICE 255 END FIRST Slide 8: Example Program with Object Code Line Loc Source statement Object code 5 1000 COPY START 1000 10 1000 FIRST STL RETADR 141033 15 1003 CLOOP JSUB RDREC 482039 20 1006 LDA LENGTH 001036 25 1009 COMP ZERO 281030 30 100C JEQ ENDFIL 301015 35 100F JSUB WRREC 482061 40 1012 J CLOOP 3C1003 45 1015 ENDFIL LDA EOF 00102A 50 1018 STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 65 1021 JSUB WRREC 482061 70 1024 LDL RETADR 081033 75 1027 RSUB 4C0000 80 102A EOF BYTE C.EOF. 454F46 85 102D THREE WORD 3 000003 90 1030 ZERO WORD 0 000000 95 1033 RETADR RESW 1 100 1036 LENGTH RESW 1 105 1039 BUFFER RESB 4096 Slide 9: 110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER 120 . 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203D 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A RSUB 4C0000 185 205D INPUT BYTE X.F1. F1 190 205E MAXLEN WORD 4096 001000 195 . 200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 . 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER,X 509039 230 206D WD OUTPUT DC2079 235 2070 TIX LENGTH 2C1036 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X.05. 05 255 END FIRST Slide 10: SIC Instruction Set (Review) . Load/Store: LDA/STA, LDX/STX. . Arithmetic: ADD, SUB, MUL, DIV . Compare: COMP . Jump: J . Conditional Jump: JLT, JEQ, JGT SIC Instruction Format . Opcode : 8 bits . Address: one bit flag (x) and 15 bits of address FORMAT OF THE INSTRUCT.. IN SIC Slide 11: Forward reference: Reference to a label that is defined later in the program. Loc Label Operator Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … … … … … 1012 J CLOOP … … … … … 1033 RETADR RESW 1 Object Program : Object Program Header Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col. 14-19 Length of object program in bytes (hex) Text Col.1 T Col.2~7 Starting address in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69 Object code (69-10+1)/6=10 instructions End Col.1 E Col.2~7 Address of first executable instruction (hex) (END program name) Object code of above program : H COPY 001000 00107A T 001000 1E 141033 482039 001036 281030 301015 482061 ... T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000 T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 … T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 … T 002073 07 382064 4C0000 05 E 001000 Object code of above program Two Pass Assembler : Two Pass Assembler Pass 1 Assign addresses to all statements in the program Save the values assigned to all labels for use in Pass 2 Perform some processing of assembler directives Pass 2 Assemble instructions Generate data values defined by BYTE, WORD Perform processing of assembler directives not done in Pass 1 Write the object program and the assembly listing Two Pass Assembler : Two Pass Assembler Read from input line LABEL, OPCODE, OPERAND Pass 1 Pass 2 Object codes Source program OPTAB SYMTAB SYMTAB Data Structures : Data Structures Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter(LOCCTR) OPTAB (operation code table) : OPTAB (operation code table) Content mnemonics, machine code (instruction format, length) etc. Characteristic static table Implementation array or hash table, easy for search SYMTAB (symbol table) : SYMTAB (symbol table) Content label name, value, flag, (type, length) etc. Characteristic dynamic table (insert, delete, search) Implementation hash table, non-random keys, hashing function COPY 1000 FIRST 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039 Slide 19: Two Pass Assembler . Pass 1 Two Pass Assembler . Pass 2 : Two Pass Assembler . Pass 2 Assembler Design : Assembler Design Machine Dependent Assembler Features instruction formats and addressing modes program relocation Machine Independent Assembler Features literals symbol-defining statements expressions program blocks control sections and program linking Instruction Format and Addressing Mode : Instruction Format and Addressing Mode SIC/XE PC-relative or Base-relative addressing: op m Indirect addressing: op @m Immediate addressing: op #c Extended format: +op m Index addressing: op m,x register-to-register instructions larger memory -> multi-programming (program allocation) Example program Figure 2.5 Translation : Translation Register translation register name (A, X, L, B, S, T, F, PC, SW) and their values (0,1, 2, 3, 4, 5, 6, 8, 9) preloaded in SYMTAB Address translation Most register-memory instructions use program counter relative or base relative addressing Format 3: 12-bit address field base-relative: 0~4095 pc-relative: -2048~2047 Format 4: 20-bit address field PC-Relative Addressing Modes : PC-Relative Addressing Modes PC-relative 10 0000 FIRST STL RETADR 17202D (14)16 1 1 0 0 1 0 (02D) 16 displacement= RETADR - PC = 30-3 = 2D 40 0017 J CLOOP 3F2FEC (3C)16 1 1 0 0 1 0 (FEC) 16 displacement= CLOOP-PC= 6 - 1A= -14= FEC