SP UNIT I-Module II
SP UNIT I-Module II
Module I
Background: Machine Structure, Evolution of the
Components of a Programming System, Assembler,
Loaders, Macros, Compliers, Formal Systems.
Module II
Machine Structure, Machine Language and assembly
language: General Machine Structure,Machine
Language, Assembly Language
Module 2
An instruction interpreter
A location counter
An instruction register
With a neat diagram describe the General Machine Structure for IBM
360/370.
Instruction Format
The basic instruction format (of small computer SC-6521)is
If base register is not used 40 bits is required for each instruction which leads to an addition of bits and thus wastage
of memory.
Advantage of base register
It helps in the process of relocation of a program. i.e., an entire program may be moved from one series of locations to another
by changing the contents of the base register.
Efficient addressing of core.
Saves 8 bits per address reference.
Disadvantages of base register
Overhead associated with the formation of the address during execution.
Difficult to reach the data.
III. DATA
The different types of data formats present in IBM system 360 are:
1. Short form fixed point numbers
2. Long form fixed point numbers
3. Packed decimal numbers
4. Unpacked decimal numbers.
5. Short form floating point number
6. Long form floating point numbers
7. Logical or character data
Short form fixed point numbers & Long form fixed point numbers
Fixed point numbers may be stored in either a half word or a full word.
Used to represent integer numbers.
First bit for sign and remaining bytes to represent actual number in binary form.
Decimal formats ae useful fin data processing
Example:-021 is represented as
2bytes
The last 1byte (4+4 bits) is reserved for sign and data.
In between the BCD of each numbers a 4 bit zone code/padding bit/inter
nibble bit is introduced which contains 0/1.
The hex digits C,A,F,E indicates a +ve numbers ,while D & B indicates a –ve
numbers.
Example
How +21544 is stored
Short form floating point number
& Long form floating point numbers
In character data each character code is stored in 8 bits (1byte) and its length
varies from 1 to 256 bytes.
0100 0001
1byte
DATA FORMATS OF IBM 360
IV Instructions
An instruction includes an opcode, specifying the operation to be performed, such as
“add contents of memory to register” and zero or more operands, which may specify registers,
memory locations or literal data.
The operand may have addressing modes determining their meaning or may be in fixed fields.
The size or length of an instruction varies from 2 bytes to 6 bytes depending on the instruction
formats
Instructions are of different types, they are
Arithmetic instructions
Control or transfer instructions
Special interrupt instruction
The different types of operands
Register operands
Storage operands
Immediate operands
Operands
Register operands
Register operands refer to data stored in one of the 16 general purpose registers, which
are addressed by 4 bit field in the instruction.
Storage operands
Storage operand refers to data stored in core memory. The length of the operand depends
upon the specific data type.
Immediate operand
Immediate operands are single byte of data and are stored as part of the instruction.
Instruction Formats
RR format
RX format
RS format
SI format
SS format
RR instruction
RR instruction denotes register to register operation. i.e, both the operands are register.
The length of RR instruction is 2 bytes (16 bits)
The general format of RR
In SS format, the length is always on less than the data moved.i.e. If L=0 move 1 byte.
Here L=79, therefore move 80 bytes from location 1032[till 1111(1032+79)] to 1300[till 1379(1300 + 79)]
Instruction set
The various categories of instructions are
1. load-store registers instructions
2. Fixed point arithmetic
3. Logical instructions
4. Transfer instructions
5. Miscellaneous instructions
1.load-store registers instructions
2. Fixed point arithmetic
3. Logical instructions
4. Transfer instructions
5. Miscellaneous instructions
Machine level language
Machine language is the basic language of the computer, representing data as
1’s and 0’s.
Example1: L 2, 924(0, 1)
OP R1, D2(X2, B2)
Advantages & Disadvantages of machine language
Advantages
Instructions of a machine language program are immediately executed, they
require no compilation or translation.
Machine language make efficient use of storage
Disadvantages
Machine languages are machine dependent
Machine language is difficult to program, since the programmers has to know the
architecture of the system.
Writing, reading, correcting or modifying a machine language program is difficult.
Example program
Write a program that will add the number 49 to the contents of 10 adjacent full words (32bits or 4
bytes) in memory with the following assumptions:
The 10 numbers are contiguous full words beginning at absolute location 952.
The program is in core memory starting at absolute location 48.
The number 49 is a full word at absolute location 948. Figure shows the core memory
structure
Register 1 contains a 48.
Advantages
Implementation is easy.
Disadvantages
Instructions are repeated for all the data items.
It is impossible to access both the first data item and the last data item using
register 1 as the base.
Wastage of memory.
Need of relocation.
Instruction would overlap data in the core.(offset limitation)
Address modification using instructions as data
In this approach the problem consisting only of those 3 instructions followed by a the sequence of
commands that would change offset by adding 4 to them.
In addition to the 4 assumptions given in the problem statement, we are going to make one more
assumptions.
Assumption 5: relative location 896 contains a 4.
Here instruction is treated as data. Therefore adding 4 to an instruction will update its offset.
For example, if location 48 contains the instruction L 2,904(0, 1)
The instruction is stored as follows from byte number 48
Now when we add 4 to this instruction, the offset present in the 4th byte is treated as data
and is incremented by 4.
L+4=904+4=908
Address modification using instructions as data
Program is as follows:
Address modification using instructions as data
Advantages
Saves memory
Address is modified easily using the instruction.
Disadvantages
Treating instructions as data is not a good programming practice
Separate instructions are used for increasing the displacement(offset) of load and
store(12 bit of offset can support displacement upto 4095)
3.Address modification using index registers
In this approach, we use the same 3 instructions i.e. load, add and store.
We simply loop through these 3 instructions, updating the storage operands of load and store instructions, by
adding 4 to the contents of the index register during each pass.
Register 4 is used as an index register.
SR 4,4
Clear register 4 by subtracting the contents of register 4 from register 4.
The contents of register 4=0
L2,904(4,1)
Load data element of array
Address of the storage operand=904+contents of index register 4+contents of base register 1
=904+0+48=952
Content of register 2 =contents of memory location 952 =data1.
ST 2,904(4, 1)
Replace data element
Address of the storage operand register1 =904+contents of index register 4+contents of base
=904+0+48= 952
Contents of memory location 952= =contents of register2= Data1+49
Address modification using index registers
A 4,896(0,1)
Add 4 to index register
Address of the storage operand=896+contents of base register1= 896+48= 944
Contents of index register 4 = Contents of index register 4+contents of memory location 944
=0+4=4
Note
SR is RR type instruction, whose length is 2 bytes
L is RX type instruction, whose length is 4 bytes
A is RX type instruction, whose length is 4 bytes
ST is RX type instruction, whose length is 4 bytes
Contents of index register 4 will be 4,8,12 etc during the subsequent passes
Advantages
Easy to understand
Saves memory
Address modification using index registers
4.Looping
Assumption 6: relative location 892 contains a 10
Assumption 7: relative location 888 contains a 1.
L 3,892(0, 1)
Load data into register 3
Address of the storage operand=892+C(B1)=892+48=940.
Content of register 3 =contents of memory location 940 =10
S 3,888(0, 1)
Subtract 1
Address of the storage operand=888+contents of register 1
=888+48=936
C(R3)=C(R3)-contents of memory location936=10-1=9
ST 3,892(0, 1)
Store temp
Address of the storage operand=892+C(R1) =892+48 =940
Content of memory location 940=contents of register 3=9
BC 2, 2(0,1)
Branch if result is positive.
2 denotes a condition code
Looping
Assembly language
Definition
Assembly language is a low level programming language that allows and uses to write
programs using mnemonics (symbols) .
Advantages
It is mnemonic.
Reading is easier.
Addresses are symbolic.
Introduction of data to program is easier.
It can be easily modified into machine language programs.
Disadvantages
An assembly language program(source program) is required to translate into object
program.
It is machine dependent.
Lack of portability of programs between computers of different makes.
Pseudo opcodes
Pseudo opcode is an assembly language instruction that specifies an operation of the assembler.
USING
Using is a pseudo opcode that indicates to the assembler which General Purpose Register to use as a base
register and what its content will be.
Syntax : USING <content of base register><GPR to be used as base register>
Ex: USING * 5
START:
Start is a pseudo opcode that tells the assembler where the beginning of the program is and allows the user to
give a name to the program.
Ex: START sum or sum START
END:
End is a pseudo opcode that tells the assembler that the last statement of the program has been reached.
Ex: END
EQU:
EQU is the pseudo opcode which allows the program to define variables.
Ex: BASE EQU 15
Pseudo opcodes
DC (data constant)/(define constant):
DC is a declarative pseudo opcode used to create a memory area to hold a constant value .
Syntax: <Label>DC “constants‟
Ex: FOUR DC “F4‟
DS (data storage)
DS is the pseudo opcode that reserves storage for the data and gives them a name .
Syntax: <Label> DS “size‟
Ex: FOUR A DS 1F
DROP:
Drop is a pseudo opcode which indicates an unavailable base register and its contents .
Syntax: DROP <BS register number>
Ex: DROP 15
LTORG:
LTORG is a pseudo opcode which tells the assembler to place the encountered literals at an earlier location.
It is used for very long programs
Machine opcodes
BALR:
BALR is a branch and link instruction. It is an instruction to the computer to load a register
with the next address and branch to the address specified in the second field.
BALR loads the base register and it is an executable statement. It is an RR type instruction
whose length is 2 bytes.
Ex: BALR 15,0
BR:
BR is a machine opcode indicating branch to the location whose address is in general register
Ex: BR 14
BCT:
BCT indicates branch and count .
It is a RX type instruction whose size is 4 bytes.
Ex: BCT 3, loop
Decrements register 3 by 1 if result is not 0 branch back to loop
Differences between USING & BALR
USING BALR
A pseudo op that indicates to the It is an instruction to the computer to load
assembler which general register a register with the next address and
branch to the address specified in the
to use as a base and what its second field.
content will be.
Loads the base register.
Only provides the information to
the assembler but does not load
the register. Ex: : BALR 15,0
Ex: USING BEGIN 15 Loads base register 15 with next
address, and since second operand is
Specifies that 15 is the base 0,the execution proceeds with next
register instruction
Sample program
END OF UNIT I
THANK YOU