Advertisement
Guest User

Untitled

a guest
Apr 26th, 2010
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.63 KB | None | 0 0
  1.                                            
  2.       PASS -1                              
  3.                                            
  4. begin
  5.                                          
  6.  read first input line
  7.                                            
  8.  if OPCODE = 'START' then
  9.                                            
  10.    begin
  11.                                            
  12.     save #[OPERAND] as starting address
  13.                                            
  14.     initialized LOCCTR to starting address
  15.                                            
  16.     write line to intermediate file
  17.                                            
  18.     read next input line
  19.                                          
  20.    end {if START}
  21.  else
  22.                                            
  23.    initialized LOCCTR to 0
  24.  while OPCODE != 'END' do
  25.   begin
  26.     if this is not a comment line then
  27.       begin
  28.         if there is a symbol in the LABEL field then
  29.           begin
  30.             search SYMTAB for LABEL
  31.             if found then
  32.               set error flag (duplicate symbol)
  33.             else
  34.               insert (LABEL, LOCCTR) into SYMTAB
  35.           end {if symbol}
  36.         search OPTAB for OPCODE
  37.         if found then
  38.           add 3 {instruction lengh} to LOCCTR
  39.         else if OPCODE = 'WORD' then
  40.           add 3 to LOCCTR
  41.         else if OPCODE = 'RESW' then
  42.           add 3 * #[OPERAND] to LOCCTR
  43.         else if OPCODE = 'RESB' then
  44.           add #[OPERAND] to LOCCTR
  45.         else if OPCODE = 'BYTE' then
  46.           begin
  47.             find length of constant in bytes
  48.             add length to LOCCTR
  49.           end {if BYTE}
  50.         else
  51.           set error flag (invalid operation code)
  52.       end {if not a comment}
  53.     write line to intermediate file
  54.     read next input line
  55.   end {while not END}
  56.  write last line to intermediate file
  57.  save (LOCCTR - starting address) as program length
  58. end
  59.  
  60.  
  61. PASS 2
  62.                                                
  63. begin                                          
  64.  read first input file {from intermediate file}
  65.  if OPCODE = 'START' then                      
  66.    begin                                        
  67.     write listing line                          
  68.     read next input line                        
  69.    end {if START}                              
  70.  write header record to object program          
  71.  initialized first Text record                                                            
  72.                                                                
  73. while OPCODE != 'END' do                                      
  74.  begin                                                        
  75.   if this is not a comment line then                          
  76.     begin                                                      
  77.       search OPTAB for OPCODE                                  
  78.       if found then                                            
  79.         begin                                                  
  80.          if there is a symbol in OPERAND field then            
  81.            begin                                              
  82.              search SYMTAB for OPERAND                        
  83.              if found then                                    
  84.                store symbol value as operand address          
  85.              else                                              
  86.                begin                                          
  87.                 store 0 as operand address                    
  88.                 set error flag (undefined symbol)              
  89.                end                                            
  90.            end {if symbol}                                    
  91.          else                                                  
  92.            store 0 as operand address                          
  93.          assemble the object code instruction                  
  94.         end {if opcode found}                                  
  95.       else if OPCODE = 'BYTE' or 'WORD' then                  
  96.         convert constant to object code                        
  97.       if object code not fit into the current Text record then
  98.         begin                                                  
  99.          write Text record to object program                  
  100.          initialized new Text record                          
  101.         end                                                    
  102.       add object code to Text record                          
  103.     end {if not comment}                                      
  104.   write listing line
  105.   read next input line
  106.  end {while not END}
  107.  write last Text record to object program
  108. write END record to object program
  109. write last listing file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement