OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 9:36 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re:Making a Compiler?
PostPosted: Fri Nov 15, 2002 1:23 pm 
elias wrote:
it is a Z80, and Ticalc.org dosnt help. theres an assembler for teh PC, and you can transfer your programs to the calculator form teh PC, btu i wanted to write an assembler to work on the calc. so i need a built in table of every possibnle isntruciton and its opcode, take in a text file, and replace every opcode with its binary value, and output to a file?


More or less, yes, but there are some complications, even in addition to the issues of handling the labels as described earlier. Because of the various addressing modes, the mnemonics don't quite have a one-to-one correspondence with the opcodes; Also, some of the opcodes are two bytes in length, not one, even when they have the same mnemonic. For example, here are a few of the transitions for "Load to register A":
[tt]
LD A, B ;load A from register B == 78
LD A, C ;load A from register C == 79
LD A, D ;load A from register B == 7A
LD A, E ;load A from register C == 7B
LD A, H ;load A from register H == 7C
LD A, L ;load A from register L == 7D

LD A, (BC) ;load A from the address pointed to by the combined B and C registers = 0A

LD A, (DE) ;load A from the address pointed to by the combined D and E registers = 1A

LD A, (HL) ;load A from the address pointed to by the combined H and L registers = 7E

LD A, n ;load A from the byte following the opcode == 3E xx
LD A, (nn) ;load A from the address pointed to by the two bytes following the opcode == 3A xx xx

LD A, (IX+nn) ;load A from the address pointed to in index register IX, offset by the value of the two bytes following the opcode == DD 7E xx xx

LD A, (IY+nn) ;load A from the address pointed to in index register IY, offset by the value of the two bytes following the opcode == FD 7E xx xx
[/tt]
(example data taken from the Z80 Op-Code Listing on ticalc.org; all values given in hex.)

The assembler also has to produce the appropriate executable foramt for the system it is on, and check for any errors in syntax or usage. As you can see, there are some patterns to it, but they are not consistent throughout the instruction set, partly because it was extended after the original design (the Z80 was based on the Intel 8080, but the instruction set was substantially extended by the Zilog designers).

Now, it is not really all that hard, but it can be a lot of work. It would pay to think out the design thoroughly before starting to code. HTH.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Fri Nov 15, 2002 9:32 pm 
so makign an ssembler is basicalyl busy work? i was going to include a minimal set of opcodes, and maybe expand on it.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Tue Nov 19, 2002 11:45 pm 
Does assembler compile into machine code??

and if it does how does machine code look???

Also, is there a decompiler, so i can look at machine code of programs??

Ciao


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Wed Nov 20, 2002 5:54 am 
Berserk wrote:
Does assembler compile into machine code??

and if it does how does machine code look???

Also, is there a decompiler, so i can look at machine code of programs??


<yoda>
If listen you do not, learn nothing you shall! (wacks Berserk with gimer stick)
</yoda>

Seriously, Berserk, this has been addressed numerous times already; I've personally explained it in this thread once already, as well as one other (here, reply #26) recently. In the "Where do I start?" thread (reply #42) in the OS Development message board I explained it to you specifically. Please search the message boards, re-read the existing threads, and try to understand what we've said already. While these specific questions were never asked before, the answers were implicit in the previous explanations.

I truly do want to help, and have no wish to be rude, but I cannot learn these things for you. Aristotle is said to have told the young Alexander, "There is no royal road to Geometry"; this is even more true of programming. You must make an effort to understand, or our efforts to teach will be in vain.

But to go over it once again: Assembly instructions are near-exact analogs of machine opcodes. An assembler produces binary object code, which may be raw machine code or a linkable object format such as ELF (the term 'object code' has nothing to do with object-oriented programming, BTW). This is the entire purpose of an assembler - turning the assembly language program into object code.

Most object file formats are not pure machine code per se, but usually have additional information about how to link the object code to external references, how to relocate it in memory, and so on; the object code gets turned into the final machine code when the OS loads into into memory and runs it. Machine code is a raw binary, but most debuggers and dumps will display it either as hex, as the corrosponding ASCII characters, or as a disassembly (or some combination of the three). Try experimenting with DEBUG (for DOS and Windows) or gdb (for Linux) to get a feel for it.

Disassemblers do exist (most debuggers will disassemble machine code), and allow you to review the programs symbolically, but without the symbol table from when the program was assembled or compiled, they cannot recreate the original identifiers, making it harder to read than the original source code. Trying to read someone else's program from a disassembly is... trying, but it can be done.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Wed Nov 20, 2002 10:51 am 
Making a assmbler....you could try forming NASM's C/(mabe C++? ) code to make your own NASM. And then just slowly form it to your NASM ( I don't know...mabe "BerserkASM"? )


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 21, 2002 12:41 am 
lol,

That's just what i was thinking, BUT, what does nasm compile with??

Ciao 8)


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 21, 2002 5:59 am 
I thought C.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 21, 2002 6:01 am 
http://sourceforge.net/projects/nasm


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 21, 2002 10:37 pm 
I know, BUT what compiler??


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Fri Nov 22, 2002 7:31 am 
If you're installing from source on a Linux machine then it's compiled with gcc. I don't know what the binaries are compiled with in the Win32 ports.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Fri Nov 22, 2002 6:53 pm 
I compiled it for Win32 (on Windows XP)

I used GCC, but when i compile it, the exe file appears to be a dos program?? how come, (NOTE: i used the DJGPP version of gcc)

When i right click it - it has all the dos program options.

I use this directive:
Code:
gcc -c nasm.c -o nasm.exe


Is there something wrong with this??

Ciao :D


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 28, 2002 12:19 am 
Hey,

Does anybody know how to do what i asked b4, i can't find it in the DJGPP manuals??


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 28, 2002 9:44 am 
I belive there is a command line that makes a PE file.

Also...to make programs other than command line is hard!


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Thu Nov 28, 2002 11:50 am 
By default, DJGPP gcc builds COFF files for it's object files, and links them as DOS .EXE executables designed to run using the DOS Protected Mode Interface (DPMI).

However, according to the DJGPP v2.0 FAQ, it cannot build PE executables directly. However, since PE is based on COFF, it is fairly easy to convert between the two, and a utility called RXNTDJ can be used to do so.


Top
  
 
 Post subject: Re:Making a Compiler?
PostPosted: Fri Dec 06, 2002 1:20 am 
Hey,

I was just wondering: I am going to install Mandrake Linux 9. And it comes with a version of gcc. Can i use it to make windows programs??

And here's an off topic question about linux which i need BIG help with:

How do i make Mandrake Linux detect an internal Windows Fax Modem. And is it possible to use it with linux??

Ciao ;)


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 72 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group