1.68k likes | 1.99k Views
Assembler/Session 1 . Course Title : ASSEMBLER LANGUAGE Duration : 5 Half - DAYS. Assembler/Session 1 . Objectives. Objectives. Familiarize with IBM 370 Assembly Language . Assembler/Session 1 .
E N D
Assembler/Session 1 Course Title : ASSEMBLER LANGUAGE Duration : 5 Half - DAYS
Assembler/Session 1 Objectives Objectives • Familiarize with IBM 370 Assembly Language
Assembler/Session 1 COURSE SCHEDULE SESSION 1 Day 1 Introduction SESSION 2 Day 1 Addressing SESSION 3 Day 2 Machine Instructions
Assembler/Session 1 COURSE SCHEDULE SESSION 4 Day 3 ProgramSectioning AssemblerDirectives SESSION 5 Day 3 Writing a complete program SESSION 6 Day 3 SESSION 7 Day 4 Assemble and link program
Assembler/Session 1 COURSE SCHEDULE SESSION 8 Day 4 Macro Language SESSION 9 Day 5 Other Topics
Assembler/Session 1 Assembler Language SESSION 1
Assembler/Session 1 Objectives INTRODUCTION • 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
Assembler/Session 1 STATEMENT FORMAT Objectives • 1 10 16 30 • label operation operands comments • e.g.. • INIT1 LA R5,4 ;INITIALISE REGISTER 5 • 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 Sample program Col1 Col10 Col.16 L 2,A A 2,B ST 2,ANS ….. ….. A DC F’15’ B DC F’20’ ANS DS F
Assembler/Session 1 STATEMENT FORMAT Objectives • 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 STATEMENT FORMAT Objectives • Comment Statement • * in column 1 • Any text in columns 2 - 71 • Note : Fields separated by one or more blanks
Assembler/Session 1 TYPES OF INSTRUCTIONS Objectives 1. Machine Instructions 2. Assembler Instructions (Directives) 3. Macro Instructions
Assembler/Session 1 REGISTERS Objectives 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 REGISTERS Objectives • 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 DATA REPRESENTATION Objectives 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 2’s complement form Objectives • How to identify a negative number? • - Leading bit contains a 1 (In Hex 8 to F) • How to convert to a negative number? • First switch the bits (1 to 0 , 0 to 1) • Finally add 1
Assembler/Session 1 Boundary requirements Objectives 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
Assembler/Session 1 DATA REPRESENTATION Objectives 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 DATA REPRESENTATION Objectives 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 DATA REPRESENTATION Objectives 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 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 Objectives
Assembler/Session 1 Addressing RX Operands: Implicit format: L 3,VAR Explicit format: L 3,100(0,12) Register Displacement Index reg Base reg Objectives
Assembler/Session 2 Assembler Language SESSION 2 Addressing
Assembler/Session 2 Objectives STORAGE 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 STORAGE DEFINITIONS Objectives 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 STORAGE DEFINITIONS Objectives 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 STORAGE DEFINITIONS Objectives 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 STORAGE DEFINITIONS Objectives 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 STORAGE DEFINITIONS Objectives • 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 ESTABLISHING ADDRESSABILITY Objectives • 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 ESTABLISHING ADDRESSABILITY Objectives • 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 ESTABLISHING ADDRESSABILITY Objectives 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 ESTABLISHING ADDRESSABILITY Objectives • 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 ESTABLISHING ADDRESSABILITY Objectives • 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 ESTABLISHING ADDRESSABILITY Objectives • 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 RELATIVE ADDRESSING Objectives • 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 3 & 4 Assembler Language SESSION 3 & 4 Machine Instructions
Assembler/Session 3 & 4 HANDLING CHARACTER DATA Objectives • 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 HANDLING CHARACTER DATA Objectives • 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 HANDLING CHARACTER DATA Objectives 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 HANDLING CHARACTER DATA Objectives 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 HANDLING CHARACTER DATA Objectives • 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 BINARY INSTRUCTIONS Objectives • 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 BINARY INSTRUCTIONS Objectives 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 BINARY INSTRUCTIONS Objectives • 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 BINARY INSTRUCTIONS Objectives • Binary Subtraction (S, SH and SR) • Type R-X • e.g. • S 5,FULL • SH 6,HALF • SR 7,3