Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assemblers - 2 CSCI/CMPE 3334 David Egle.

Similar presentations


Presentation on theme: "Assemblers - 2 CSCI/CMPE 3334 David Egle."— Presentation transcript:

1 Assemblers - 2 CSCI/CMPE 3334 David Egle

2 Machine Dependent Features
The algorithm presented in the previous lecture was based on the SIC machine What changes would be needed for other architectures – i.e., the SIC/XE New instruction formats Additional instructions Additional addressing modes Additional registers

3 SIC/XE Assembler Changes must be made to format of source code
How do we indicate indirect addressing immediate addressing extended format (4 byte) mode How do we set up for base addressing Need to recognize when registers are used Need to determine whether PC relative addressing or base relative addressing are required

4 SIC/XE Assembler Changes also made to machine code handling
Which format should be used How are registers numbered How are displacements calculated Which bits are set in formats 3 & 4 Truncation of opcode value

5 Programmer changes The programmer must revise their coding to take advantage of the new features Use registers whenever possible Be aware of the limitations of PC and base relative addressing Use immediate and indirect addressing when possible Don’t specify specific address in START – use START 0 With the increased memory, more than one program may be in memory at the same time – let the assembler and loader handle the details

6 SIC/XE sample program (1/3)
COPY START 0 COPY FILE FROM INPUT TO OUTPUT FIRST STL RETADR SAVE RETURN ADDRES LDB #LENGTH ESTABLISH BASE REGISTER BASE LENGTH CLOOP +JSUB RDREC READ INPUT RECORD LDA LENGTH TEST FOR EOF (LENGTH = 0) COMP #0 JEQ ENDFIL EXIT IF EOF FOUND +JSUB WRREC WRITE OUTPUT RECORD J CLOOP LOOP ENDFIL LDA EOF INSERT END OF FILE MARKER STA BUFFER LDA #3 SET LENGTH = 3 STA LENGTH +JSUB WRREC WRITE EOF RETURN TO CALLER EOF BYTE C'EOF' RETADR RESW 1 LENGTH RESW 1 LENGTH OF RECORD BUFFER RESB BYTE BUFFER AREA

7 SIC/XE sample program (2/3)
. . SUBROUTINE TO READ RECORD INTO BUFFER RDREC CLEAR X CLEAR LOOP COUNTER CLEAR A CLEAR A TO ZERO CLEAR S CLEAR S TO ZERO +LDT #4096 RLOOP TD INPUT TEST INPUT DEVICE JEQ RLOOP LOOP UNTIL READY RD INPUT READ CHARACTER INTO REGISTAR A COMPR A,S TEST FOR END OF RECORD (X'00') JEQ EXIT EXIT LOOP IF EOF STCH BUFFER,X STORE CHARCTER IN BUFFER TIXR T LOOP UNLESS MAX LENGTH JLT RLOOP HAS BEEN REACHED EXIT STX LENGTH SAVE RECORD LENGTH RSUB RETURN TO CALLER INPUT BYTE X'F1' CODE FOR INPUT DEVICE

8 SIC/XE sample program (3/3)
. . SUBROUTINE TO WRITE RECORD FROM BUFFER WRREC CLEAR X CLEAR LOOP COUNTER LDT LENGTH WLOOP TD OUTPUT TEST OUTPUT DEVICE JEQ WLOOP LOOP UNTIL READY LDCH BUFFER,X GET CHARCTER FROM BUFFER WD OUTPUT WRITE CHARACTER TIXR T LOOP UNTIL ALL CHARACTERS JLT WLOOP HAVE BEEN WRITTEN RSUB RETURN TO CALLER OUTPUT BYTE X'05' CODE FOR OUTPUT DEVICE END FIRST

9 Changes to tables Opcode table MUST include instruction format type
Symbol table should include register names and values We may need further additions

10 Displacement calculation
If extended mode is not specified, assume PC relative addressing as default If displacement out of range, try base relative addressing If that fails, generate an error message

11 Displacement calculation
For either mode of displacement, the general form is target address = (reg) + displacement where reg is either PC or B So, to get the displacement, the assembler must calculate displacement = target address – (reg) BUT, how can the assembler know the value of PC or B???

12 PC relative addressing
The assembler does not know the value of any register It must use the location counter (LOCCTR) and the knowledge of the instruction cycle: fetch instruction from location pointed to by PC update PC decode instruction execute instruction So, when an instruction is executed, the PC contains the address of the next instruction

13 PC relative addressing
So, to compute the displacement using PC relative addressing, the assembler must compute displacement = address of target – (LOCCTR + size of instruction being executed) for the XE, the size is 3 Note that this displacement is a 12 bit signed integer range is to 2047

14 Base relative addressing
This is a bit easier, BUT requires assistance from the programmer B register is under control of the programmer must be loaded with the correct value To let the assembler know the contents of B, a new directive is used BASE symbol There is also a directive NOBASE which tells the assembler that the content of the B register cannot be relied on for addressing NOTE: Assembler directives DO NOT produce executable code

15 Base relative addressing
So, to compute the displacement using base relative addressing, the assembler must compute displacement = address of target – (address of symbol specified by BASE) Note that this displacement is a 12 bit unsigned integer range is 0 to 4095

16 Immediate operands Convert operand to its internal representation
Operand may be a value, or a symbol If it does not fit in 12 bits, and extended format was not specified – Error if it does not fit in 20 bits, - Error another addressing form must be used Set the appropriate bits in the instruction

17 Indirect addressing Not much to do here other than to set the appropriate bits and hope the programmer knows what they are doing

18 Relocation SIC requires an absolute loader
The program must be loaded in the specified address to execute properly If loaded in a different location, the address portions of the instructions need to change This would affect almost every instruction It is not practical to plan execution at a specific address A program should be loaded wherever there is room

19 Relocation The assembler cannot make the address changes itself
It has no idea where the program will be loaded The assembler must tell the loader which parts of the program will require modification Produces a relocatable object file Note that there is no need to adjust operands when it is immediate or register PC or base relative addressing is used In these cases, there is no address to fix

20 Relocation To handle relocation
start the location counter at 0 (START 0) generate object code where direct addresses are calculated relative to the load address (0) Note that these will only be found in format 4 instructions on the XE, but in most instructions on the SIC add information in the object file telling the loader which address fields require adjustment

21 Object file format Need a new type of record Modification record
Maddress (note that this is different from the text) NOTE: This is not how modern computers handle this situation. But we will need this modification record later.

22 Paging (from Stallings)
Split memory into equal sized, small chunks -page frames Split programs (processes) into equal sized small chunks - pages Allocate the required number page frames to a process Operating System maintains list of free frames A process does not require contiguous page frames Use page table to keep track

23 Allocation of Free Frames

24 Logical and Physical Addresses - Paging

25 Virtual Memory Demand paging Page fault
Do not require all pages of a process in memory Bring in pages as required Page fault Required page is not in memory Operating System must swap in required page May need to swap out a page to make space Select page to throw out based on recent history

26 Thrashing Too many processes in too little memory
Operating System spends all its time swapping Little or no real work is done Disk light is on all the time Solutions Good page replacement algorithms Reduce number of processes running Fit more memory

27 Bonus We do not need all of a process in memory for it to run
We can swap in pages as required So - we can now run processes that are bigger than total memory available! Main memory is called real memory User/programmer sees much bigger memory - virtual memory


Download ppt "Assemblers - 2 CSCI/CMPE 3334 David Egle."

Similar presentations


Ads by Google