Re:Making a Compiler?
Posted: Fri Nov 15, 2002 1:23 pm
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":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?
[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.