Just for anyone wondering. This is absolutely not applicable to a real architecture like x86 (at least not in the way it was presented). First of all the idea of opcode table is impossible since opcodes depend on their arguments. For example, in x86, the assembly mnemonic "add" can refer to 12 different machine instructions, each with different encodings. Second of all, building symbol table on the first pass is also impossible since certain instructions can have variable length. For example "jz" (jump if zero) will be 2 bytes long for 8bit offset, 4 bytes long for 16bit offset and 5 bytes long for 32bit offset. We can't know what length this instruction will have until we know it's distance to the label, and we can't know addresses of labels until we resolve all of these variable length encodings. Chicken and egg kind of problem. Things can get even more complicated if we add external symbols to the mix. On top of that, encoding operands is fairly complicated and varies between different instructions and addressing modes. There are also 6 different prefixes that can be added before an instruction to affect its meaning. Assemblers do a ton of work to encode your assembly code in the most optimal way possible. A lot of people seem to think that assembly is a 1-1 translation to machine code and don't realize how much abstraction there is between assembly and machine code. Assemblers make a ton of choices for you and perform many different optimizations/instruction substitution. They are a lot more sophisticated than people realize.
1: LocationCounter ← 0 2: Get first line of source code. 3: while more lines do 4: if line has a label then 5: SymbolTable.Symbol ← label 6: SymbolTable.Location ← LocationCounter 7: end if 8: Determine number of bytes required by the line when assembled. 9: LocationCounter ← LocationCounter + NumberOfBytes 10: Get next line of source code. 11: end while
Just for anyone wondering. This is absolutely not applicable to a real architecture like x86 (at least not in the way it was presented). First of all the idea of opcode table is impossible since opcodes depend on their arguments. For example, in x86, the assembly mnemonic "add" can refer to 12 different machine instructions, each with different encodings. Second of all, building symbol table on the first pass is also impossible since certain instructions can have variable length. For example "jz" (jump if zero) will be 2 bytes long for 8bit offset, 4 bytes long for 16bit offset and 5 bytes long for 32bit offset. We can't know what length this instruction will have until we know it's distance to the label, and we can't know addresses of labels until we resolve all of these variable length encodings. Chicken and egg kind of problem. Things can get even more complicated if we add external symbols to the mix. On top of that, encoding operands is fairly complicated and varies between different instructions and addressing modes. There are also 6 different prefixes that can be added before an instruction to affect its meaning. Assemblers do a ton of work to encode your assembly code in the most optimal way possible. A lot of people seem to think that assembly is a 1-1 translation to machine code and don't realize how much abstraction there is between assembly and machine code. Assemblers make a ton of choices for you and perform many different optimizations/instruction substitution. They are a lot more sophisticated than people realize.
1: LocationCounter ← 0
2: Get first line of source code.
3: while more lines do
4: if line has a label then
5: SymbolTable.Symbol ← label
6: SymbolTable.Location ← LocationCounter
7: end if
8: Determine number of bytes required by the line when assembled.
9: LocationCounter ← LocationCounter + NumberOfBytes
10: Get next line of source code.
11: end while
My Class loved this. Thanks mate.
No problem 👍
OMG I'M SUCH A BIG FAN PLEASE COME TO THAILAND
wait this isn't BTS
😂😂😂🤣🤣😂
simple and concise. nalla video machi
Thank you :-)
Thanks for making this. Really appreciated!
I love this man so much
Cheers bud! :-)
There is a question from AS computer Science paper suggest that data items are converted into their binary equivalent is done by first pass
Clear and concise
excellent video!
They aren't highlighted because they are variables (not labels)
JUST AWESOME
your awesome
Glad you like it!
incredible video. 420/69