Assembler/Session 1 Assembler LanguageAssembler Language forfor Mainframe ProgrammersMainframe Programmers
Objectives • Familiarize with IBM 370 Assembly Language ObjectivesObjectivesObjectivesObjectives Assembler/Session 1
SESSION 1SESSION 1 Day 1Day 1 Introduction SESSION 2SESSION 2 Day 1Day 1 Addressing SESSION 3SESSION 3 Day 2Day 2 Machine Instructions Assembler/Session 1 COURSE SCHEDULECOURSE SCHEDULE
Writing a complete program SESSION 4SESSION 4 Day 3Day 3 Program Sectioning SESSION 5SESSION 5 Day 3Day 3 Assembler Directives SESSION 6SESSION 6 Day 3Day 3 Assemble and link programSESSION 7SESSION 7 Day 4Day 4 COURSE SCHEDULE Assembler/Session 1
Macro LanguageSESSION 8SESSION 8 Day 4Day 4 Other TopicsSESSION 9SESSION 9 Day 5Day 5 Assembler/Session 1 COURSE SCHEDULE
Assembler LanguageAssembler Language SESSION 1 Assembler/Session 1
Objectives • An assembler language is a symbolic form of machine language • Assembler translates assembler language program to machine language • An assembler program consists of many statements • In general, one assembler language statement corresponds to one machine language instruction INTRODUCTIONINTRODUCTION Assembler/Session 1
Objectives STATEMENT FORMATSTATEMENT FORMAT 1 10 16 30 label operation operands comments e.g.. INIT1 LA R5,4 ;INITIALISE REGISTER 5 Rules for choosing labels:Rules for choosing labels: • maximum 8 characters • Alphabets, digits, @, #, $ • First character should not be a digit • label should begin in column 1 Assembler/Session 1
Objectives Col1 Col10 Col.16 L 2,A A 2,B ST 2,ANS ….. ….. A DC F’15’ B DC F’20’ ANS DS F Sample programSample program Assembler/Session 1
Objectives STATEMENT FORMATSTATEMENT FORMAT Operation • One of the 200 M/C instruction mnemonics (eg. MVC) Operand • can be a register or memory location Continuing a statement • Place any character in column 72 of the line to be continued • Continue the statement from column 16 of next line • Maximum 2 continuation lines for a statement Assembler/Session 1
Objectives STATEMENT FORMATSTATEMENT FORMAT Comment Statement • * in column 1 • Any text in columns 2 - 71 Note : Fields separated by one or more blanks Assembler/Session 1
Objectives TYPES OF INSTRUCTIONSTYPES OF INSTRUCTIONS 1. Machine Instructions 2. Assembler Instructions (Directives) 3. Macro Instructions Assembler/Session 1
Objectives REGISTERSREGISTERS Registers are storage areas inside the processor Advantages: - No need to retrieve data from main storage (saves time) - Shared resource that allows inter communication between programs Assembler/Session 1
Objectives REGISTERSREGISTERS General purpose registers: * 16 registers available * Numbered 0 - 15 * Holds 32 bits (4 bytes) of data (1 Full word) Floating point registers: * 4 registers available * Numbered 0,2,4,6 * Holds 64 bits (8 bytes) of data Note : The registers 0, 1, 13, 14 and 15 are reserved for special purpose By IBM convention these registers are used for calling subprograms Assembler/Session 1
Objectives DATA REPRESENTATIONDATA REPRESENTATION Binary fields - Always fixed in length, either 2 or 4 bytes (Full word or Half word) - Negative numbers stored in 2’s complement form Examples: A DC H’295’ 01 27 B DC H’-75’ FF 35 Assembler/Session 1
Objectives 2’s complement form2’s complement form Assembler/Session 1 How to identify a negative number?How to identify a negative number? -- Leading bit contains a 1 (In Hex 8 to F)Leading bit contains a 1 (In Hex 8 to F) How to convert to a negative numberHow to convert to a negative number?? -First switch the bits (1 to 0 , 0 to 1)First switch the bits (1 to 0 , 0 to 1) -Finally add 1Finally add 1
Objectives Boundary requirementsBoundary requirements Assembler/Session 1 Full word – Should begin in a full word boundary (Achieved by aligning with 0F) Half word – Should begin in a half word boundary (Achieved by aligning with 0H) How to find: The starting address of Full word should end with 0, 4, 8 or C and Half words should end with 0, 2, 4, 6, 8, A, C or E
Objectives DATA REPRESENTATIONDATA REPRESENTATION Characters - One byte (EBCDIC form) - Character representation of decimal digits is called Zoned Decimal (first nibble is zone and next is digit) Zone digit Zone Code 0 - 9 + C, A,E,F - D, B +, - , blank Blank F Assembler/Session 1
Objectives DATA REPRESENTATIONDATA REPRESENTATION Floating Point Numbers - Always fixed in length, 4, 8 or 16 bytes (Full word, double word, double double word) - Left most bit represents sign (0 - positive; 1 - negative) - Next 7 bits represent exponent - Remaining bytes represent the fraction Assembler/Session 1
Objectives DATA REPRESENTATIONDATA REPRESENTATION Decimal numbers ( Packed Decimal representation) - Each byte but the rightmost has 2 decimal digits (0-9) - The right most byte contains a digit in the left half and a sign indicator in the right Sign indicator: C- Positive D - Negative Example: 753 - 7 5 3 C Assembler/Session 1
Objectives Addressing Operands • Register addressing • Base, displacement addressing • Base, index and displacement addressing Assembler/Session 1
Objectives INSTRUCTION FORMATS RR opcode R1 R2 SI opcode I2 B1 D1 SS opcode L B1 D1 B2 D2 SS opcode L1 L2 B1 D1 B2 D2 RX opcode R1 X2 B2 D2 RS opcode R1 R3 B2 D2 Assembler/Session 1
Objectives Addressing RX Operands: Implicit format: L 3,VAR Explicit format: L 3,100(0,12) Register Displacement Index reg Base reg Assembler/Session 1
Assembler LanguageAssembler Language SESSION 2SESSION 2 Addressing Assembler/Session 2
ObjectivesSTORAGE DEFINITIONSSTORAGE DEFINITIONS Two ways to define fields : 1. Define a field and initialize the data in it using the DC assembler directive 2. Define a field without initializing using the DS assembler directive Assembler/Session 2
Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS Format: label {DS/DC} dtLn’value’ where : label : Label used to name the field (optional) d : Duplication factor (optional) t : Type of data ( required) Ln : The letter ‘L’ followed by the length of the field in bytes (optional) value : Represents the value enclosed in apostrophes Assembler/Session 2
Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS Examples: ALPHA DC C’ABC EF’ FLDS DS 3CL2 H1 DC H’29’ F2 DC F’-10’ F1 DC X’03’ F3 DC PL4’-72’ Note : for character constants truncation or padding is to the right and for almost all others it is to the left. Assembler/Session 2
Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS DC TYPES Type Implied Alignment Data Representation Length C - None Character X - None Hex digits B - None Binary digits F 4 Full word Binary H 2 Half word Binary E 4 Full word Floating point D 8 Double word Floating point L 16 Double word Floating point P - None Packed decimal Assembler/Session 2
Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS Data Representation in other languages: Assembler FORTRAN COBOL PASCAL BASIC Language DC Type C Character Display String String F, H Integer COMP Integer Integer E Real COMP-1 Real Single precision D Double COMP-2 Real Double Precision Precision X, B Logical N/A Boolean Hex P N/A COMP-3 N/A N/A Assembler/Session 2
Objectives STORAGE DEFINITIONS Literals • A literal is a constant preceded by an equals sign ‘=‘. • Can be used as a main-storage operand but not as a destination field of an instruction • Causes assembler to define a field that is initialized with the data specified • All constants defined by literals are put by the assembler in a literal pool, usually at the very end of the program (Unless changed by LTORG instruction) L R4,=F’1’ Assembler/Session 2
Objectives Exercise 1 Q 1 and Q2. 2.What will happen in the following cases DC CL5’123’ DC CL5’123456’ DC X’A1245’ DC XL2’A1245’ DC XL5’A1245’ DC F’19’ DC FL1’513’ Assembler/Session 2
Objectives EQU (Assembler directive) • The EQU statement is used to associate a fixed value with a symbol R4 EQU 4 DRBACK EQU OUT+25 Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY • By establishing the addressability of a coding section, you can refer to the symbolic addresses defined in it in the operands of machine instruction • Assembler will convert the implicit addresses into explicit addresses (base - displacement form) Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY To establish the address of a coding section : • Specify a base address from which the assembler can compute displacements • Assign a base register to contain this base address • Write the instruction that loads the base register with the base address Note: The base address should remain in the base register throughout the execution of the program Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Establishing Base Register The USING and DROP assembler instructions enable one to use expressions representing implicit addresses as operands of machine instruction statements, leaving the assignment of base registers and the calculation of displacements to the assembler USING - Use Base Address Register - allows one to specify a base address and assign one or more base registers Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY To use the USING instruction correctly, one should know : • which locations in a coding section are made addressable by the USING statement • where in a source module you can use these established addresses as implicit addresses in instruction operands Format: symbol USING base address,basereg1| basereg2|,.. e.g. USING BASE,9,10,11 USING *,12 Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Range of a USING instruction: • The range of a USING instruction is the 4096 bytes beginning at the base address specified in the USING instruction Domain of a USING instruction • The domain of a USING instruction begins where the USING instruction appears in a source module to the end of the source module Assembler/Session 2
Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY The assembler converts implicit address references into their explicit form: • if the address reference appears in the domain of a USING instruction • if the addresses referred to lie within the range of the same USING instruction Guideline: • Specify all USING instructions at the beginning of the source module • Specify a base address in each USING instruction that lies at the beginning of each control section Assembler/Session 2
Objectives RELATIVE ADDRESSINGRELATIVE ADDRESSING • Relative addressing is the technique of addressing instructions and data areas by designating their location in relation to the location counter or to some symbolic location ALPHA LR 3,4 CR 4,6 ALPHA+2 or BETA-4 BCR 1,14 BETA AR 2,3 Note : Always avoid using relative addressing Assembler/Session 2
Assembler LanguageAssembler Language SESSION 3 & 4 Machine Instructions Assembler/Session 3 & 4
Objectives HANDLING CHARACTER DATAHANDLING CHARACTER DATA Move Character Instruction (MVC) • Copy data from one place in memory to another Format : MVC operand1,operand2 S1(L), S2 - implicit D1(L,B1),D2(B2) - explicit e.g... MVC INPUT(5),OUTPUT Assembler/Session 3 & 4
Objectives HANDLING CHARACTER DATAHANDLING CHARACTER DATA Move Immediate Instruction (MVI) • Can move only one byte of constant data to a field Format : MVI operand1,operand2 S1,I2 - implicit D1(B1),I2 - explicit e.g.. MVI CTL,C’B’ Assembler/Session 3 & 4
Objectives HANDLING CHARACTER DATAHANDLING CHARACTER DATA Advanced Techniques 1. Explicit lengths and relative addressing MVC PAD+6(4),=CL4’ ‘ PAD DS CL10 2. Overlapping fields and the MVC instruction MVC FLDB,FLDA FLDA DC C’A’ FLDB DS CL3 Limitation of MVC : Can only move 256 bytes Assembler/Session 3 & 4
Objectives HANDLING CHARACTER DATAHANDLING CHARACTER DATA Moving more than 256 characters: MVCL instruction Uses 2 pairs of even-odd pair of registers Format : MVCL R1,R2 (Both are even registers) Reg R1 – Address of destination R1+1 – Length Reg R2 - Source R2+1 – Padding character (1st 8 bits) and Length Eg: LA 2,Q LA 3,2000 LA 4,P LA 5,1500 MVCL 2,4 Assembler/Session 3 & 4
Objectives HANDLING CHARACTER DATAHANDLING CHARACTER DATA Comparison Instructions • Compares 2 values - the values are found in fields, in registers or in immediate data CLC - Compare logical character e.g. CLC FLDA,FLDB CLI - Compare logical immediate e.g. CLI FLDA,C’K’ Assembler/Session 3 & 4
Objectives Exercise 2 Q1 and Q2 2. What will be the effect of the following instructions : MVI OUTAREA,C’ ‘ MVC OUTAREA+1(132),OUTAREA OUTAREA DS 133C Assembler/Session 3 & 4
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Three types of binary instructions •Full word •Half word •Register The Binary Move Instructions L, LH, LR ,ST, STH Type : R,X Register and indexed storage e.g... L 5,FULL LR 5,7 STH 7,HALF Assembler/Session 3 & 4
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Note : Do not mix up the instruction types and field types e.g. LH 5,FULL - right half of Reg 5 gets 1st 2 bytes at FULL L 6,HALF - Reg 6 gets 4 bytes starting from HALF ST 3,RES - 4 bytes of reg 3 are stored starting from RES RES DS H HALF DC H’15’ FULL DC F’8’ Assembler/Session 3 & 4
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Binary Addition (A, AH and AR) • Fixed-point overflow occurs when the sum will not fit in the receiving register • Type R-X e.g. A 5,FULL AH 6,HALF AR 7,3 Assembler/Session 3 & 4
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Binary Subtraction (S, SH and SR) • Type R-X e.g. S 5,FULL SH 6,HALF SR 7,3 Assembler/Session 3 & 4
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Binary comparisons (C, CH and CR) e.g. C 5,FULL CH 6,HALF CR 7,3 Condition code set as HIGH, LOW or EQUAL Assembler/Session 3 & 4
ObjectivesBinary Multiplication (M, MR, MH) Format : M op1,op2 op1 : An even numbered register; refers to an even-odd pair of registers (any register in case of half word format) op2 : storage area (full word/half word/register) Assembler/Session 3 & 4
Binary Multiplication (M, MR, MH) ... Function : The value in OP2 is multiplied by the value in the odd register of the even-odd pair and the result placed in even-odd registers (For half word format : The half word specified in OP2 is multiplied by the value in OP1 and result stored in OP1.)
Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Binary Division (D, DR) Format: D op1,op2 Type : R-X / R-R Op1 : An even numbered register. It refers to an even-odd pair of registers. The pair holds the double word to be divided. The even register receives the remainder; the odd register receives the quotient. e.g. D 4,FULL Assembler/Session 3 & 4
Objectives BC and BCR Instructions • instructions that do or do not branch depending on the value of the condition code Format : BC M1,S2 BCR M1,R2 e.g. BC B’1001’,BRPTA will cause a branch to the instruction named BRPTA, if at the time the instruction is executed, the condition code is 0 or 3. Assembler/Session 3 & 4
Objectives BRANCHINGBRANCHING A branch causes execution to continue at some other instruction in the program • Branch conditions : Arithmatic B, BZ,BP,BM, BNZ,BNP,BNM,BO,BNO • Comparison BH, BL, BE, BNH, BNL,BNE e.g : CLI FLDA,C’K’ BNL GOOD Assembler/Session 3 & 4
Objectives CONDITION CODE PROCESSINGCONDITION CODE PROCESSING • condition code occupies 2 bits of PSW • condition code is set by each of a number of instructions • condition code is an extremely important intermediary between arithmetic instructions and conditional branch instructions • very important in implementing control structures CC Arithmetic Comparison 0 Zero First operand = Second operand 1 < Zero First operand < Second operand 2 >Zero First operand > second operand 3 Overflow Not set Assembler/Session 3 & 4
Objectives LPR, LNR and LCR Instructions Format: LPR,LNR or LCR R1,R2 LPR - Load positive register (Loads into R1 the absolute value of R2) LNR Load Negative register (Loads into R1 the negative of absolute value of R2) LCR Load complement register (Loads opposite sign of the value in R2) Note: R1 and R2 can be the same Assembler/Session 3 & 4
Objectives BIT MANIPULATIONSBIT MANIPULATIONS Operation S-I S-S R-R R-X OR OI OC OR O AND NI NC NR N Exclusive OR XI XC XR X e.g... OI FLDA,X’0F’ NR 5,7 X 9,FULL Assembler/Session 3 & 4
Objectives BIT MANIPULATIONSBIT MANIPULATIONS OR Second 0 1 AND Second 0 1 First 0 0 1 First 0 0 0 1 1 1 1 0 1 Exclusive OR Second 0 1 First 0 0 1 1 1 0 Assembler/Session 3 & 4
Objectives BIT MANIPULATIONSBIT MANIPULATIONS Testing individual bits - Test under mask (TM) TM S1,I2 Function : The bits of S1 ( a single byte) are tested under the control of the mask in I2 and condition code is set as ‘all zeroes’, all ones’ or ‘mixed’ e.g. TM EMP,B’00000101’ BNM NEXT Assembler/Session 3 & 4
Objectives BIT MANIPULATIONSBIT MANIPULATIONS Bit Shifting Instructions SLL, SLDL Left logical SRL, SRDL Right logical (No condition code set) SLA, SLDA Left arithmetic SRA, SRDA Right arithmetic (Sign bit not affected and condition code set) e.g. SLL 5,1 SRDA 4,5 Assembler/Session 3 & 4
Objectives BIT MANIPULATIONSBIT MANIPULATIONS Bit Shifting Instructions Condition code setting for arithmetic shift instructions 0- Result is zero 1- Result is negative 2- Result is positive 3- Overflow generated Overflow is generated when a bit other than the sign bit is shifted out Assembler/Session 3 & 4
Objectives BIT MANIPULATIONS Translations • To translate from one bit combination to another Format : TR S1(L),S2 or S1,S2 S1 : The field whose data is to be translated S2 : A 256-byte translation table Function : The value of the original byte is used as a displacement into the translation table. The byte found there replaces the original byte. e.g. TR WORK,XTABLE If the source byte is x’40’ (Space), then the displacement into the table is 64. The value in the table at displacement 64 will be replacing the source. Assembler/Session 3 & 4
Objectives BIT MANIPULATIONS Assembler/Session 3 & 4 Translations 1 byte - 256 possible combinations x’00’,x’01’, x’02’, x’03’,…………..x’0F’ x’10’,x’11’,x’12’,…………………..x’1F’ ………………………………………….. x’F1’,x’F2’,x’F3’,…………………x’FF’ The table should start with replacement byte for x’00’ and end with replacement for x’FF’
Objectives BIT MANIPULATIONS (TRT) Assembler/Session 3 & 4 Translations - TRT (Translate and test register) -Similar to TR but the source is not changed -Table is searched similar to TR taking the displacement into the table -Usually employed for editing purposes -The characters we need to search will have non zeros (x’00’) but other characters will be x’00’. -Source is searched one character at a time from left to right -The first nonzero match in the table halts the instruction -Condition code is set to 1 if match found before last byte, 2 if found at the last and 0 if not found -Loads address of source operand if found in last 24 bits of register 1, value from the table into last bit of register 2. No bits are changed in both the registers
Objectives BIT MANIPULATIONS (TRT continued) Assembler/Session 3 & 4 Translations - TRT (Translate and test register) This example searches for a period X’4B’ The period 4B is decimal 75. So the X’4B’ is placed at the 76th position in the table. (Any non zero character may be placed in the table Table should be declared as follows: TABLE DC 75X’00’ DC X’4B’ DC 180X’00’
Objectives Numeric ConversionsNumeric Conversions 1. Conversion to binary (CVB) Format: CVB operand1,operand2 operand1 : Register operand2 : a double word (containing valid packed decimal number) e.g. CVB 5,DOUBLE Use : Character data -(PACK)->Packed decimal-(CVB)-> binary Assembler/Session 3 & 4
Objectives Numeric ConversionsNumeric Conversions 2. Conversion from binary (CVD) Format: CVD operand1,operand2 operand1 : Register operand2 : a double word e.g. CVD 5,DOUBLE Use : Binary-(CVD)->Packed decimal-(UNPK)-> Character data Assembler/Session 3 & 4
Objectives Numeric ConversionsNumeric Conversions 3. Conversion from Zoned decimal to packed (PACK) (SS instruction) Format: PACK operand1,operand2 operand1 : Packed decimal operand2 : Zoned Decimal e.g. PACK PACKED(3),ZONED(5) Assembler/Session 3 & 4
Objectives Numeric ConversionsNumeric Conversions 4 Packed decimal to Zoned decimal (UNPACK) Format: UNPACK operand1,operand2 operand1 : Zoned decimal operand2 : Packed decimal e.g. UNPACK ZD(5),PACKED(2) Assembler/Session 3 & 4
Objectives Relation between CVD,CVB,PACK and UNPACKRelation between CVD,CVB,PACK and UNPACK Assembler/Session 3 & 4 Binary inBinary in RegisterRegister PackedPacked DecimalDecimal ZonedZoned DecimalDecimal CVBCVB PACKPACK InputInput CVDCVD UNPKUNPK OutputOutput
Objectives Example code for Different conversionsExample code for Different conversions Assembler/Session 3 & 4 PACK PNUM(8),START(3)PACK PNUM(8),START(3) CVB 7,PNUMCVB 7,PNUM A 7,=F’1’A 7,=F’1’ CVD 7,PNUMCVD 7,PNUM UNPK ANS(3),PNUM(8)UNPK ANS(3),PNUM(8) …… …… START DC C’125’START DC C’125’ ANS DS CL3ANS DS CL3 PNUM DS DPNUM DS D
Objectives Packed decimal operationsPacked decimal operations Assembler/Session 3 & 4 SS format - OPCODE D1(L1,B1),D2(L2,B2) AP - Add packed SP - Subtract packed ZAP - Zero and add packed MP - Multiply packed DP - Divide packed CP - Compare packed Note: All these operations ignore the decimal places. You have to track the decimal places and edit it with ED and EDMK instructions
Objectives Packed decimal operationsPacked decimal operations Assembler/Session 3 & 4 Advanced instructions: SRP - Shift and Round packed OPCODE D1(L,B1),D2(B2),I3 First operand - Memory location including length Second operand - Direction and number of places to shift Third operand - Whether to round or not ------------------------------------------------------------------------- Second operand, <= 32, left shift is done and 33 to 64 right shift is done. Number for right shift = ( 64 - number of digits to be shifted) (No rounding is involved in left shift
Objectives Packed decimal operationsPacked decimal operations Assembler/Session 3 & 4 Advanced instructions: (SRP continued) NUM is a 5 byte packed decimal number and contains 001234567C. What is the value in number after each of these instructions? 1. SRP NUM(5),2,0 2. SRP NUM(5),62,0 3. SRP NUM(5),62,5 4. SRP NUM(5),60,5
Objectives Packed decimal operationsPacked decimal operations Assembler/Session 3 & 4 Advanced instructions: MVZ - Move Zone (Moves the first half of each byte) MVN - Move numeric (Moves the second half of each byte) MVO - Move with offset EG: Multiply A by 100 where value of A is 123 MVC TEMP(3),A MVN TEMP+2(1),=X’00’ MVZ TEMP+3(1),=X’00’ MVN TEMP+3(1),A+2 A DC PL3’123’ TEMP DS PL4
Objectives Editing the output for printingEditing the output for printing ED and EDMK instructions ( D1(L,B1), D2(B2)) (Pattern and PD number) Patterns: x’20’ - Digit selector x’21’ - Significance selector x’22’ - Field separator x’60’ - Sign indicator Pattern and the packed decimal number processed from left 1 byte at a time X 0 1 2 3 4 5 6 C (Instruction: ED P(12),X) Fill Character P 40 20 20 6B 20 21 20 4B 20 20 60 40 (Before execution) P 40 40 F1 6B F2 F3 F4 4B F5 F6 40 40 (After execution) 1 , 2 3 4 . 5 6 (Last 2 bytes spaces since number is positive) Assembler/Session 3 & 4 …… ……
Objectives Editing the output for printingEditing the output for printing Assembler/Session 3 & 4 Values being examined Action taken Pattern byte PDdigit Newpattern New state of SI Digit selector 0 1-9 Fill character digit in EBCIDIC Off On Significanc e starter 0 1-9 Fill character digit in EBCIDIC On On Field seperator None Fill character Off When the significant indicator is off Anyother byte None Fill character Off Digit selector 0-9 digit in EBCIDIC On Significanc e starter 0-9 digit in EBCIDIC On Field seperator None Fill character Off When the significant indicator is on Anyother byte None Pattern byte notchanged On
Objectives Editing the output for printingEditing the output for printing Assembler/Session 3 & 4 -ED and EDMK can detect the difference between significant and non signi ficant digits ie between leading and non leading zeros - Significance starter forces all subsequent digits to be considered significant -When significance indicator is off and detection of a significant digit turns it on, the address of that significant digit placed in 8-31 of register 1 by EDMK -EDMK allows a floating currency and/or algebraic sign but ED does not allow
Objectives TABLE PROCESSINGTABLE PROCESSING A table is a named storage structure consisting of subunits or entries e.g. RATE DS 6F L 4,RATE+8 Accessing table elements with indexed storage operands: e.g. LH 9,=F8’ L 5,RATE(9) (9 - index register) Assembler/Session 3 & 4
Objectives Multi-purpose branching instructions Convenient when counted repetition structure (table processing) is needed • Branch on count (BCT and BCTR) Format: BCT op1,op2 (R-X) Function: First the op1 value is decremented by 1. Second the branch is taken to the address specified in op2 only if the value in op1 is not 0. e.g. LH 9,=H’12’ REPEAT EQU * .. BCT 9,REPEAT Assembler/Session 3 & 4
Objectives • Branch on index high and branch on index low or equal (BXH and BXLE) Format: BXLE op1,op2,op3 BXH op1 : A register known as the index register op2 : A even-odd pair of registers Even register - increment register Odd register - Limit register op3 : A storage operand. This is the branch address. Assembler/Session 3 & 4
Objectives Function : First, the value in the increment register is added to the indexed register. Second, the branch is taken only when the value in the index register is ‘lower than or equal to’ / ‘higher than’ the value in the limit register Useful when the same register is to be used as the count and index register Assembler/Session 3 & 4
Objectives BXLE - ‘DO UNTIL’ repetitions BXH- ‘DO WHILE’ repetitions e.g... LH 7,=H’0’ index LH 2,=H’2’ increment amount LH 3,=H’18 the limit --- REPEAT ... LH 6,TABLE(7) ... BXLE 7,2,REPEAT Assembler/Session 3 & 4
ObjectivesLoad instructions with additional features • Load and Test (LTR) e.g... LTR 15,15 BNZ ERROR • Load Address (LA) LA R1,D2(X2,B2) Assembler/Session 3 & 4
Objectives USING EQUATESUSING EQUATES • To associate a fixed value with a symbol • Useful for length and relative address calculation e.g. TABLE DS 0H DC C’01 DC C’02’ ... TBLEND EQU * TBLSIZE EQU TBLEND-TABLE Assembler/Session 3 & 4
Objectives USING EQUATESUSING EQUATES Can be used for the following purposes: 1. To assign single absolute values to symbols. 2. To assign the values of previously defined symbols or expressions to new symbols, thus allowing you to use different mnemonics for different purposes. 3. To compute expressions whose values are unknown at coding time or difficult to calculate. The value of the expressions is then assigned to a symbol. Assembler/Session 3 & 4
Assembler LanguageAssembler Language SESSION 5 Program Sectioning Assembler/Session 5
Objectives Beginning and End of Source ModulesBeginning and End of Source Modules •Code a CSECT segment before any statement that affects the location counter •END statement is required as the last statement in the assembly Assembler/Session 5
Objectives CONTROL SECTIONSCONTROL SECTIONS •A source module can be divided into one or more control sections •A control section is the smallest subdivision of a program that can be relocated as a unit Assembler/Session 5
• At coding time, establish the addressability of each control section within the source module, and provide any symbolic linkages between control sections that lie in different source modules. • Initiated by using the START or CSECT instruction CONTROL SECTIONSCONTROL SECTIONS
Objectives CONTROL SECTIONSCONTROL SECTIONS •Any instruction that affects the location counter, or uses its current value, establishes the beginning of the first control section. Assembler/Session 5
Format of CSECT: Name Operation Operand Any symbol CSECT Not required or blank Note: The end of a control section or portion of a control section is marked by (a) any instruction that defines a new or continued control section, or (b) the END instruction. CONTROL SECTIONSCONTROL SECTIONS
Objectives DUMMY SECTIONSDUMMY SECTIONS •A dummy control section is a reference control section that allows you to describe the layout of data in a storage area without actually reserving any virtual storage. Assembler/Session 5
• Use the DSECT instruction to initiate a dummy control section or to indicate its continuation. Format of DSECT: Name Operation Operand Any symbol DSECT Not required or blank DUMMY SECTIONSDUMMY SECTIONS
Objectives DUMMY SECTIONSDUMMY SECTIONS To use a dummy section : • Reserve a storage area for the unformatted data • Ensure that this data is loaded into the area at execution time Analogy: Cobol copybook Assembler/Session 5
• Ensure that the locations of the symbols in the dummy section actually correspond to the locations of the data being described • Establish the addressability of the dummy section in combination with the storage area You can then refer to the unformatted data symbolically by using the symbols defined in the dummy section. DUMMY SECTIONSDUMMY SECTIONS
Objectives ASMBLY2 CSECT BEGIN BALR 2,0 USING *,2 ... Reg 3 points to data area LA 3,INPUT USING INAREA,3 CLI INCODE,C'A' BE ATYPE ... ATYPE MVC WORKA,INPUTA MVC WORKB,INPUTB . . Assembler/Session 5
WORKA DS CL20 WORKB DS CL18 INPUT DS CL39 ... INAREA DSECT INCODE DS CL1 INPUTA DS CL20 INPUTB DS CL18 ...
Objectives Assembler DirectivesAssembler Directives TITLE : To provide headings for each page of the assembly listing of the source modules. EJECT : To stop the printing of the assembler listing on the current page, and continue the printing on the next page. ORG : To reset the location counter Assembler/Session 5
LTORG : A literal pool is created immediately after a LTORG instruction or, if no LTORG instruction is specified, at the end of the first control section. PRINT : To control the amount of detail to be printed in the listing of programs. PRINT NOGEN / GEN Assembler DirectivesAssembler Directives
Assembler LanguageAssembler Language SESSION 6 Writing a complete program Assembler/Session 6
Objectives Program Entry and Exit LogicProgram Entry and Exit Logic Program entry - Preserve register contents Program Exit - Restore register contents Register save area Always calling program provides a save area of 18 Full words long used for storage of registers Save area address passed through register 13 by IBM convention Assembler/Session 6
Objectives A register save area (18 consecutive full words) Word Address Contents 1 SAV 2 SAV+4 Address of calling program’s save area 3 SAV+8 Address of called program’s save area 4 SAV+12 Contents of Register 14 5 SAV+16 Contents of Register 15 6 SAV+20 Contents of Register 0 ... 18 SAV+68 Contents of Register 12 Assembler/Session 6
Objectives Responsibilities of called program Program entry conventions 1.Save contents of registers 0-12,14 & 15 in calling program’s save area 2.Establish base register 3.Store calling program’s save area in the 2nd word of its own save area Assembler/Session 6
Objectives Program entry conventions (contd..) 4. Store the address of its register save area in the third word of the calling program’s register save area (The addresses in the 3d word of save area establish a chain of register save areas. This will be useful in reading the dump when program crashes). Assembler/Session 6
Objectives Responsibilities of called program (contd..) Program Entry STM R14,R12,12(R13) BALR R12,0 USING *,R12 ST R13,SAVOWN+4 store calling programs save area LR R14,R13 LA R13,SAVOWN Reg 13 contains current prog’s SA ... ST R13,8(R14) Assembler/Session 6
Objectives Responsibilities of called program (contd..) Program Exit conventions 1. Restore registers 0-12 and 14 2. Place the address of the save area provided by the calling program in Reg 13 3. Place a return code in the low order byte of register 15 if one is required. Otherwise restore register 15. Assembler/Session 6
Objectives Responsibilities of called program (contd..) Program Exit L R13,4(R13) LM R14,R12,12(R13) BR R14 Assembler/Session 6
Objectives Responsibilities of calling program 1. Register 13 must contain the address of a register save area. 2. Register 15 should be set to the beginning address of the subroutine L R15,=V(SUBENTRY) where SUBENTRY is the entry address (usually the CSECT name) of the subroutine Assembler/Session 6
Objectives Responsibilities of calling program (contd...) 3. Register 14 should have the return address 4. Register 1 should have the address of the parameter list A BALR instruction stores the address of the next instruction in the calling program into register 14 and transfers control to the called subroutine BALR R14,R15 Assembler/Session 6
Objectives Passing parameters to a subroutine • The standard interface requires that addresses of parameters be placed in a block of storage, and the address of the block be loaded into register 1 as the subroutine is called • Both input and output parameters are treated the same way e.g... ADDS DC A(T) DC A(U) DC A(V) LA R1,ADDS Assembler/Session 6
Objectives R1 Main storage Addr of parmlist Parmlist parm3 Addr of parm1 Addr of parm2 parm1 Addr of parm3 parm2 Assembler/Session 6
Objectives Called subroutine B may get the second parameter by L R3,4(,R1) L R8,0(,R3) Assembler/Session 6
Objectives Registers with special use R0 : Contains single word output of a subroutine R1 : contains the address of an area of main storage that contains addresses of parameters Assembler/Session 6
Objectives Registers with special use (contd...) R14 : Contains the return address, the address in the calling routine to which a subroutine should return control when finished R15 : contains the address of the entry point in the subroutine R13 : contains the address of an area in which register contents can be stored by a subroutine Assembler/Session 6
Objectives The subroutine RANDOM RANDOM STM R14,R12,12(R13) BALR R12,0 USING *,R12 L R7,RN M R6,=F’65541’ ST R7,RN LR R0,R7 LM R1,R12,24(R13) BR R14 RN DC F’8193’ Assembler/Session 6
Objectives Subroutine RDIGIT RDIGIT STM R14,R12,12(R13) BALR R12,0 USING *,R12 ST R13,SAV+4 LA R13,SAV ... L R15,RANDAD BALR R14,R15 ... L R13,SAV+4 LM R14,R15,12(R13) LM R1,R12,24(R13) BR R14 SAV DS 18F RANDAD DC A(RANDOM) Assembler/Session 6
Objectives Linkage ConventionsLinkage Conventions •Program divided into 2 or more source modules •Source module divided into 2 or more control sections •For link-editing, a complete object module or any individual control section of the object module can be specified Assembler/Session 6
Objectives Communicating between program parts • To communicate between 2 or more source modules, symbolically link them together • To communicate between 2 or more control sections within a source module, establish proper addressability Assembler/Session 6
Objectives Establishing symbolic linkage • Identify external symbols in the EXTRN or WXTRN instruction or the V-type address constant • provide A-type or V-type address constants to reserve storage for addresses represented by external symbols • In the external source modules, identify these symbols with the ENTRY instruction (name entry of a START or CSECT instruction is automatically identified as an entry symbol) External symbol dictionary Assembler/Session 6
Objectives Establishing symbolic linkage (contd...) e.g. program A EXTRN TABLEB WXTRN TABLEB TABADR DS V(TABLEB) program B ENTRY TABLEB TABLEB DS ... Assembler/Session 6
Objectives Address Constants (A and V) • An address constant is a main storage address contained in a constant • A V-type constant is the value of an external symbol - a relocatable symbol that is external to the current control section. Used for branching to locations in other control sections e.g L 5,ADCON ADCON DC A(SOMWHERE) GSUBAD DC V(READATA) Assembler/Session 6
Assembler LanguageAssembler Language SESSION 7 Assemble and Link Program Assembler/Session 7
Objectives Processing of Instructions Time/ M/C Assembler ENTRY Macro Activity instructions. EXTRN Instr. Code source m/c DC,DS instruc. Preassembly Refer to macro instruc. Assembly object code LKED Prog fetch Execution data area form data area in load mod Processing of Instructions Time/ M/C Assembler ENTRY Macro Activity instructions. EXTRN Instr. Code source m/c DC,DS instruc. Preassembly Refer to macro instruc. Assembly object code LKED Prog fetch Execution data area form data area in load mod Assembler/Session 7
Objectives JCL ‘ parm’ processing EXEC PGM=pgmname,PARM= When program gets control : •Register 1 contains the address of a full word on a full word boundary in program’s address space •the high order bit of this full word is set to 1 (this convention is to indicate the last word in a variable length parameter list) Assembler/Session 7
JCL ‘ parm’ processing ... • Bits 1-31 of the full word contain the address of a 2-byte length field on a half word boundary • The length field contains a binary count of the no. of bytes in the PARM field which immediately follows the length field
Objectives COBOL to Assembler CALL asmpgm USING COMM-AREA PL/I to Assembler DCL ASMSUB ENTRY OPTIONS(ASSEMBLER) CHARSTRING CHAR(25); CALL ASMSUB(CHARSTRING); Ref : PL/I Programming Guide, COBOL programming Guide Assembler/Session 7
Assembler LanguageAssembler Language SESSION 8 Macro Language Assembler/Session 8
ObjectivesMacros • Short source routines written and stored in libraries •Assembler inserts the source statements in the program where the macro appears Assembler/Session 8
Macro Definition Format : •A header statement •A prototype •Model statements •A trailer statement
Objectives Header statement: MACRO Prototype: &name MOVE &TO,&FROM,&LENGTH Model statements: A set of machine and assembler instructions Trailer statement: &name MEND Assembler/Session 8
Objectives Macro Instruction: • A statement containing the name of a macro • when expanded, the symbolic parameters in the model statements are replaced by corresponding parameters from the macro instructions • symbolic parameters may be positional or keyword Assembler/Session 8
Macro Instruction ... MACRO &LABEL HALFSWAP &REG,&SV &LABEL ST &REG,&SV SLL &REG,8 IC &REG,&SV SLL &REG,8 IC &REG,&SV+1 MEND
Objectives SET Symbols (global or local) 3 types : • arithmetic (SETA) • binary (SETB) • character (SETC) • SET symbols are declared using, LCLA LCLB LCLC GCLA GCLB GCLC Assembler/Session 8
Objectives Format: Label operation operands symbol-name SETA An expression SETB SETC e.g. LCLA &A1 GCLA &A2 &A1 SETA 1 &A2 SETA &A1+3 Assembler/Session 8
Objectives Attributes There are 6 attributes of a symbol or symbolic parameter : type, length, scaling, integer, count and number System variable symbols &SYSINDX, &SYSDATE, &SYSTIME, &SYSECT, &SYSPARM, &SYSLOC Assembler/Session 8
Objectives Conditional Assembly The assembler can be made to branch and loop among assembler language statements using sequence symbols and the assembler instructions AIF and AGO Sequence symbol : Period followed by 1 to 7 alphabets or digits of which the first is a letter e.g. .Z23Ab Assembler/Session 8
Objectives Format: Label Operation Operand seq symbol AGO seq. symbol or blank -do- AIF A logical expression enclosed in parenthesis, followed by seq symbol Assembler/Session 8
A logical expression is composed of one or more relations or values of SETB symbols connected by logical connects AND, OR, AND NOT, OR NOT A relation consists of 2 arithmetic expressions or 2 character expressions connected by a relational operator EQ, NE, LT, LE, GT, GE
Objectives e.g. MACRO PSRCH &PARAMS,&STRING GBLB &FOUND LCLA &I &FOUND SETB 0 .LP AIF ((&I GE N’&PARAMS) OR &FOUND) .E &I SETA &I+1 &FOUND SETB (‘&PARAMS(&I)’ EQ ‘&STRING’) AGO .LP .E MEND Assembler/Session 8
Objectives Accessing QSAM files: Keywords in DCB parameter: DSORG PS Physical sequential RECFM F,FA,FB,FBA,V,VBA BLKSIZE Block length LRECL Record Length DDNAME Dataset name in JCL MACRF Macro GM - Get Move GL - Get Locate PM - Put Move PL - Put locate Move parameter directly puts the record in the storage area specified while Locate mode Loads the address of the record in Register 1 Assembler/Session 8
Objectives Accessing VSAM files: ACB macro AM - VSAM (For documentation) BUFND - No. of I/O buffers for data control intervals BUFNI - No. of I/O buffers for index control intervals BUFSP - Size of an area for data and Index I/O buffers DDNAME - Filename used in the DD statement. If omitted refers to the ACB macro name EXLST - Address to the EXLST macro. Generates a list of addresses for user routines MACRF - Types of processing the file will do Assembler/Session 8
Objectives Accessing VSAM files: ACB macro (Continued) EXLST options: AM - VSAM EODAD = (Address, A/N, L) (Load module) EXCPAD = (Address, A/N, L) (Load module) JRNAD = (Address, A/N, L) (Load module) LERAD = (Address, A/N, L) (Load module) SYNAD = (Address, A/N, L) (Load module) Active/No, Stored in load module Assembler/Session 8
Objectives Accessing VSAM files: RPL macro (Request parameter list) ACB - Address of the ACB macro AREA - Address of the work area to be used AREALEN - Length of the work area (Should be large enough to hold largest record in Move mode and at least 4 bytes in the Locate mode) RECLEN -Length of the records in the file (For VB you have to put the length before writing using MODCB) ARG - Label containing the key for the search (Key for KSDS, RRN for RRDS and RBA for ESDS) OPTCD - 5 sets of groups of parameters Assembler/Session 8
Objectives Accessing VSAM files: RPL macro (Continued) Options for OPTCD: KEY/CNV/ADR - Access by key,Control interval or Relative byte address SEQ/DIR/SKP - Sequential processing,Direct, Skip sequential FWD/BWD - Forward sequential processing,Backward ARD/LRD -Start seq.processing with ARG specified/ Backward processing from the last record NUP/NSP/UPD - No updating(Next rec not ready),No updating Next rec ready(DA only), Record updating) MVE/LOC - Move mode/ Locate mode Assembler/Session 8
Objectives Accessing VSAM files: OPEN - Open the file CLOSE - Close the file GET - Read a record PUT - Store a record ERASE - Delete a record POINT - Position for access Advanced macros: SHOWCB, TESTCB, MODCB Assembler/Session 8
Assembler LanguageAssembler Language SESSION 9 Other Topics Assembler/Session 9
ObjectivesCharacteristics of good assembler program • has simple, easy to understand logic • uses mostly simple instructions • has no relative addressing • uses subroutines Assembler/Session 8
Characteristics of good assembler program ... • uses DSECTs • has efficient code (LA R10, 4(0,R10 - A R10,=F’4) • does not abnormally terminate due to user error • requests and check feedback from macro instructions • provides meaningful error messages
Objectives Characteristics of good assembler program (contd..) • lets the assembler determine lengths • has opcodes, operand and comments aligned • contains meaningful comments • uses meaningful labels Assembler/Session 8
Objectives Structured Programming • To improve design and understandability of a program • made up of building blocks of subroutines Conventions for general purpose registers • Base registers • Link registers Assembler/Session 8
Objectives The EXecute Instruction • the EX instruction is a R-X type instruction that directs the execution of an instruction called the subject instruction, which is addressed by the second operand • the subject instruction is in effect a one-instruction subroutine Assembler/Session 9
•The subject instruction is modified before execution (though not altered at its main storage location) : bits 8-15 of the instruction ORed with bits 24-31 of register R1 to form the second byte of the instruction actually executed e.g. Let reg 9 have the length of string to be moved EX R9,VARMVC VARMVC MVC A(0),B The EXecute Instruction (contd...)
Objectives DEBUGGINGDEBUGGING Exceptions and Interrupts Interrupts that result directly from attempts at invalid program execution are called program-check interrupts; identified by a code Interruption code 1 : Operation Interruption code 2 : Privileged operation Interruption code 4 : Protection Interruption code 5 :Addressing Interruption code 6 :Specification Assembler/Session 9
Objectives DEBUGGING Exceptions and Interrupts (contd..) Interruption code 7 : Data Interruption code 8 : Fixed-Point Overflow Interruption code 9 : Fixed-Point Divide Other Interruption codes ( 3, 10, 11, 12, 13, 14, 15) Assembler/Session 9
Objectives DEBUGGINGDEBUGGING Reading dumps • whenever a program abends an indicative dump is generated • The completion code is a code furnished by the O/S to designate the reason for the termination of the job step • In case of program check interruption, the first 2 digits of the completion code is 0C Assembler/Session 9
• Locate the entry point of your program Reading dumps ... DEBUGGINGDEBUGGING
Objectives DEBUGGINGDEBUGGING Reading dumps (contd...) • The register contents are the contents at the point of interruption (the instruction that caused the interrupt is usually the one just before the interrupt address given) • use address at interrupt and entry address to locate the instruction that caused the program- check interruption Assembler/Session 9
Objectives DEBUGGINGDEBUGGING Full and Partial dumps • //SYSUDUMP DD SYSOUT=A • SNAP macro Assembler/Session 9
Reading the dump • SAVE AREA trace • P/P Storage • Examine register contents, PSW and listed entry point to find the portion of program being executed • Look at main storage dump to determine the data being used DEBUGGINGDEBUGGING
Objectives SYSTEM MACROSSYSTEM MACROS Data Management Macros DCB - Construct a data control block OPEN - Logically connect a dataset CLOSE - Logically disconnect a dataset GET - Obtain next logical record (queued access) PUT - Write next logical record (queued access) READ - Read a block (basic access) WRITE - Write a block (basic access) Assembler/Session 9
Objectives SYSTEM MACROSSYSTEM MACROS Supervisor Services Macros ABEND - Abnormally terminate a task CALL - Pass control to a control section GETMAIN - Allocate virtual storage FREEMAIN - Free virtual storage LOAD - Bring a load module into virtual storage RETURN - return control to the calling program SAVE - Save register contents Assembler/Session 9
Objectives SYSTEM MACROSSYSTEM MACROS Supervisor Services Macros (contd) SNAP - Dump virtual storage and continue LINK - Pass control to a Program in Another load module WTO - Write to operator Assembler/Session 9
Objectives SYSTEM MACROSSYSTEM MACROS e.g. File I/O OPEN (INFILE,INPUT) GET INFILE,RECAREA PUT OUTFILE,RECAREA CLOSE (INFILE) INFILE DCB DSORG=PS,MACRF=GM,DDNAME=IFILE OUTFILE DCB DSORG=PS,MACRF=PM,DDNAME=OFILE (RECFM=,LRECL=,BLKSIZE=,) Assembler/Session 9
Objectives SYSTEM MACROSSYSTEM MACROS Three forms : Standard form : Results in instructions that store into an inline parameter list and pass control to the required program List form : Provides as out-of-line parameter list Execute form : Provides the executable instructions required to modify the out-of-line parameter list and pass control to the required program Assembler/Session 9
Thank you Thank you

Assembler Language Tutorial for Mainframe Programmers

  • 1.
    Assembler/Session 1 Assembler LanguageAssemblerLanguage forfor Mainframe ProgrammersMainframe Programmers
  • 2.
    Objectives • Familiarize withIBM 370 Assembly Language ObjectivesObjectivesObjectivesObjectives Assembler/Session 1
  • 3.
    SESSION 1SESSION 1 Day1Day 1 Introduction SESSION 2SESSION 2 Day 1Day 1 Addressing SESSION 3SESSION 3 Day 2Day 2 Machine Instructions Assembler/Session 1 COURSE SCHEDULECOURSE SCHEDULE
  • 4.
    Writing a completeprogram SESSION 4SESSION 4 Day 3Day 3 Program Sectioning SESSION 5SESSION 5 Day 3Day 3 Assembler Directives SESSION 6SESSION 6 Day 3Day 3 Assemble and link programSESSION 7SESSION 7 Day 4Day 4 COURSE SCHEDULE Assembler/Session 1
  • 5.
    Macro LanguageSESSION 8SESSION8 Day 4Day 4 Other TopicsSESSION 9SESSION 9 Day 5Day 5 Assembler/Session 1 COURSE SCHEDULE
  • 6.
  • 7.
    Objectives • An assemblerlanguage is a symbolic form of machine language • Assembler translates assembler language program to machine language • An assembler program consists of many statements • In general, one assembler language statement corresponds to one machine language instruction INTRODUCTIONINTRODUCTION Assembler/Session 1
  • 8.
    Objectives STATEMENT FORMATSTATEMENT FORMAT 110 16 30 label operation operands comments e.g.. INIT1 LA R5,4 ;INITIALISE REGISTER 5 Rules for choosing labels:Rules for choosing labels: • maximum 8 characters • Alphabets, digits, @, #, $ • First character should not be a digit • label should begin in column 1 Assembler/Session 1
  • 9.
    Objectives Col1 Col10 Col.16 L2,A A 2,B ST 2,ANS ….. ….. A DC F’15’ B DC F’20’ ANS DS F Sample programSample program Assembler/Session 1
  • 10.
    Objectives STATEMENT FORMATSTATEMENT FORMAT Operation •One of the 200 M/C instruction mnemonics (eg. MVC) Operand • can be a register or memory location Continuing a statement • Place any character in column 72 of the line to be continued • Continue the statement from column 16 of next line • Maximum 2 continuation lines for a statement Assembler/Session 1
  • 11.
    Objectives STATEMENT FORMATSTATEMENT FORMAT CommentStatement • * in column 1 • Any text in columns 2 - 71 Note : Fields separated by one or more blanks Assembler/Session 1
  • 12.
    Objectives TYPES OF INSTRUCTIONSTYPESOF INSTRUCTIONS 1. Machine Instructions 2. Assembler Instructions (Directives) 3. Macro Instructions Assembler/Session 1
  • 13.
    Objectives REGISTERSREGISTERS Registers are storageareas inside the processor Advantages: - No need to retrieve data from main storage (saves time) - Shared resource that allows inter communication between programs Assembler/Session 1
  • 14.
    Objectives REGISTERSREGISTERS General purpose registers: *16 registers available * Numbered 0 - 15 * Holds 32 bits (4 bytes) of data (1 Full word) Floating point registers: * 4 registers available * Numbered 0,2,4,6 * Holds 64 bits (8 bytes) of data Note : The registers 0, 1, 13, 14 and 15 are reserved for special purpose By IBM convention these registers are used for calling subprograms Assembler/Session 1
  • 15.
    Objectives DATA REPRESENTATIONDATA REPRESENTATION Binaryfields - Always fixed in length, either 2 or 4 bytes (Full word or Half word) - Negative numbers stored in 2’s complement form Examples: A DC H’295’ 01 27 B DC H’-75’ FF 35 Assembler/Session 1
  • 16.
    Objectives 2’s complement form2’scomplement form Assembler/Session 1 How to identify a negative number?How to identify a negative number? -- Leading bit contains a 1 (In Hex 8 to F)Leading bit contains a 1 (In Hex 8 to F) How to convert to a negative numberHow to convert to a negative number?? -First switch the bits (1 to 0 , 0 to 1)First switch the bits (1 to 0 , 0 to 1) -Finally add 1Finally add 1
  • 17.
    Objectives Boundary requirementsBoundary requirements Assembler/Session1 Full word – Should begin in a full word boundary (Achieved by aligning with 0F) Half word – Should begin in a half word boundary (Achieved by aligning with 0H) How to find: The starting address of Full word should end with 0, 4, 8 or C and Half words should end with 0, 2, 4, 6, 8, A, C or E
  • 18.
    Objectives DATA REPRESENTATIONDATA REPRESENTATION Characters -One byte (EBCDIC form) - Character representation of decimal digits is called Zoned Decimal (first nibble is zone and next is digit) Zone digit Zone Code 0 - 9 + C, A,E,F - D, B +, - , blank Blank F Assembler/Session 1
  • 19.
    Objectives DATA REPRESENTATIONDATA REPRESENTATION FloatingPoint Numbers - Always fixed in length, 4, 8 or 16 bytes (Full word, double word, double double word) - Left most bit represents sign (0 - positive; 1 - negative) - Next 7 bits represent exponent - Remaining bytes represent the fraction Assembler/Session 1
  • 20.
    Objectives DATA REPRESENTATIONDATA REPRESENTATION Decimalnumbers ( Packed Decimal representation) - Each byte but the rightmost has 2 decimal digits (0-9) - The right most byte contains a digit in the left half and a sign indicator in the right Sign indicator: C- Positive D - Negative Example: 753 - 7 5 3 C Assembler/Session 1
  • 21.
    Objectives Addressing Operands • Registeraddressing • Base, displacement addressing • Base, index and displacement addressing Assembler/Session 1
  • 22.
    Objectives INSTRUCTION FORMATS RR opcodeR1 R2 SI opcode I2 B1 D1 SS opcode L B1 D1 B2 D2 SS opcode L1 L2 B1 D1 B2 D2 RX opcode R1 X2 B2 D2 RS opcode R1 R3 B2 D2 Assembler/Session 1
  • 23.
    Objectives Addressing RX Operands: Implicitformat: L 3,VAR Explicit format: L 3,100(0,12) Register Displacement Index reg Base reg Assembler/Session 1
  • 24.
    Assembler LanguageAssembler Language SESSION2SESSION 2 Addressing Assembler/Session 2
  • 25.
    ObjectivesSTORAGE DEFINITIONSSTORAGE DEFINITIONS Twoways to define fields : 1. Define a field and initialize the data in it using the DC assembler directive 2. Define a field without initializing using the DS assembler directive Assembler/Session 2
  • 26.
    Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS Format: label{DS/DC} dtLn’value’ where : label : Label used to name the field (optional) d : Duplication factor (optional) t : Type of data ( required) Ln : The letter ‘L’ followed by the length of the field in bytes (optional) value : Represents the value enclosed in apostrophes Assembler/Session 2
  • 27.
    Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS Examples: ALPHADC C’ABC EF’ FLDS DS 3CL2 H1 DC H’29’ F2 DC F’-10’ F1 DC X’03’ F3 DC PL4’-72’ Note : for character constants truncation or padding is to the right and for almost all others it is to the left. Assembler/Session 2
  • 28.
    Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS DCTYPES Type Implied Alignment Data Representation Length C - None Character X - None Hex digits B - None Binary digits F 4 Full word Binary H 2 Half word Binary E 4 Full word Floating point D 8 Double word Floating point L 16 Double word Floating point P - None Packed decimal Assembler/Session 2
  • 29.
    Objectives STORAGE DEFINITIONSSTORAGE DEFINITIONS DataRepresentation in other languages: Assembler FORTRAN COBOL PASCAL BASIC Language DC Type C Character Display String String F, H Integer COMP Integer Integer E Real COMP-1 Real Single precision D Double COMP-2 Real Double Precision Precision X, B Logical N/A Boolean Hex P N/A COMP-3 N/A N/A Assembler/Session 2
  • 30.
    Objectives STORAGE DEFINITIONS Literals • Aliteral is a constant preceded by an equals sign ‘=‘. • Can be used as a main-storage operand but not as a destination field of an instruction • Causes assembler to define a field that is initialized with the data specified • All constants defined by literals are put by the assembler in a literal pool, usually at the very end of the program (Unless changed by LTORG instruction) L R4,=F’1’ Assembler/Session 2
  • 31.
    Objectives Exercise 1 Q1 and Q2. 2.What will happen in the following cases DC CL5’123’ DC CL5’123456’ DC X’A1245’ DC XL2’A1245’ DC XL5’A1245’ DC F’19’ DC FL1’513’ Assembler/Session 2
  • 32.
    Objectives EQU (Assembler directive) •The EQU statement is used to associate a fixed value with a symbol R4 EQU 4 DRBACK EQU OUT+25 Assembler/Session 2
  • 33.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY •By establishing the addressability of a coding section, you can refer to the symbolic addresses defined in it in the operands of machine instruction • Assembler will convert the implicit addresses into explicit addresses (base - displacement form) Assembler/Session 2
  • 34.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Toestablish the address of a coding section : • Specify a base address from which the assembler can compute displacements • Assign a base register to contain this base address • Write the instruction that loads the base register with the base address Note: The base address should remain in the base register throughout the execution of the program Assembler/Session 2
  • 35.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY EstablishingBase Register The USING and DROP assembler instructions enable one to use expressions representing implicit addresses as operands of machine instruction statements, leaving the assignment of base registers and the calculation of displacements to the assembler USING - Use Base Address Register - allows one to specify a base address and assign one or more base registers Assembler/Session 2
  • 36.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Touse the USING instruction correctly, one should know : • which locations in a coding section are made addressable by the USING statement • where in a source module you can use these established addresses as implicit addresses in instruction operands Format: symbol USING base address,basereg1| basereg2|,.. e.g. USING BASE,9,10,11 USING *,12 Assembler/Session 2
  • 37.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Rangeof a USING instruction: • The range of a USING instruction is the 4096 bytes beginning at the base address specified in the USING instruction Domain of a USING instruction • The domain of a USING instruction begins where the USING instruction appears in a source module to the end of the source module Assembler/Session 2
  • 38.
    Objectives ESTABLISHING ADDRESSABILITYESTABLISHING ADDRESSABILITY Theassembler converts implicit address references into their explicit form: • if the address reference appears in the domain of a USING instruction • if the addresses referred to lie within the range of the same USING instruction Guideline: • Specify all USING instructions at the beginning of the source module • Specify a base address in each USING instruction that lies at the beginning of each control section Assembler/Session 2
  • 39.
    Objectives RELATIVE ADDRESSINGRELATIVE ADDRESSING •Relative addressing is the technique of addressing instructions and data areas by designating their location in relation to the location counter or to some symbolic location ALPHA LR 3,4 CR 4,6 ALPHA+2 or BETA-4 BCR 1,14 BETA AR 2,3 Note : Always avoid using relative addressing Assembler/Session 2
  • 40.
    Assembler LanguageAssembler Language SESSION3 & 4 Machine Instructions Assembler/Session 3 & 4
  • 41.
    Objectives HANDLING CHARACTER DATAHANDLINGCHARACTER DATA Move Character Instruction (MVC) • Copy data from one place in memory to another Format : MVC operand1,operand2 S1(L), S2 - implicit D1(L,B1),D2(B2) - explicit e.g... MVC INPUT(5),OUTPUT Assembler/Session 3 & 4
  • 42.
    Objectives HANDLING CHARACTER DATAHANDLINGCHARACTER DATA Move Immediate Instruction (MVI) • Can move only one byte of constant data to a field Format : MVI operand1,operand2 S1,I2 - implicit D1(B1),I2 - explicit e.g.. MVI CTL,C’B’ Assembler/Session 3 & 4
  • 43.
    Objectives HANDLING CHARACTER DATAHANDLINGCHARACTER DATA Advanced Techniques 1. Explicit lengths and relative addressing MVC PAD+6(4),=CL4’ ‘ PAD DS CL10 2. Overlapping fields and the MVC instruction MVC FLDB,FLDA FLDA DC C’A’ FLDB DS CL3 Limitation of MVC : Can only move 256 bytes Assembler/Session 3 & 4
  • 44.
    Objectives HANDLING CHARACTER DATAHANDLINGCHARACTER DATA Moving more than 256 characters: MVCL instruction Uses 2 pairs of even-odd pair of registers Format : MVCL R1,R2 (Both are even registers) Reg R1 – Address of destination R1+1 – Length Reg R2 - Source R2+1 – Padding character (1st 8 bits) and Length Eg: LA 2,Q LA 3,2000 LA 4,P LA 5,1500 MVCL 2,4 Assembler/Session 3 & 4
  • 45.
    Objectives HANDLING CHARACTER DATAHANDLINGCHARACTER DATA Comparison Instructions • Compares 2 values - the values are found in fields, in registers or in immediate data CLC - Compare logical character e.g. CLC FLDA,FLDB CLI - Compare logical immediate e.g. CLI FLDA,C’K’ Assembler/Session 3 & 4
  • 46.
    Objectives Exercise 2 Q1and Q2 2. What will be the effect of the following instructions : MVI OUTAREA,C’ ‘ MVC OUTAREA+1(132),OUTAREA OUTAREA DS 133C Assembler/Session 3 & 4
  • 47.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Threetypes of binary instructions •Full word •Half word •Register The Binary Move Instructions L, LH, LR ,ST, STH Type : R,X Register and indexed storage e.g... L 5,FULL LR 5,7 STH 7,HALF Assembler/Session 3 & 4
  • 48.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Note: Do not mix up the instruction types and field types e.g. LH 5,FULL - right half of Reg 5 gets 1st 2 bytes at FULL L 6,HALF - Reg 6 gets 4 bytes starting from HALF ST 3,RES - 4 bytes of reg 3 are stored starting from RES RES DS H HALF DC H’15’ FULL DC F’8’ Assembler/Session 3 & 4
  • 49.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS BinaryAddition (A, AH and AR) • Fixed-point overflow occurs when the sum will not fit in the receiving register • Type R-X e.g. A 5,FULL AH 6,HALF AR 7,3 Assembler/Session 3 & 4
  • 50.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS BinarySubtraction (S, SH and SR) • Type R-X e.g. S 5,FULL SH 6,HALF SR 7,3 Assembler/Session 3 & 4
  • 51.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS Binarycomparisons (C, CH and CR) e.g. C 5,FULL CH 6,HALF CR 7,3 Condition code set as HIGH, LOW or EQUAL Assembler/Session 3 & 4
  • 52.
    ObjectivesBinary Multiplication (M,MR, MH) Format : M op1,op2 op1 : An even numbered register; refers to an even-odd pair of registers (any register in case of half word format) op2 : storage area (full word/half word/register) Assembler/Session 3 & 4
  • 53.
    Binary Multiplication (M,MR, MH) ... Function : The value in OP2 is multiplied by the value in the odd register of the even-odd pair and the result placed in even-odd registers (For half word format : The half word specified in OP2 is multiplied by the value in OP1 and result stored in OP1.)
  • 54.
    Objectives BINARY INSTRUCTIONSBINARY INSTRUCTIONS BinaryDivision (D, DR) Format: D op1,op2 Type : R-X / R-R Op1 : An even numbered register. It refers to an even-odd pair of registers. The pair holds the double word to be divided. The even register receives the remainder; the odd register receives the quotient. e.g. D 4,FULL Assembler/Session 3 & 4
  • 55.
    Objectives BC and BCRInstructions • instructions that do or do not branch depending on the value of the condition code Format : BC M1,S2 BCR M1,R2 e.g. BC B’1001’,BRPTA will cause a branch to the instruction named BRPTA, if at the time the instruction is executed, the condition code is 0 or 3. Assembler/Session 3 & 4
  • 56.
    Objectives BRANCHINGBRANCHING A branch causesexecution to continue at some other instruction in the program • Branch conditions : Arithmatic B, BZ,BP,BM, BNZ,BNP,BNM,BO,BNO • Comparison BH, BL, BE, BNH, BNL,BNE e.g : CLI FLDA,C’K’ BNL GOOD Assembler/Session 3 & 4
  • 57.
    Objectives CONDITION CODE PROCESSINGCONDITIONCODE PROCESSING • condition code occupies 2 bits of PSW • condition code is set by each of a number of instructions • condition code is an extremely important intermediary between arithmetic instructions and conditional branch instructions • very important in implementing control structures CC Arithmetic Comparison 0 Zero First operand = Second operand 1 < Zero First operand < Second operand 2 >Zero First operand > second operand 3 Overflow Not set Assembler/Session 3 & 4
  • 58.
    Objectives LPR, LNR andLCR Instructions Format: LPR,LNR or LCR R1,R2 LPR - Load positive register (Loads into R1 the absolute value of R2) LNR Load Negative register (Loads into R1 the negative of absolute value of R2) LCR Load complement register (Loads opposite sign of the value in R2) Note: R1 and R2 can be the same Assembler/Session 3 & 4
  • 59.
    Objectives BIT MANIPULATIONSBIT MANIPULATIONS OperationS-I S-S R-R R-X OR OI OC OR O AND NI NC NR N Exclusive OR XI XC XR X e.g... OI FLDA,X’0F’ NR 5,7 X 9,FULL Assembler/Session 3 & 4
  • 60.
    Objectives BIT MANIPULATIONSBIT MANIPULATIONS ORSecond 0 1 AND Second 0 1 First 0 0 1 First 0 0 0 1 1 1 1 0 1 Exclusive OR Second 0 1 First 0 0 1 1 1 0 Assembler/Session 3 & 4
  • 61.
    Objectives BIT MANIPULATIONSBIT MANIPULATIONS Testingindividual bits - Test under mask (TM) TM S1,I2 Function : The bits of S1 ( a single byte) are tested under the control of the mask in I2 and condition code is set as ‘all zeroes’, all ones’ or ‘mixed’ e.g. TM EMP,B’00000101’ BNM NEXT Assembler/Session 3 & 4
  • 62.
    Objectives BIT MANIPULATIONSBIT MANIPULATIONS BitShifting Instructions SLL, SLDL Left logical SRL, SRDL Right logical (No condition code set) SLA, SLDA Left arithmetic SRA, SRDA Right arithmetic (Sign bit not affected and condition code set) e.g. SLL 5,1 SRDA 4,5 Assembler/Session 3 & 4
  • 63.
    Objectives BIT MANIPULATIONSBIT MANIPULATIONS BitShifting Instructions Condition code setting for arithmetic shift instructions 0- Result is zero 1- Result is negative 2- Result is positive 3- Overflow generated Overflow is generated when a bit other than the sign bit is shifted out Assembler/Session 3 & 4
  • 64.
    Objectives BIT MANIPULATIONS Translations • Totranslate from one bit combination to another Format : TR S1(L),S2 or S1,S2 S1 : The field whose data is to be translated S2 : A 256-byte translation table Function : The value of the original byte is used as a displacement into the translation table. The byte found there replaces the original byte. e.g. TR WORK,XTABLE If the source byte is x’40’ (Space), then the displacement into the table is 64. The value in the table at displacement 64 will be replacing the source. Assembler/Session 3 & 4
  • 65.
    Objectives BIT MANIPULATIONS Assembler/Session 3& 4 Translations 1 byte - 256 possible combinations x’00’,x’01’, x’02’, x’03’,…………..x’0F’ x’10’,x’11’,x’12’,…………………..x’1F’ ………………………………………….. x’F1’,x’F2’,x’F3’,…………………x’FF’ The table should start with replacement byte for x’00’ and end with replacement for x’FF’
  • 66.
    Objectives BIT MANIPULATIONS (TRT) Assembler/Session3 & 4 Translations - TRT (Translate and test register) -Similar to TR but the source is not changed -Table is searched similar to TR taking the displacement into the table -Usually employed for editing purposes -The characters we need to search will have non zeros (x’00’) but other characters will be x’00’. -Source is searched one character at a time from left to right -The first nonzero match in the table halts the instruction -Condition code is set to 1 if match found before last byte, 2 if found at the last and 0 if not found -Loads address of source operand if found in last 24 bits of register 1, value from the table into last bit of register 2. No bits are changed in both the registers
  • 67.
    Objectives BIT MANIPULATIONS (TRTcontinued) Assembler/Session 3 & 4 Translations - TRT (Translate and test register) This example searches for a period X’4B’ The period 4B is decimal 75. So the X’4B’ is placed at the 76th position in the table. (Any non zero character may be placed in the table Table should be declared as follows: TABLE DC 75X’00’ DC X’4B’ DC 180X’00’
  • 68.
    Objectives Numeric ConversionsNumeric Conversions 1.Conversion to binary (CVB) Format: CVB operand1,operand2 operand1 : Register operand2 : a double word (containing valid packed decimal number) e.g. CVB 5,DOUBLE Use : Character data -(PACK)->Packed decimal-(CVB)-> binary Assembler/Session 3 & 4
  • 69.
    Objectives Numeric ConversionsNumeric Conversions 2.Conversion from binary (CVD) Format: CVD operand1,operand2 operand1 : Register operand2 : a double word e.g. CVD 5,DOUBLE Use : Binary-(CVD)->Packed decimal-(UNPK)-> Character data Assembler/Session 3 & 4
  • 70.
    Objectives Numeric ConversionsNumeric Conversions 3.Conversion from Zoned decimal to packed (PACK) (SS instruction) Format: PACK operand1,operand2 operand1 : Packed decimal operand2 : Zoned Decimal e.g. PACK PACKED(3),ZONED(5) Assembler/Session 3 & 4
  • 71.
    Objectives Numeric ConversionsNumeric Conversions 4Packed decimal to Zoned decimal (UNPACK) Format: UNPACK operand1,operand2 operand1 : Zoned decimal operand2 : Packed decimal e.g. UNPACK ZD(5),PACKED(2) Assembler/Session 3 & 4
  • 72.
    Objectives Relation between CVD,CVB,PACKand UNPACKRelation between CVD,CVB,PACK and UNPACK Assembler/Session 3 & 4 Binary inBinary in RegisterRegister PackedPacked DecimalDecimal ZonedZoned DecimalDecimal CVBCVB PACKPACK InputInput CVDCVD UNPKUNPK OutputOutput
  • 73.
    Objectives Example code forDifferent conversionsExample code for Different conversions Assembler/Session 3 & 4 PACK PNUM(8),START(3)PACK PNUM(8),START(3) CVB 7,PNUMCVB 7,PNUM A 7,=F’1’A 7,=F’1’ CVD 7,PNUMCVD 7,PNUM UNPK ANS(3),PNUM(8)UNPK ANS(3),PNUM(8) …… …… START DC C’125’START DC C’125’ ANS DS CL3ANS DS CL3 PNUM DS DPNUM DS D
  • 74.
    Objectives Packed decimal operationsPackeddecimal operations Assembler/Session 3 & 4 SS format - OPCODE D1(L1,B1),D2(L2,B2) AP - Add packed SP - Subtract packed ZAP - Zero and add packed MP - Multiply packed DP - Divide packed CP - Compare packed Note: All these operations ignore the decimal places. You have to track the decimal places and edit it with ED and EDMK instructions
  • 75.
    Objectives Packed decimal operationsPackeddecimal operations Assembler/Session 3 & 4 Advanced instructions: SRP - Shift and Round packed OPCODE D1(L,B1),D2(B2),I3 First operand - Memory location including length Second operand - Direction and number of places to shift Third operand - Whether to round or not ------------------------------------------------------------------------- Second operand, <= 32, left shift is done and 33 to 64 right shift is done. Number for right shift = ( 64 - number of digits to be shifted) (No rounding is involved in left shift
  • 76.
    Objectives Packed decimal operationsPackeddecimal operations Assembler/Session 3 & 4 Advanced instructions: (SRP continued) NUM is a 5 byte packed decimal number and contains 001234567C. What is the value in number after each of these instructions? 1. SRP NUM(5),2,0 2. SRP NUM(5),62,0 3. SRP NUM(5),62,5 4. SRP NUM(5),60,5
  • 77.
    Objectives Packed decimal operationsPackeddecimal operations Assembler/Session 3 & 4 Advanced instructions: MVZ - Move Zone (Moves the first half of each byte) MVN - Move numeric (Moves the second half of each byte) MVO - Move with offset EG: Multiply A by 100 where value of A is 123 MVC TEMP(3),A MVN TEMP+2(1),=X’00’ MVZ TEMP+3(1),=X’00’ MVN TEMP+3(1),A+2 A DC PL3’123’ TEMP DS PL4
  • 78.
    Objectives Editing the outputfor printingEditing the output for printing ED and EDMK instructions ( D1(L,B1), D2(B2)) (Pattern and PD number) Patterns: x’20’ - Digit selector x’21’ - Significance selector x’22’ - Field separator x’60’ - Sign indicator Pattern and the packed decimal number processed from left 1 byte at a time X 0 1 2 3 4 5 6 C (Instruction: ED P(12),X) Fill Character P 40 20 20 6B 20 21 20 4B 20 20 60 40 (Before execution) P 40 40 F1 6B F2 F3 F4 4B F5 F6 40 40 (After execution) 1 , 2 3 4 . 5 6 (Last 2 bytes spaces since number is positive) Assembler/Session 3 & 4 …… ……
  • 79.
    Objectives Editing the outputfor printingEditing the output for printing Assembler/Session 3 & 4 Values being examined Action taken Pattern byte PDdigit Newpattern New state of SI Digit selector 0 1-9 Fill character digit in EBCIDIC Off On Significanc e starter 0 1-9 Fill character digit in EBCIDIC On On Field seperator None Fill character Off When the significant indicator is off Anyother byte None Fill character Off Digit selector 0-9 digit in EBCIDIC On Significanc e starter 0-9 digit in EBCIDIC On Field seperator None Fill character Off When the significant indicator is on Anyother byte None Pattern byte notchanged On
  • 80.
    Objectives Editing the outputfor printingEditing the output for printing Assembler/Session 3 & 4 -ED and EDMK can detect the difference between significant and non signi ficant digits ie between leading and non leading zeros - Significance starter forces all subsequent digits to be considered significant -When significance indicator is off and detection of a significant digit turns it on, the address of that significant digit placed in 8-31 of register 1 by EDMK -EDMK allows a floating currency and/or algebraic sign but ED does not allow
  • 81.
    Objectives TABLE PROCESSINGTABLE PROCESSING Atable is a named storage structure consisting of subunits or entries e.g. RATE DS 6F L 4,RATE+8 Accessing table elements with indexed storage operands: e.g. LH 9,=F8’ L 5,RATE(9) (9 - index register) Assembler/Session 3 & 4
  • 82.
    Objectives Multi-purpose branching instructions Convenientwhen counted repetition structure (table processing) is needed • Branch on count (BCT and BCTR) Format: BCT op1,op2 (R-X) Function: First the op1 value is decremented by 1. Second the branch is taken to the address specified in op2 only if the value in op1 is not 0. e.g. LH 9,=H’12’ REPEAT EQU * .. BCT 9,REPEAT Assembler/Session 3 & 4
  • 83.
    Objectives • Branch onindex high and branch on index low or equal (BXH and BXLE) Format: BXLE op1,op2,op3 BXH op1 : A register known as the index register op2 : A even-odd pair of registers Even register - increment register Odd register - Limit register op3 : A storage operand. This is the branch address. Assembler/Session 3 & 4
  • 84.
    Objectives Function : First,the value in the increment register is added to the indexed register. Second, the branch is taken only when the value in the index register is ‘lower than or equal to’ / ‘higher than’ the value in the limit register Useful when the same register is to be used as the count and index register Assembler/Session 3 & 4
  • 85.
    Objectives BXLE - ‘DOUNTIL’ repetitions BXH- ‘DO WHILE’ repetitions e.g... LH 7,=H’0’ index LH 2,=H’2’ increment amount LH 3,=H’18 the limit --- REPEAT ... LH 6,TABLE(7) ... BXLE 7,2,REPEAT Assembler/Session 3 & 4
  • 86.
    ObjectivesLoad instructions withadditional features • Load and Test (LTR) e.g... LTR 15,15 BNZ ERROR • Load Address (LA) LA R1,D2(X2,B2) Assembler/Session 3 & 4
  • 87.
    Objectives USING EQUATESUSING EQUATES •To associate a fixed value with a symbol • Useful for length and relative address calculation e.g. TABLE DS 0H DC C’01 DC C’02’ ... TBLEND EQU * TBLSIZE EQU TBLEND-TABLE Assembler/Session 3 & 4
  • 88.
    Objectives USING EQUATESUSING EQUATES Canbe used for the following purposes: 1. To assign single absolute values to symbols. 2. To assign the values of previously defined symbols or expressions to new symbols, thus allowing you to use different mnemonics for different purposes. 3. To compute expressions whose values are unknown at coding time or difficult to calculate. The value of the expressions is then assigned to a symbol. Assembler/Session 3 & 4
  • 89.
    Assembler LanguageAssembler Language SESSION5 Program Sectioning Assembler/Session 5
  • 90.
    Objectives Beginning and Endof Source ModulesBeginning and End of Source Modules •Code a CSECT segment before any statement that affects the location counter •END statement is required as the last statement in the assembly Assembler/Session 5
  • 91.
    Objectives CONTROL SECTIONSCONTROL SECTIONS •Asource module can be divided into one or more control sections •A control section is the smallest subdivision of a program that can be relocated as a unit Assembler/Session 5
  • 92.
    • At codingtime, establish the addressability of each control section within the source module, and provide any symbolic linkages between control sections that lie in different source modules. • Initiated by using the START or CSECT instruction CONTROL SECTIONSCONTROL SECTIONS
  • 93.
    Objectives CONTROL SECTIONSCONTROL SECTIONS •Anyinstruction that affects the location counter, or uses its current value, establishes the beginning of the first control section. Assembler/Session 5
  • 94.
    Format of CSECT: NameOperation Operand Any symbol CSECT Not required or blank Note: The end of a control section or portion of a control section is marked by (a) any instruction that defines a new or continued control section, or (b) the END instruction. CONTROL SECTIONSCONTROL SECTIONS
  • 95.
    Objectives DUMMY SECTIONSDUMMY SECTIONS •Adummy control section is a reference control section that allows you to describe the layout of data in a storage area without actually reserving any virtual storage. Assembler/Session 5
  • 96.
    • Use theDSECT instruction to initiate a dummy control section or to indicate its continuation. Format of DSECT: Name Operation Operand Any symbol DSECT Not required or blank DUMMY SECTIONSDUMMY SECTIONS
  • 97.
    Objectives DUMMY SECTIONSDUMMY SECTIONS Touse a dummy section : • Reserve a storage area for the unformatted data • Ensure that this data is loaded into the area at execution time Analogy: Cobol copybook Assembler/Session 5
  • 98.
    • Ensure thatthe locations of the symbols in the dummy section actually correspond to the locations of the data being described • Establish the addressability of the dummy section in combination with the storage area You can then refer to the unformatted data symbolically by using the symbols defined in the dummy section. DUMMY SECTIONSDUMMY SECTIONS
  • 99.
    Objectives ASMBLY2 CSECT BEGIN BALR2,0 USING *,2 ... Reg 3 points to data area LA 3,INPUT USING INAREA,3 CLI INCODE,C'A' BE ATYPE ... ATYPE MVC WORKA,INPUTA MVC WORKB,INPUTB . . Assembler/Session 5
  • 100.
    WORKA DS CL20 WORKBDS CL18 INPUT DS CL39 ... INAREA DSECT INCODE DS CL1 INPUTA DS CL20 INPUTB DS CL18 ...
  • 101.
    Objectives Assembler DirectivesAssembler Directives TITLE: To provide headings for each page of the assembly listing of the source modules. EJECT : To stop the printing of the assembler listing on the current page, and continue the printing on the next page. ORG : To reset the location counter Assembler/Session 5
  • 102.
    LTORG : Aliteral pool is created immediately after a LTORG instruction or, if no LTORG instruction is specified, at the end of the first control section. PRINT : To control the amount of detail to be printed in the listing of programs. PRINT NOGEN / GEN Assembler DirectivesAssembler Directives
  • 103.
    Assembler LanguageAssembler Language SESSION6 Writing a complete program Assembler/Session 6
  • 104.
    Objectives Program Entry andExit LogicProgram Entry and Exit Logic Program entry - Preserve register contents Program Exit - Restore register contents Register save area Always calling program provides a save area of 18 Full words long used for storage of registers Save area address passed through register 13 by IBM convention Assembler/Session 6
  • 105.
    Objectives A register savearea (18 consecutive full words) Word Address Contents 1 SAV 2 SAV+4 Address of calling program’s save area 3 SAV+8 Address of called program’s save area 4 SAV+12 Contents of Register 14 5 SAV+16 Contents of Register 15 6 SAV+20 Contents of Register 0 ... 18 SAV+68 Contents of Register 12 Assembler/Session 6
  • 106.
    Objectives Responsibilities of calledprogram Program entry conventions 1.Save contents of registers 0-12,14 & 15 in calling program’s save area 2.Establish base register 3.Store calling program’s save area in the 2nd word of its own save area Assembler/Session 6
  • 107.
    Objectives Program entry conventions(contd..) 4. Store the address of its register save area in the third word of the calling program’s register save area (The addresses in the 3d word of save area establish a chain of register save areas. This will be useful in reading the dump when program crashes). Assembler/Session 6
  • 108.
    Objectives Responsibilities of calledprogram (contd..) Program Entry STM R14,R12,12(R13) BALR R12,0 USING *,R12 ST R13,SAVOWN+4 store calling programs save area LR R14,R13 LA R13,SAVOWN Reg 13 contains current prog’s SA ... ST R13,8(R14) Assembler/Session 6
  • 109.
    Objectives Responsibilities of calledprogram (contd..) Program Exit conventions 1. Restore registers 0-12 and 14 2. Place the address of the save area provided by the calling program in Reg 13 3. Place a return code in the low order byte of register 15 if one is required. Otherwise restore register 15. Assembler/Session 6
  • 110.
    Objectives Responsibilities of calledprogram (contd..) Program Exit L R13,4(R13) LM R14,R12,12(R13) BR R14 Assembler/Session 6
  • 111.
    Objectives Responsibilities of callingprogram 1. Register 13 must contain the address of a register save area. 2. Register 15 should be set to the beginning address of the subroutine L R15,=V(SUBENTRY) where SUBENTRY is the entry address (usually the CSECT name) of the subroutine Assembler/Session 6
  • 112.
    Objectives Responsibilities of callingprogram (contd...) 3. Register 14 should have the return address 4. Register 1 should have the address of the parameter list A BALR instruction stores the address of the next instruction in the calling program into register 14 and transfers control to the called subroutine BALR R14,R15 Assembler/Session 6
  • 113.
    Objectives Passing parameters toa subroutine • The standard interface requires that addresses of parameters be placed in a block of storage, and the address of the block be loaded into register 1 as the subroutine is called • Both input and output parameters are treated the same way e.g... ADDS DC A(T) DC A(U) DC A(V) LA R1,ADDS Assembler/Session 6
  • 114.
    Objectives R1 Main storage Addrof parmlist Parmlist parm3 Addr of parm1 Addr of parm2 parm1 Addr of parm3 parm2 Assembler/Session 6
  • 115.
    Objectives Called subroutine Bmay get the second parameter by L R3,4(,R1) L R8,0(,R3) Assembler/Session 6
  • 116.
    Objectives Registers with specialuse R0 : Contains single word output of a subroutine R1 : contains the address of an area of main storage that contains addresses of parameters Assembler/Session 6
  • 117.
    Objectives Registers with specialuse (contd...) R14 : Contains the return address, the address in the calling routine to which a subroutine should return control when finished R15 : contains the address of the entry point in the subroutine R13 : contains the address of an area in which register contents can be stored by a subroutine Assembler/Session 6
  • 118.
    Objectives The subroutine RANDOM RANDOMSTM R14,R12,12(R13) BALR R12,0 USING *,R12 L R7,RN M R6,=F’65541’ ST R7,RN LR R0,R7 LM R1,R12,24(R13) BR R14 RN DC F’8193’ Assembler/Session 6
  • 119.
    Objectives Subroutine RDIGIT RDIGIT STMR14,R12,12(R13) BALR R12,0 USING *,R12 ST R13,SAV+4 LA R13,SAV ... L R15,RANDAD BALR R14,R15 ... L R13,SAV+4 LM R14,R15,12(R13) LM R1,R12,24(R13) BR R14 SAV DS 18F RANDAD DC A(RANDOM) Assembler/Session 6
  • 120.
    Objectives Linkage ConventionsLinkage Conventions •Programdivided into 2 or more source modules •Source module divided into 2 or more control sections •For link-editing, a complete object module or any individual control section of the object module can be specified Assembler/Session 6
  • 121.
    Objectives Communicating between programparts • To communicate between 2 or more source modules, symbolically link them together • To communicate between 2 or more control sections within a source module, establish proper addressability Assembler/Session 6
  • 122.
    Objectives Establishing symbolic linkage •Identify external symbols in the EXTRN or WXTRN instruction or the V-type address constant • provide A-type or V-type address constants to reserve storage for addresses represented by external symbols • In the external source modules, identify these symbols with the ENTRY instruction (name entry of a START or CSECT instruction is automatically identified as an entry symbol) External symbol dictionary Assembler/Session 6
  • 123.
    Objectives Establishing symbolic linkage(contd...) e.g. program A EXTRN TABLEB WXTRN TABLEB TABADR DS V(TABLEB) program B ENTRY TABLEB TABLEB DS ... Assembler/Session 6
  • 124.
    Objectives Address Constants (Aand V) • An address constant is a main storage address contained in a constant • A V-type constant is the value of an external symbol - a relocatable symbol that is external to the current control section. Used for branching to locations in other control sections e.g L 5,ADCON ADCON DC A(SOMWHERE) GSUBAD DC V(READATA) Assembler/Session 6
  • 125.
    Assembler LanguageAssembler Language SESSION7 Assemble and Link Program Assembler/Session 7
  • 126.
    Objectives Processing of Instructions Time/M/C Assembler ENTRY Macro Activity instructions. EXTRN Instr. Code source m/c DC,DS instruc. Preassembly Refer to macro instruc. Assembly object code LKED Prog fetch Execution data area form data area in load mod Processing of Instructions Time/ M/C Assembler ENTRY Macro Activity instructions. EXTRN Instr. Code source m/c DC,DS instruc. Preassembly Refer to macro instruc. Assembly object code LKED Prog fetch Execution data area form data area in load mod Assembler/Session 7
  • 127.
    Objectives JCL ‘ parm’processing EXEC PGM=pgmname,PARM= When program gets control : •Register 1 contains the address of a full word on a full word boundary in program’s address space •the high order bit of this full word is set to 1 (this convention is to indicate the last word in a variable length parameter list) Assembler/Session 7
  • 128.
    JCL ‘ parm’processing ... • Bits 1-31 of the full word contain the address of a 2-byte length field on a half word boundary • The length field contains a binary count of the no. of bytes in the PARM field which immediately follows the length field
  • 129.
    Objectives COBOL to Assembler CALLasmpgm USING COMM-AREA PL/I to Assembler DCL ASMSUB ENTRY OPTIONS(ASSEMBLER) CHARSTRING CHAR(25); CALL ASMSUB(CHARSTRING); Ref : PL/I Programming Guide, COBOL programming Guide Assembler/Session 7
  • 130.
    Assembler LanguageAssembler Language SESSION8 Macro Language Assembler/Session 8
  • 131.
    ObjectivesMacros • Short sourceroutines written and stored in libraries •Assembler inserts the source statements in the program where the macro appears Assembler/Session 8
  • 132.
    Macro Definition Format : •Aheader statement •A prototype •Model statements •A trailer statement
  • 133.
    Objectives Header statement: MACRO Prototype: &name MOVE&TO,&FROM,&LENGTH Model statements: A set of machine and assembler instructions Trailer statement: &name MEND Assembler/Session 8
  • 134.
    Objectives Macro Instruction: • Astatement containing the name of a macro • when expanded, the symbolic parameters in the model statements are replaced by corresponding parameters from the macro instructions • symbolic parameters may be positional or keyword Assembler/Session 8
  • 135.
    Macro Instruction ... MACRO &LABELHALFSWAP &REG,&SV &LABEL ST &REG,&SV SLL &REG,8 IC &REG,&SV SLL &REG,8 IC &REG,&SV+1 MEND
  • 136.
    Objectives SET Symbols (globalor local) 3 types : • arithmetic (SETA) • binary (SETB) • character (SETC) • SET symbols are declared using, LCLA LCLB LCLC GCLA GCLB GCLC Assembler/Session 8
  • 137.
    Objectives Format: Label operation operands symbol-nameSETA An expression SETB SETC e.g. LCLA &A1 GCLA &A2 &A1 SETA 1 &A2 SETA &A1+3 Assembler/Session 8
  • 138.
    Objectives Attributes There are 6attributes of a symbol or symbolic parameter : type, length, scaling, integer, count and number System variable symbols &SYSINDX, &SYSDATE, &SYSTIME, &SYSECT, &SYSPARM, &SYSLOC Assembler/Session 8
  • 139.
    Objectives Conditional Assembly The assemblercan be made to branch and loop among assembler language statements using sequence symbols and the assembler instructions AIF and AGO Sequence symbol : Period followed by 1 to 7 alphabets or digits of which the first is a letter e.g. .Z23Ab Assembler/Session 8
  • 140.
    Objectives Format: Label Operation Operand seqsymbol AGO seq. symbol or blank -do- AIF A logical expression enclosed in parenthesis, followed by seq symbol Assembler/Session 8
  • 141.
    A logical expressionis composed of one or more relations or values of SETB symbols connected by logical connects AND, OR, AND NOT, OR NOT A relation consists of 2 arithmetic expressions or 2 character expressions connected by a relational operator EQ, NE, LT, LE, GT, GE
  • 142.
    Objectives e.g. MACRO PSRCH &PARAMS,&STRING GBLB &FOUND LCLA&I &FOUND SETB 0 .LP AIF ((&I GE N’&PARAMS) OR &FOUND) .E &I SETA &I+1 &FOUND SETB (‘&PARAMS(&I)’ EQ ‘&STRING’) AGO .LP .E MEND Assembler/Session 8
  • 143.
    Objectives Accessing QSAM files: Keywordsin DCB parameter: DSORG PS Physical sequential RECFM F,FA,FB,FBA,V,VBA BLKSIZE Block length LRECL Record Length DDNAME Dataset name in JCL MACRF Macro GM - Get Move GL - Get Locate PM - Put Move PL - Put locate Move parameter directly puts the record in the storage area specified while Locate mode Loads the address of the record in Register 1 Assembler/Session 8
  • 144.
    Objectives Accessing VSAM files:ACB macro AM - VSAM (For documentation) BUFND - No. of I/O buffers for data control intervals BUFNI - No. of I/O buffers for index control intervals BUFSP - Size of an area for data and Index I/O buffers DDNAME - Filename used in the DD statement. If omitted refers to the ACB macro name EXLST - Address to the EXLST macro. Generates a list of addresses for user routines MACRF - Types of processing the file will do Assembler/Session 8
  • 145.
    Objectives Accessing VSAM files:ACB macro (Continued) EXLST options: AM - VSAM EODAD = (Address, A/N, L) (Load module) EXCPAD = (Address, A/N, L) (Load module) JRNAD = (Address, A/N, L) (Load module) LERAD = (Address, A/N, L) (Load module) SYNAD = (Address, A/N, L) (Load module) Active/No, Stored in load module Assembler/Session 8
  • 146.
    Objectives Accessing VSAM files:RPL macro (Request parameter list) ACB - Address of the ACB macro AREA - Address of the work area to be used AREALEN - Length of the work area (Should be large enough to hold largest record in Move mode and at least 4 bytes in the Locate mode) RECLEN -Length of the records in the file (For VB you have to put the length before writing using MODCB) ARG - Label containing the key for the search (Key for KSDS, RRN for RRDS and RBA for ESDS) OPTCD - 5 sets of groups of parameters Assembler/Session 8
  • 147.
    Objectives Accessing VSAM files:RPL macro (Continued) Options for OPTCD: KEY/CNV/ADR - Access by key,Control interval or Relative byte address SEQ/DIR/SKP - Sequential processing,Direct, Skip sequential FWD/BWD - Forward sequential processing,Backward ARD/LRD -Start seq.processing with ARG specified/ Backward processing from the last record NUP/NSP/UPD - No updating(Next rec not ready),No updating Next rec ready(DA only), Record updating) MVE/LOC - Move mode/ Locate mode Assembler/Session 8
  • 148.
    Objectives Accessing VSAM files: OPEN- Open the file CLOSE - Close the file GET - Read a record PUT - Store a record ERASE - Delete a record POINT - Position for access Advanced macros: SHOWCB, TESTCB, MODCB Assembler/Session 8
  • 149.
    Assembler LanguageAssembler Language SESSION9 Other Topics Assembler/Session 9
  • 150.
    ObjectivesCharacteristics of goodassembler program • has simple, easy to understand logic • uses mostly simple instructions • has no relative addressing • uses subroutines Assembler/Session 8
  • 151.
    Characteristics of goodassembler program ... • uses DSECTs • has efficient code (LA R10, 4(0,R10 - A R10,=F’4) • does not abnormally terminate due to user error • requests and check feedback from macro instructions • provides meaningful error messages
  • 152.
    Objectives Characteristics of goodassembler program (contd..) • lets the assembler determine lengths • has opcodes, operand and comments aligned • contains meaningful comments • uses meaningful labels Assembler/Session 8
  • 153.
    Objectives Structured Programming • Toimprove design and understandability of a program • made up of building blocks of subroutines Conventions for general purpose registers • Base registers • Link registers Assembler/Session 8
  • 154.
    Objectives The EXecute Instruction •the EX instruction is a R-X type instruction that directs the execution of an instruction called the subject instruction, which is addressed by the second operand • the subject instruction is in effect a one-instruction subroutine Assembler/Session 9
  • 155.
    •The subject instructionis modified before execution (though not altered at its main storage location) : bits 8-15 of the instruction ORed with bits 24-31 of register R1 to form the second byte of the instruction actually executed e.g. Let reg 9 have the length of string to be moved EX R9,VARMVC VARMVC MVC A(0),B The EXecute Instruction (contd...)
  • 156.
    Objectives DEBUGGINGDEBUGGING Exceptions and Interrupts Interruptsthat result directly from attempts at invalid program execution are called program-check interrupts; identified by a code Interruption code 1 : Operation Interruption code 2 : Privileged operation Interruption code 4 : Protection Interruption code 5 :Addressing Interruption code 6 :Specification Assembler/Session 9
  • 157.
    Objectives DEBUGGING Exceptions and Interrupts(contd..) Interruption code 7 : Data Interruption code 8 : Fixed-Point Overflow Interruption code 9 : Fixed-Point Divide Other Interruption codes ( 3, 10, 11, 12, 13, 14, 15) Assembler/Session 9
  • 158.
    Objectives DEBUGGINGDEBUGGING Reading dumps • whenevera program abends an indicative dump is generated • The completion code is a code furnished by the O/S to designate the reason for the termination of the job step • In case of program check interruption, the first 2 digits of the completion code is 0C Assembler/Session 9
  • 159.
    • Locate theentry point of your program Reading dumps ... DEBUGGINGDEBUGGING
  • 160.
    Objectives DEBUGGINGDEBUGGING Reading dumps (contd...) •The register contents are the contents at the point of interruption (the instruction that caused the interrupt is usually the one just before the interrupt address given) • use address at interrupt and entry address to locate the instruction that caused the program- check interruption Assembler/Session 9
  • 161.
    Objectives DEBUGGINGDEBUGGING Full and Partialdumps • //SYSUDUMP DD SYSOUT=A • SNAP macro Assembler/Session 9
  • 162.
    Reading the dump •SAVE AREA trace • P/P Storage • Examine register contents, PSW and listed entry point to find the portion of program being executed • Look at main storage dump to determine the data being used DEBUGGINGDEBUGGING
  • 163.
    Objectives SYSTEM MACROSSYSTEM MACROS DataManagement Macros DCB - Construct a data control block OPEN - Logically connect a dataset CLOSE - Logically disconnect a dataset GET - Obtain next logical record (queued access) PUT - Write next logical record (queued access) READ - Read a block (basic access) WRITE - Write a block (basic access) Assembler/Session 9
  • 164.
    Objectives SYSTEM MACROSSYSTEM MACROS SupervisorServices Macros ABEND - Abnormally terminate a task CALL - Pass control to a control section GETMAIN - Allocate virtual storage FREEMAIN - Free virtual storage LOAD - Bring a load module into virtual storage RETURN - return control to the calling program SAVE - Save register contents Assembler/Session 9
  • 165.
    Objectives SYSTEM MACROSSYSTEM MACROS SupervisorServices Macros (contd) SNAP - Dump virtual storage and continue LINK - Pass control to a Program in Another load module WTO - Write to operator Assembler/Session 9
  • 166.
    Objectives SYSTEM MACROSSYSTEM MACROS e.g.File I/O OPEN (INFILE,INPUT) GET INFILE,RECAREA PUT OUTFILE,RECAREA CLOSE (INFILE) INFILE DCB DSORG=PS,MACRF=GM,DDNAME=IFILE OUTFILE DCB DSORG=PS,MACRF=PM,DDNAME=OFILE (RECFM=,LRECL=,BLKSIZE=,) Assembler/Session 9
  • 167.
    Objectives SYSTEM MACROSSYSTEM MACROS Threeforms : Standard form : Results in instructions that store into an inline parameter list and pass control to the required program List form : Provides as out-of-line parameter list Execute form : Provides the executable instructions required to modify the out-of-line parameter list and pass control to the required program Assembler/Session 9
  • 168.

Editor's Notes

  • #8 The unit of control in a computer is the instruction; a program is a set of instructions. Each instruction contains an operation code, which designates the operation to be performed by the computer. Instructions also contain operand addresses, to instruct the computer which storage locations or registers to use in the operation A computer has an instruction address register, which always holds in main storage the address of the next instruction to be executed. Execution of an instruction can be divided into two parts, an instruction cycle and an execution cycle. During the instruction cycle, the control subsystem retrieves the instruction from the location addressed by the instruction address register, and decodes the instruction preparatory to executing it. During the decoding process, the control subsystem identifies from the operation code in the instruction the typw of operation to be performed. It decodes tithe rest of the instruction accordingly and sets up data paths for the execution of the instruction. During the execution cycle, the operation, such as arithmetic, specified by the instruction is actually performed. The instruction address register is also updated during the execution cycle. Usually it is changed to refer to the instruction immediately following (in main storage) the instruction being executed; some instructions are branch instructions in which part of the execution of the instruction itself is to replace the contents of the instruction address register by one of the operands of the instruction. . While machine language is numeric, assembler language allows alphabetic names for operation codes and storage locations. Until early 1950s al programming was done directly in machine language. The main storage of the IBM system/370 is organized into bytes, each of which consists of eight bits. The bytes in turn are grouped into words of 4 bytes each, half words of 2 bytes each and double words of eight bytes each.
  • #10 The unit of control in a computer is the instruction; a program is a set of instructions. Each instruction contains an operation code, which designates the operation to be performed by the computer. Instructions also contain operand addresses, to instruct the computer which storage locations or registers to use in the operation A computer has an instruction address register, which always holds in main storage the address of the next instruction to be executed. Execution of an instruction can be divided into two parts, an instruction cycle and an execution cycle. During the instruction cycle, the control subsystem retrieves the instruction from the location addressed by the instruction address register, and decodes the instruction preparatory to executing it. During the decoding process, the control subsystem identifies from the operation code in the instruction the type of operation to be performed. It decodes tithe rest of the instruction accordingly and sets up data paths for the execution of the instruction. During the execution cycle, the operation, such as arithmetic, specified by the instruction is actually performed. The instruction address register is also updated during the execution cycle. Usually it is changed to refer to the instruction immediately following (in main storage) the instruction being executed; some instructions are branch instructions in which part of the execution of the instruction itself is to replace the contents of the instruction address register by one of the operands of the instruction. . While machine language is numeric, assembler language allows alphabetic names for operation codes and storage locations. Until early 1950s al programming was done directly in machine language. The main storage of the IBM system/370 is organized into bytes, each of which consists of eight bits. The bytes in turn are grouped into words of 4 bytes each, half words of 2 bytes each and double words of eight bytes each.