140 likes | 234 Views
Systems Programming. Chapter 2 Assembler III. 2.2 Machine-Dependent Assembler Features. SIC/XE Features: (see Figure 2.5) Indirect addressing Adding the prefix @ to the operand. (like pointer) Avoid the need for another instruction like return operation
E N D
Systems Programming Chapter 2 Assembler III CPS4200 System Programming Spring 2007
2.2 Machine-Dependent Assembler Features • SIC/XE Features: (see Figure 2.5) • Indirect addressing Adding the prefix @ to the operand. (like pointer) • Avoid the need for another instruction like return operation • Immediate operands are denoted by prefix #. • Operand is already present as part of the instruction and need not be fetched from anywhere • Instruction that refers to memory are normally assembled using either the program-counter relative or the base relative mode. • Directive BASE base relative mode. CPS4200 System Programming Spring 2007
2.2 Machine-Dependent Assembler Features • If the displacements required for both program-counter relative and base relative addressing are too large to fit into a 3-byte instruction, then the 4-byte extended format must be used. • The prefix +is added to the operation code in extended format. • Register to register instruction is used wherever possible. CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • Figure 2.6 shows the object code • generated fro each statement in the program figure 2.5. • START statement specifies a beginning • program address 0.indicate a re-locatable program • Translation of register-to-register • instructions such as CLEAR and COMPR is straight forward. • Register names and their values can be preloaded onto SYMTAB. CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • Most of the register-to-memory instruction are assembled using either program-counter (PC) relative or base (B) relative addressing. • The resulting displacement must be small enough to fit in the 12-bit field in the instruction. For example: • 0 <= disp <= 4095 for base relative mode, or • -2048 <= disp <= +2047 for program-counter relative mode. CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • if the disp is too large, 4-byte extended instruction must be used. No displacement to be calculated. • For example: • 0006 CLOOP +JSUB RDREC 4B101036 The operand address is 1036. OPCode = 48, flag bits are 110001. • 20 bit address=01036 (can’t be represented in 12 bits). • (0001)2 = (1)h • 48 = (0100 1000) + • (0011) = • 0100 1011 = 4B CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • Question? • If extended format is not specified, what will happen? • What if we don’t specify extended format explicitly, is the system still working? Why? CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • Displacement Calculation • The program counter is advanced after each instruction is fetched and before it is executed. • For example: (program-counter relative assembly) 10 0000 FRIST STL RETADR 17202D • During the execution of STL instruction, PC will contain the address of the next instruction (that is PC=0003). • The address of RETADR = 0030 • Displacement disp = (30)h – (3)h = (2D)h, at execution time, the target address calculation performed will be (PC) + disp = 0030 CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • p is set to be 1 to indicate program-counter relative • (11 0010 ) + 2D (11) 202D. Opcode of STL is 14. Therefore, (14)h + (0011)2 202D17202D CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • For example (program-counter relative assembly) • 0017 J CLOOP 3F2FEC • The operand address is 0006. • The program counter will contain the address 001A. • The displacement = 6 – 1A = -14 = FEC ( 2’s complement for -14 in a 12-bit filed) • Base displacement (programmer must tell the assembler what the base register will contain) • Programmer must tell assembler what the base register will contain during the execution of the program for the assembler to calculate the displacements. CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • BASE LENGTH: it informs the assembler that the base register will contain the address of LENGTH. • LDB #LENGTH loadsthis value into the register during program execution. • The assembler assumes for addressing purposes that register B contains this address until it encounters another BASE statement. • Example: Base relative assembly (program counter does not work in this case?) 160 104E STCH BUFFER,X 57C003 • Register B contains 0033 (the address of LENGTH). • The address of BUFFER is 0036 CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • The displacement is 36 -33 = 3. The x and b are set to be 1 to indicate indexed and base relative addressing. • Immediate Addressing: No memory reference is involved. Convert immediate operand to its internal representation and insert it into the instruction. • For example: 55 0020 LDA #3 010003 • Operand is stored in instruction is 0003 • Bit i set to be 1 to indicate immediate addressing CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • For example: 133 103C +LDT #4096 75101000 • The operand (4096) is too large to fit into the 12-bit displacement field, so the extended instruction format is called for. • (74)h + (0001)2 + (0001) + (1000)h • For example: different way of using immediate addressing: 12 0003 LDB #LENGTH 69202D • The immediate operand is a symbol LENGTH. Since the value of this symbol is the address assigned to it, this immediate instruction has the effect of loading register B with the address of LENGTH. Displacement=> (0033)h = disp + (PC), disp = (30)h – (3)h = (2D)h , (68)h + (01) 2 (0010) 2 (02D) h CPS4200 System Programming Spring 2007
2.2.1 Instruction Formats and Addressing Modes • It is a combination of program–counter relative addressing with immediate addressing. • In general, the target address calculation is performed; then, if immediate mode is specified, the target address (not the contents stored at that address) becomes the operand. • Indirect addressing: • The displacement is computed in the usually way. • bit n is set to indicate that the contents stored at this location represent the address of the operand, not the operand itself. Line 70 shows a statement like it. CPS4200 System Programming Spring 2007