Skip to main content
GameDev.net gamedev.net
🔒 Locked

Writing a assembler

Started by Chargh Jul 29, 2011 at 4:52 PM 3 replies 950+ views
Original Post
Chargh
Chargh
I'm currently trying to build a assembler backend for my scripting language, which is luckily already a C like language (as in simplicity in variable handling, it is kinda useless as a scripting engine). I already knew quite a bit about assembler but not on the actual machine code level. Now that I'm able to write simple helloworld bootloaders with my own assembler I begin to wonder why certain instructions have multiple opcodes. For instance several 'mov' instructions dealing with the 'ax' register have separate op codes. These are smaller then the ones who apply to any register. Are these instructions faster or do they serve no other point then reducing binary size? How does this apply to jmp's? I can understand that a far jump is slower then a short jump because of the need to update registers. Does this also apply to jmp rel8 vs jmp rel16/32? I did some Google searches but I couldn't find anything useful. Are there more people out there who are writing there own assembler/compiler because they spent so much time on their scripting engine that it seems quite a waste not to do so, my intermediate language (which is interpreted by my scripting engine) is already nothing more then a glorified assembler language.

Chargh,
RoyCHill
RoyCHill

I'm currently trying to build a assembler backend for my scripting language, which is luckily already a C like language (as in simplicity in variable handling, it is kinda useless as a scripting engine). I already knew quite a bit about assembler but not on the actual machine code level. Now that I'm able to write simple helloworld bootloaders with my own assembler I begin to wonder why certain instructions have multiple opcodes. For instance several 'mov' instructions dealing with the 'ax' register have separate op codes. These are smaller then the ones who apply to any register. Are these instructions faster or do they serve no other point then reducing binary size? How does this apply to jmp's? I can understand that a far jump is slower then a short jump because of the need to update registers. Does this also apply to jmp rel8 vs jmp rel16/32? I did some Google searches but I couldn't find anything useful. Are there more people out there who are writing there own assembler/compiler because they spent so much time on their scripting engine that it seems quite a waste not to do so, my intermediate language (which is interpreted by my scripting engine) is already nothing more then a glorified assembler language.

Chargh,


Those are intermediate codes that directly use the accumulator register.
I assume that you are working with 16bit real mode assembly. I recommend using 32bit flat mode and you get to handle up to 4 gigs of ram but doing the 16bit real mode calls is a little tricky unless that hint that the virtual processor mode can be used to create a 16bit virtual mode environment on 32bit protected or flat mode. Hmm I would look that up.

I could not find anything on it, but I think it is possible with dual core processors.

[research 5 minutes]
Here is a more up-to-date assembly online document that mentions 64bit technology.
Assembly Language for x86 Processors


Yep, page 17 of that document mentions about virtual-8086 mode
I noticed that the document has its register marks for publishing.

Site to the book. It is sold.
http://kipirvine.com/asm/
General Studies A.S - College of Southern Nevada 2003 GPA 2.3
Chargh
Chargh
It can generate both 16 and 32 bit code. I only run-tested the 16 bit code because it launches through 'qemu test.bin' if its orgin is 0x7C00, the 32bit code is tested through nasm's dissambler. All the relocation/import addresses and types (rel 16 or 32, segment:offset...) which the linker is going to use is ready. Now I got all the comparison instructions implemented I was wondering if there is any use in implementing the 8bit rel versions for any other reason then binary size? Because I don't worry about file size, but I was wondering if there is any other reason for these instructions to exist. Same goes for the single byte 'mov, cmp...' with multi byte versions present, are they any faster or do they all just take the same time? Thanks for the reference to the book. I already got the red dragon book, but a more in depth assembly book might be a good purchase.
Adam_42
Adam_42
I suspect that on modern processors, assuming no cache issues you won't gain much if any performance by using the smaller instructions.

However, because of cache misses, code size is important to performance in most programs. That's one reason why compilers have options to optimize for code size.

Out of curiosity why aren't you using Yasm or some other library to do your assembling?
Chargh
Chargh

Out of curiosity why aren't you using Yasm or some other library to do your assembling?


Thank you, now I see the point of using them. And for above, believe it or not, I like to do that kind of programming.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.