0% found this document useful (0 votes)
318 views5 pages

Two Pass Assembler

This document discusses a two pass assembler implemented in C. It includes code to: - Print the assembly code labels and opcodes - Calculate the Location Counters (LC) for each instruction - Generate the symbol table with symbol names, values, lengths, and relative/absolute flags - Parse the USING statement to populate the base register table - Print the second pass table with labels, opcodes, and LCs

Uploaded by

Wasim Mirza
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
318 views5 pages

Two Pass Assembler

This document discusses a two pass assembler implemented in C. It includes code to: - Print the assembly code labels and opcodes - Calculate the Location Counters (LC) for each instruction - Generate the symbol table with symbol names, values, lengths, and relative/absolute flags - Parse the USING statement to populate the base register table - Print the second pass table with labels, opcodes, and LCs

Uploaded by

Wasim Mirza
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Synopsis of system software

Design of two pass assembler in c

Tarun Tandon Roll no: 22 K37h1

An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture. This representation is usually defined by the hardware manufacturer, and is based on mnemonics that symbolize processing steps (instructions), processor registers, memory locations, and other language features. An assembly language is thus specific to a certain physical (or virtual) computer architecture. This is in contrast to most high-level programming languages, which, ideally, are portable

Assembler
Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities.[1] The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitutione.g., to generate common short sequences of instructions as inline, instead of called subroutines. Assemblers are generally simpler to write than compilers for high-level languages, and have been available since the 1950s. Modern assemblers, especially for RISC architectures, such as SPARC orPOWER, as well as x86 and x86-64, optimize Instruction scheduling to exploit the CPU pipeline efficiently

Number of passes
There are two types of assemblers based on how many passes through the source are needed to produce the executable program. One-pass assemblers go through the source code once. Any symbol used before it is defined will

require "errata" at the end of the object code (or, at least, no earlier than the point where the symbol is defined) telling the linker or the loader to "go back" and overwrite a placeholder which had been left where the as yet undefined symbol was used. Two-pass assemblers create a table with all symbols and their values in the first pass, then use

the table in a second pass to generate code. In both cases, the assembler must be able to determine the size of each instruction on the first or

only pass in order to calculate the addresses of symbols. This means that if the size of an operation referring to an operand defined later depends on the type or distance of the operand, the assembler will make a pessimistic estimate when first encountering the operation, and if necessary pad it with one or more "no-operation" instructions in the second pass or the errata.

#include< stdio.h> #include< string.h> #include< conio.h>

void main() { char *code[9][4]={ {"PRG1","START","",""}, {"","USING","*","15"}, {"","L","",""}, {"","A","",""}, {"","ST","",""}, {"FOUR","DC","F",""}, {"FIVE","DC","F",""}, {"TEMP","DS","1F",""}, {"","END","",""} }; char av[2],avail[15]={'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'}; int i,j,k,count[3],lc[9]={0,0,0,0,0,0,0,0,0},loc=0; clrscr(); printf("----------------------------------------------------\n"); printf("LABEL\t\tOPCODE\n"); printf("----------------------------------------------------\n\n"); for(i=0;i< =8;i++) { for(j=0;j< =3;j++) { printf("%s\t\t",code[i][j]); } j=0; printf("\n"); } getch(); printf("-----------------------------------------------------"); printf("\nVALUES FOR LC : \n\n"); for(j=0;j< =8;j++) { if((strcmp(code[j][1],"START")!=0)&&(strcmp(code[j][1],"USING")!=0)&&(strcmp(code[j][1],"L")!=0)) lc[j]=lc[j-1]+4; printf("%d\t",lc[j]); }

printf("\n\nSYMBOL TABLE:\n----------------------------------------------------\n"); printf("SYMBOL\t\tVALUE\t\tLENGTH\t\tR/A"); printf("\n----------------------------------------------------\n"); for(i=0;i< 9;i++) { if(strcmp(code[i][1],"START")==0) { printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R'); } else if(strcmp(code[i][0],"")!=0) { printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R'); loc=4+loc; } else if(strcmp(code[i][1],"USING")==0){} else {loc=4+loc;} } printf("----------------------------------------------------"); printf("\n\nBASE TABLE:\n-------------------------------------------------------\n"); printf("REG NO\t\tAVAILIBILITY\tCONTENTS OF BASE TABLE"); printf("\n-------------------------------------------------------\n"); for(j=0;j< =8;j++) { if(strcmp(code[j][1],"USING")!=0) {} else { strcpy(av,code[j][3]); } } count[0]=(int)av[0]-48; count[1]=(int)av[1]-48; count[2]=count[0]*10+count[1]; avail[count[2]-1]='Y'; for(k=0;k< 16;k++) { printf(" %d\t\t %c\n",k,avail[k-1]); } printf("-------------------------------------------------------\n"); printf("Continue..??");

getchar(); printf("PASS2 TABLE:\n\n"); printf("LABEL\t\tOP1\t\tLC\t\t"); printf("\n----------------------------------------------------\n"); loc=0; for(i=0;i< =8;i++) { for(j=0;j< =3;j++) { printf("%s\t\t",code[i][j]); } j=0; printf("\n"); } printf("-----------------------------------------------------"); getch(); }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy