Title | CS1104 Discussion 7 - Hope its helpful |
---|---|
Course | Computer Systems |
Institution | University of the People |
Pages | 1 |
File Size | 36.1 KB |
File Type | |
Total Downloads | 31 |
Total Views | 148 |
Hope its helpful...
The Hack assembler is a two-pass assembler. Explain why there is a need for going twice over the code.
An assembler is a translator, that translates an assembler program into a conventional machine language program. In doing so, the assembler goes through the program one line at a time and generates machine code for that instruction. The main reason why most assemblers use a 2-pass system is to address the problem of forward references, i.e. references to variables or subroutines that have not yet been encountered when parsing the source code.
There is a method named backpatching that solves this issue with one pass only. Describe this method.
I think this definition on Stack Overflow puts backpatching quite clearly when it defines it as the process of leaving blank entries for the go to instruction where the target address is unknown in the forward transfer in the first pass and filling these unknown in the second pass. This is precisely applicable where a jump is generated; in this case the target of the jump is temporarily left unspecified only to be filled in when the proper label can be determined. Backpatching can therefore be quite handy in generating code for Boolean expressions and flow-of-control statements in one pass.
What are the pros and cons for one pass assembly vs. two pass assembly?
The main advantages of a one pass assembly is that:
Single pass compiler is faster and smaller than the multi pass compiler. Generate the object code in memory for immediate execution
Disadvantages:
It is less efficient in comparison with multi pass compiler. the list created in one-pass Backpatching can be very large and use a lot of memory
Advantages of a one pass assembly is that:
It is able to detect redefinitions
Disadvantages:
It is a slower process as 2 passes take more time than 1 pass...